github.com/grafana/synthetic-monitoring-agent@v0.64.2/internal/scraper/catalogue_fixture_test.go (about) 1 package scraper 2 3 import ( 4 "context" 5 "io" 6 "testing" 7 "time" 8 9 "github.com/rs/zerolog" 10 11 "github.com/grafana/synthetic-monitoring-agent/internal/testhelper" 12 sm "github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring" 13 "github.com/prometheus/client_golang/prometheus" 14 ) 15 16 func collectFixtureCatalogue(t *testing.T, name string, spec fixtureSpec) MetricLabelCatalogue { 17 return collectFixtureCatalogueWithLogger(t, name, spec, testhelper.Logger(t)) 18 } 19 20 func collectFixtureCatalogueSilently(t *testing.T, name string, spec fixtureSpec) MetricLabelCatalogue { 21 return collectFixtureCatalogueWithLogger(t, name, spec, zerolog.New(io.Discard)) 22 } 23 24 func collectFixtureCatalogueWithLogger(t *testing.T, name string, spec fixtureSpec, logger zerolog.Logger) MetricLabelCatalogue { 25 t.Helper() 26 27 ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) 28 defer cancel() 29 30 probeImpl, check, stop := spec.setup(ctx, t) 31 defer stop() 32 33 check.Job = name + " job" 34 check.Frequency = 60000 35 check.Modified = 42 36 check.BasicMetricsOnly = spec.basicMetricsOnly 37 38 s := Scraper{ 39 checkName: check.Type().String(), 40 target: check.Target, 41 logger: logger, 42 prober: probeImpl, 43 labelsLimiter: testLabelsLimiter{maxMetricLabels: 100, maxLogLabels: 100}, 44 labellingMode: testLabellingMode{}, 45 summaries: make(map[uint64]prometheus.Summary), 46 histograms: make(map[uint64]prometheus.Histogram), 47 check: check, 48 probe: sm.Probe{Id: 100, TenantId: 200, Name: "test-probe", Latitude: -1, Longitude: -2, Region: "test-region"}, 49 } 50 51 data, _, err := s.collectData(ctx, time.Unix(3141, 0)) 52 if err != nil { 53 t.Fatalf("collectData(%s): %v", name, err) 54 } 55 56 return CatalogueFromTimeseries(data.Metrics()) 57 }