diff --git a/receiver/prometheusreceiver/metrics_receiver_helper_test.go b/receiver/prometheusreceiver/metrics_receiver_helper_test.go index 248c7ff380c3..56769d375061 100644 --- a/receiver/prometheusreceiver/metrics_receiver_helper_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_helper_test.go @@ -4,7 +4,9 @@ package prometheusreceiver import ( + "bytes" "context" + "encoding/binary" "fmt" "log" "math" @@ -17,9 +19,11 @@ import ( "time" gokitlog "github.com/go-kit/log" + "github.com/gogo/protobuf/proto" promcfg "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/value" + dto "github.com/prometheus/prometheus/prompb/io/prometheus/client" "github.com/prometheus/prometheus/scrape" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -37,6 +41,9 @@ type mockPrometheusResponse struct { code int data string useOpenMetrics bool + + useProtoBuf bool // This overrides data and useOpenMetrics above + buf []byte } type mockPrometheus struct { @@ -82,11 +89,18 @@ func (mp *mockPrometheus) ServeHTTP(rw http.ResponseWriter, req *http.Request) { rw.WriteHeader(404) return } - if pages[index].useOpenMetrics { + switch { + case pages[index].useProtoBuf: + rw.Header().Set("Content-Type", "application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited") + case pages[index].useOpenMetrics: rw.Header().Set("Content-Type", "application/openmetrics-text") } rw.WriteHeader(pages[index].code) - _, _ = rw.Write([]byte(pages[index].data)) + if pages[index].useProtoBuf { + _, _ = rw.Write(pages[index].buf) + } else { + _, _ = rw.Write([]byte(pages[index].data)) + } } func (mp *mockPrometheus) Close() { @@ -563,10 +577,11 @@ func assertNormalNan() numberPointComparator { } } -func compareHistogram(count uint64, sum float64, buckets []uint64) histogramPointComparator { +func compareHistogram(count uint64, sum float64, upperBounds []float64, buckets []uint64) histogramPointComparator { return func(t *testing.T, histogramDataPoint pmetric.HistogramDataPoint) { assert.Equal(t, count, histogramDataPoint.Count(), "Histogram count value does not match") assert.Equal(t, sum, histogramDataPoint.Sum(), "Histogram sum value does not match") + assert.Equal(t, upperBounds, histogramDataPoint.ExplicitBounds().AsRaw(), "Histogram upper bounds values do not match") assert.Equal(t, buckets, histogramDataPoint.BucketCounts().AsRaw(), "Histogram bucket count values do not match") } } @@ -593,7 +608,7 @@ func compareSummary(count uint64, sum float64, quantiles [][]float64) summaryPoi } // starts prometheus receiver with custom config, retrieves metrics from MetricsSink -func testComponent(t *testing.T, targets []*testData, useStartTimeMetric bool, trimMetricSuffixes bool, startTimeMetricRegex string, cfgMuts ...func(*promcfg.Config)) { +func testComponent(t *testing.T, targets []*testData, alterConfig func(*Config), cfgMuts ...func(*promcfg.Config)) { ctx := context.Background() mp, cfg, err := setupMockPrometheus(targets...) for _, cfgMut := range cfgMuts { @@ -602,13 +617,16 @@ func testComponent(t *testing.T, targets []*testData, useStartTimeMetric bool, t require.Nilf(t, err, "Failed to create Prometheus config: %v", err) defer mp.Close() - cms := new(consumertest.MetricsSink) - receiver := newPrometheusReceiver(receivertest.NewNopCreateSettings(), &Config{ + config := &Config{ PrometheusConfig: cfg, - UseStartTimeMetric: useStartTimeMetric, - StartTimeMetricRegex: startTimeMetricRegex, - TrimMetricSuffixes: trimMetricSuffixes, - }, cms) + StartTimeMetricRegex: "", + } + if alterConfig != nil { + alterConfig(config) + } + + cms := new(consumertest.MetricsSink) + receiver := newPrometheusReceiver(receivertest.NewNopCreateSettings(), config, cms) require.NoError(t, receiver.Start(ctx, componenttest.NewNopHost())) // verify state after shutdown is called @@ -695,3 +713,22 @@ func getTS(ms pmetric.MetricSlice) pcommon.Timestamp { } return 0 } + +func prometheusMetricFamilyToProtoBuf(t *testing.T, buffer *bytes.Buffer, metricFamily *dto.MetricFamily) *bytes.Buffer { + if buffer == nil { + buffer = &bytes.Buffer{} + } + + data, err := proto.Marshal(metricFamily) + require.NoError(t, err) + + varintBuf := make([]byte, binary.MaxVarintLen32) + varintLength := binary.PutUvarint(varintBuf, uint64(len(data))) + + _, err = buffer.Write(varintBuf[:varintLength]) + require.NoError(t, err) + _, err = buffer.Write(data) + require.NoError(t, err) + + return buffer +} diff --git a/receiver/prometheusreceiver/metrics_receiver_honor_timestamp_test.go b/receiver/prometheusreceiver/metrics_receiver_honor_timestamp_test.go index 3ce6b001b28e..020ed21db4b9 100644 --- a/receiver/prometheusreceiver/metrics_receiver_honor_timestamp_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_honor_timestamp_test.go @@ -150,7 +150,7 @@ func TestHonorTimeStampsWithTrue(t *testing.T) { }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } // TestHonorTimeStampsWithFalse validates that with honor_timestamp config set to false, @@ -168,7 +168,7 @@ func TestHonorTimeStampsWithFalse(t *testing.T) { }, } - testComponent(t, targets, false, false, "", func(cfg *promcfg.Config) { + testComponent(t, targets, nil, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.HonorTimestamps = false } @@ -246,7 +246,7 @@ func verifyHonorTimeStampsTrue(t *testing.T, td *testData, resourceMetrics []pme histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(pcommon.NewTimestampFromTime(time.UnixMilli(ts4))), compareHistogramTimestamp(pcommon.NewTimestampFromTime(time.UnixMilli(ts4))), - compareHistogram(2500, 5000, []uint64{1000, 500, 500, 500}), + compareHistogram(2500, 5000, []float64{0.05, 0.5, 1}, []uint64{1000, 500, 500, 500}), }, }, }), @@ -310,7 +310,7 @@ func verifyHonorTimeStampsTrue(t *testing.T, td *testData, resourceMetrics []pme histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(pcommon.NewTimestampFromTime(time.UnixMilli(ts9))), compareHistogramTimestamp(pcommon.NewTimestampFromTime(time.UnixMilli(ts9))), - compareHistogram(2400, 4950, []uint64{900, 500, 500, 500}), + compareHistogram(2400, 4950, []float64{0.05, 0.5, 1}, []uint64{900, 500, 500, 500}), }, }, }), @@ -374,7 +374,7 @@ func verifyHonorTimeStampsTrue(t *testing.T, td *testData, resourceMetrics []pme histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(pcommon.NewTimestampFromTime(time.UnixMilli(ts9))), compareHistogramTimestamp(pcommon.NewTimestampFromTime(time.UnixMilli(ts14))), - compareHistogram(2500, 5000, []uint64{1000, 500, 500, 500}), + compareHistogram(2500, 5000, []float64{0.05, 0.5, 1}, []uint64{1000, 500, 500, 500}), }, }, }), @@ -446,7 +446,7 @@ func verifyHonorTimeStampsFalse(t *testing.T, td *testData, resourceMetrics []pm histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts1), - compareHistogram(2500, 5000, []uint64{1000, 500, 500, 500}), + compareHistogram(2500, 5000, []float64{0.05, 0.5, 1}, []uint64{1000, 500, 500, 500}), }, }, }), @@ -512,7 +512,7 @@ func verifyHonorTimeStampsFalse(t *testing.T, td *testData, resourceMetrics []pm histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(ts2), compareHistogramTimestamp(ts2), - compareHistogram(2400, 4950, []uint64{900, 500, 500, 500}), + compareHistogram(2400, 4950, []float64{0.05, 0.5, 1}, []uint64{900, 500, 500, 500}), }, }, }), diff --git a/receiver/prometheusreceiver/metrics_receiver_labels_test.go b/receiver/prometheusreceiver/metrics_receiver_labels_test.go index c1e0631f0ff5..8db248ef0d67 100644 --- a/receiver/prometheusreceiver/metrics_receiver_labels_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_labels_test.go @@ -29,7 +29,7 @@ func TestExternalLabels(t *testing.T) { }, } - testComponent(t, targets, false, false, "", func(cfg *promcfg.Config) { + testComponent(t, targets, nil, func(cfg *promcfg.Config) { cfg.GlobalConfig.ExternalLabels = labels.FromStrings("key", "value") }) } @@ -121,7 +121,7 @@ func TestLabelLimitConfig(t *testing.T) { }, } - testComponent(t, targets, false, false, "", func(cfg *promcfg.Config) { + testComponent(t, targets, nil, func(cfg *promcfg.Config) { // set label limit in scrape_config for _, scrapeCfg := range cfg.ScrapeConfigs { scrapeCfg.LabelLimit = 5 @@ -198,7 +198,7 @@ func verifyLabelConfigTarget1(t *testing.T, td *testData, rms []pmetric.Resource histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts1), - compareHistogram(2500, 5000, []uint64{1000, 500, 500, 500}), + compareHistogram(2500, 5000, []float64{0.1, 0.5, 1}, []uint64{1000, 500, 500, 500}), compareHistogramAttributes(map[string]string{"label1": "value1", "label2": "value2"}), }, }, @@ -248,7 +248,7 @@ func TestLabelNameLimitConfig(t *testing.T) { }, } - testComponent(t, targets, false, false, "", func(cfg *promcfg.Config) { + testComponent(t, targets, nil, func(cfg *promcfg.Config) { // set label limit in scrape_config for _, scrapeCfg := range cfg.ScrapeConfigs { scrapeCfg.LabelNameLengthLimit = 20 @@ -284,7 +284,7 @@ func TestLabelValueLimitConfig(t *testing.T) { }, } - testComponent(t, targets, false, false, "", func(cfg *promcfg.Config) { + testComponent(t, targets, nil, func(cfg *promcfg.Config) { // set label name limit in scrape_config for _, scrapeCfg := range cfg.ScrapeConfigs { scrapeCfg.LabelValueLengthLimit = 25 @@ -360,7 +360,7 @@ func verifyEmptyLabelValuesTarget1(t *testing.T, td *testData, rms []pmetric.Res histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts1), - compareHistogram(2500, 5000, []uint64{1000, 500, 500, 500}), + compareHistogram(2500, 5000, []float64{0.1, 0.5, 1}, []uint64{1000, 500, 500, 500}), compareHistogramAttributes(map[string]string{"id": "1"}), }, }, @@ -462,7 +462,7 @@ func TestEmptyLabelValues(t *testing.T) { validateFunc: verifyEmptyLabelValuesTarget2, }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } const honorLabelsTarget = ` @@ -556,7 +556,7 @@ func TestEmptyLabels(t *testing.T) { validateFunc: verifyEmptyLabelsTarget1, }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } func TestHonorLabelsFalseConfig(t *testing.T) { @@ -570,7 +570,7 @@ func TestHonorLabelsFalseConfig(t *testing.T) { }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } func verifyHonorLabelsTrue(t *testing.T, td *testData, rms []pmetric.ResourceMetrics) { @@ -613,7 +613,7 @@ func TestHonorLabelsTrueConfig(t *testing.T) { }, } - testComponent(t, targets, false, false, "", func(cfg *promcfg.Config) { + testComponent(t, targets, nil, func(cfg *promcfg.Config) { // set label name limit in scrape_config for _, scrapeCfg := range cfg.ScrapeConfigs { scrapeCfg.HonorLabels = true @@ -639,7 +639,7 @@ func TestRelabelJobInstance(t *testing.T) { }, } - testComponent(t, targets, false, false, "", func(cfg *promcfg.Config) { + testComponent(t, targets, nil, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.MetricRelabelConfigs = []*relabel.Config{ { @@ -709,7 +709,7 @@ func TestTargetInfoResourceAttributes(t *testing.T) { }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } func verifyTargetInfoResourceAttributes(t *testing.T, td *testData, rms []pmetric.ResourceMetrics) { @@ -759,7 +759,7 @@ func TestScopeInfoScopeAttributes(t *testing.T) { }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } func verifyMultipleScopes(t *testing.T, td *testData, rms []pmetric.ResourceMetrics) { diff --git a/receiver/prometheusreceiver/metrics_receiver_metric_name_normalize_test.go b/receiver/prometheusreceiver/metrics_receiver_metric_name_normalize_test.go index 5ac7682f1b7a..b2c06b590bc9 100644 --- a/receiver/prometheusreceiver/metrics_receiver_metric_name_normalize_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_metric_name_normalize_test.go @@ -44,7 +44,9 @@ func TestMetricNormalize(t *testing.T) { }, } - testComponent(t, targets, false, true, "") + testComponent(t, targets, func(c *Config) { + c.TrimMetricSuffixes = true + }) } func verifyNormalizeMetric(t *testing.T, td *testData, resourceMetrics []pmetric.ResourceMetrics) { diff --git a/receiver/prometheusreceiver/metrics_receiver_non_numerical_test.go b/receiver/prometheusreceiver/metrics_receiver_non_numerical_test.go index 05107737acb9..85c5986e1e7c 100644 --- a/receiver/prometheusreceiver/metrics_receiver_non_numerical_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_non_numerical_test.go @@ -70,7 +70,7 @@ func TestStaleNaNs(t *testing.T) { validateScrapes: true, }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } func verifyStaleNaNs(t *testing.T, td *testData, resourceMetrics []pmetric.ResourceMetrics) { @@ -133,7 +133,7 @@ func verifyStaleNaNsSuccessfulScrape(t *testing.T, td *testData, resourceMetric histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(startTimestamp), compareHistogramTimestamp(ts1), - compareHistogram(2500, 5000, []uint64{1000, 500, 500, 500}), + compareHistogram(2500, 5000, []float64{0.05, 0.5, 1}, []uint64{1000, 500, 500, 500}), }, }, }), @@ -252,7 +252,7 @@ func TestNormalNaNs(t *testing.T) { validateFunc: verifyNormalNaNs, }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } func verifyNormalNaNs(t *testing.T, td *testData, resourceMetrics []pmetric.ResourceMetrics) { @@ -339,7 +339,7 @@ func TestInfValues(t *testing.T) { validateFunc: verifyInfValues, }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } func verifyInfValues(t *testing.T, td *testData, resourceMetrics []pmetric.ResourceMetrics) { diff --git a/receiver/prometheusreceiver/metrics_receiver_open_metrics_test.go b/receiver/prometheusreceiver/metrics_receiver_open_metrics_test.go index 3ab80d737ed7..a39b12bdf336 100644 --- a/receiver/prometheusreceiver/metrics_receiver_open_metrics_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_open_metrics_test.go @@ -74,7 +74,7 @@ func TestOpenMetricsPositive(t *testing.T) { targets = append(targets, testData) } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } func verifyFailTarget(t *testing.T, td *testData, mds []pmetric.ResourceMetrics) { @@ -107,7 +107,7 @@ func TestOpenMetricsFail(t *testing.T) { targets = append(targets, testData) } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } func verifyInvalidTarget(t *testing.T, td *testData, mds []pmetric.ResourceMetrics) { @@ -142,7 +142,7 @@ func TestOpenMetricsInvalid(t *testing.T) { targets = append(targets, testData) } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } // reads test data from testdata/openmetrics directory @@ -228,7 +228,7 @@ func TestInfoStatesetMetrics(t *testing.T) { }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } diff --git a/receiver/prometheusreceiver/metrics_receiver_protobuf_test.go b/receiver/prometheusreceiver/metrics_receiver_protobuf_test.go new file mode 100644 index 000000000000..dbb00e9025b2 --- /dev/null +++ b/receiver/prometheusreceiver/metrics_receiver_protobuf_test.go @@ -0,0 +1,158 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package prometheusreceiver + +import ( + "math" + "testing" + + dto "github.com/prometheus/prometheus/prompb/io/prometheus/client" + "go.opentelemetry.io/collector/pdata/pmetric" +) + +func TestScrapeViaProtobuf(t *testing.T) { + mf := &dto.MetricFamily{ + Name: "test_counter", + Type: dto.MetricType_COUNTER, + Metric: []dto.Metric{ + { + Label: []dto.LabelPair{ + { + Name: "foo", + Value: "bar", + }, + }, + Counter: &dto.Counter{ + Value: 1234, + }, + }, + }, + } + buffer := prometheusMetricFamilyToProtoBuf(t, nil, mf) + + mf = &dto.MetricFamily{ + Name: "test_gauge", + Type: dto.MetricType_GAUGE, + Metric: []dto.Metric{ + { + Gauge: &dto.Gauge{ + Value: 400.8, + }, + }, + }, + } + prometheusMetricFamilyToProtoBuf(t, buffer, mf) + + mf = &dto.MetricFamily{ + Name: "test_summary", + Type: dto.MetricType_SUMMARY, + Metric: []dto.Metric{ + { + Summary: &dto.Summary{ + SampleCount: 1213, + SampleSum: 456, + Quantile: []dto.Quantile{ + { + Quantile: 0.5, + Value: 789, + }, + { + Quantile: 0.9, + Value: 1011, + }, + }, + }, + }, + }, + } + prometheusMetricFamilyToProtoBuf(t, buffer, mf) + + mf = &dto.MetricFamily{ + Name: "test_histogram", + Type: dto.MetricType_HISTOGRAM, + Metric: []dto.Metric{ + { + Histogram: &dto.Histogram{ + SampleCount: 1213, + SampleSum: 456, + Bucket: []dto.Bucket{ + { + UpperBound: 0.5, + CumulativeCount: 789, + }, + { + UpperBound: 10, + CumulativeCount: 1011, + }, + { + UpperBound: math.Inf(1), + CumulativeCount: 1213, + }, + }, + }, + }, + }, + } + prometheusMetricFamilyToProtoBuf(t, buffer, mf) + + expectations := []testExpectation{ + assertMetricPresent( + "test_counter", + compareMetricType(pmetric.MetricTypeSum), + compareMetricUnit(""), + []dataPointExpectation{{ + numberPointComparator: []numberPointComparator{ + compareDoubleValue(1234), + }, + }}, + ), + assertMetricPresent( + "test_gauge", + compareMetricType(pmetric.MetricTypeGauge), + compareMetricUnit(""), + []dataPointExpectation{{ + numberPointComparator: []numberPointComparator{ + compareDoubleValue(400.8), + }, + }}, + ), + assertMetricPresent( + "test_summary", + compareMetricType(pmetric.MetricTypeSummary), + compareMetricUnit(""), + []dataPointExpectation{{ + summaryPointComparator: []summaryPointComparator{ + compareSummary(1213, 456, [][]float64{{0.5, 789}, {0.9, 1011}}), + }, + }}, + ), + assertMetricPresent( + "test_histogram", + compareMetricType(pmetric.MetricTypeHistogram), + compareMetricUnit(""), + []dataPointExpectation{{ + histogramPointComparator: []histogramPointComparator{ + compareHistogram(1213, 456, []float64{0.5, 10}, []uint64{789, 222, 202}), + }, + }}, + ), + } + + targets := []*testData{ + { + name: "target1", + pages: []mockPrometheusResponse{ + {code: 200, useProtoBuf: true, buf: buffer.Bytes()}, + }, + validateFunc: func(t *testing.T, td *testData, result []pmetric.ResourceMetrics) { + verifyNumValidScrapeResults(t, td, result) + doCompare(t, "target1", td.attributes, result[0], expectations) + }, + }, + } + + testComponent(t, targets, func(c *Config) { + c.EnableProtobufNegotiation = true + }) +} diff --git a/receiver/prometheusreceiver/metrics_receiver_test.go b/receiver/prometheusreceiver/metrics_receiver_test.go index acfc6f8a4f83..bef58d079e7b 100644 --- a/receiver/prometheusreceiver/metrics_receiver_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_test.go @@ -167,7 +167,7 @@ func verifyTarget1(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts1), - compareHistogram(2500, 5000, []uint64{1000, 500, 500, 500}), + compareHistogram(2500, 5000, []float64{0.05, 0.5, 1}, []uint64{1000, 500, 500, 500}), }, }, }), @@ -234,7 +234,7 @@ func verifyTarget1(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc // TODO: Prometheus Receiver Issue- start_timestamp are incorrect for Summary and Histogram metrics after a failed scrape (issue not yet posted on collector-contrib repo) compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts2), - compareHistogram(2600, 5050, []uint64{1100, 500, 500, 500}), + compareHistogram(2600, 5050, []float64{0.05, 0.5, 1}, []uint64{1100, 500, 500, 500}), }, }, }), @@ -303,7 +303,7 @@ func verifyTarget1(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc // TODO: #6360 Prometheus Receiver Issue- start_timestamp should reset if the prior scrape had higher value compareHistogramStartTimestamp(ts3), compareHistogramTimestamp(ts3), - compareHistogram(2400, 4900, []uint64{900, 500, 500, 500}), + compareHistogram(2400, 4900, []float64{0.05, 0.5, 1}, []uint64{900, 500, 500, 500}), }, }, }), @@ -545,7 +545,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts1), compareHistogramAttributes(map[string]string{"method": "post", "code": "200"}), - compareHistogram(10, 7, []uint64{8, 2}), + compareHistogram(10, 7, []float64{1}, []uint64{8, 2}), }, }, { @@ -553,7 +553,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts1), compareHistogramAttributes(map[string]string{"method": "post", "code": "400"}), - compareHistogram(50, 25, []uint64{30, 20}), + compareHistogram(50, 25, []float64{1}, []uint64{30, 20}), }, }, }), @@ -629,7 +629,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts2), compareHistogramAttributes(map[string]string{"method": "post", "code": "200"}), - compareHistogram(50, 43, []uint64{40, 10}), + compareHistogram(50, 43, []float64{1}, []uint64{40, 10}), }, }, { @@ -637,7 +637,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts2), compareHistogramTimestamp(ts2), compareHistogramAttributes(map[string]string{"method": "post", "code": "300"}), - compareHistogram(3, 2, []uint64{3, 0}), + compareHistogram(3, 2, []float64{1}, []uint64{3, 0}), }, }, { @@ -645,7 +645,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts2), compareHistogramAttributes(map[string]string{"method": "post", "code": "400"}), - compareHistogram(60, 30, []uint64{35, 25}), + compareHistogram(60, 30, []float64{1}, []uint64{35, 25}), }, }, }), @@ -737,7 +737,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts3), compareHistogramAttributes(map[string]string{"method": "post", "code": "200"}), - compareHistogram(50, 43, []uint64{40, 10}), + compareHistogram(50, 43, []float64{1}, []uint64{40, 10}), }, }, { @@ -745,7 +745,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts2), compareHistogramTimestamp(ts3), compareHistogramAttributes(map[string]string{"method": "post", "code": "300"}), - compareHistogram(5, 7, []uint64{3, 2}), + compareHistogram(5, 7, []float64{1}, []uint64{3, 2}), }, }, { @@ -753,7 +753,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts3), compareHistogramAttributes(map[string]string{"method": "post", "code": "400"}), - compareHistogram(60, 30, []uint64{35, 25}), + compareHistogram(60, 30, []float64{1}, []uint64{35, 25}), }, }, }), @@ -845,7 +845,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts4), compareHistogramTimestamp(ts4), compareHistogramAttributes(map[string]string{"method": "post", "code": "200"}), - compareHistogram(49, 42, []uint64{40, 9}), + compareHistogram(49, 42, []float64{1}, []uint64{40, 9}), }, }, { @@ -853,7 +853,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts4), compareHistogramTimestamp(ts4), compareHistogramAttributes(map[string]string{"method": "post", "code": "300"}), - compareHistogram(3, 4, []uint64{2, 1}), + compareHistogram(3, 4, []float64{1}, []uint64{2, 1}), }, }, { @@ -861,7 +861,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts4), compareHistogramTimestamp(ts4), compareHistogramAttributes(map[string]string{"method": "post", "code": "400"}), - compareHistogram(59, 29, []uint64{34, 25}), + compareHistogram(59, 29, []float64{1}, []uint64{34, 25}), }, }, }), @@ -953,7 +953,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts4), compareHistogramTimestamp(ts5), compareHistogramAttributes(map[string]string{"method": "post", "code": "200"}), - compareHistogram(50, 43, []uint64{41, 9}), + compareHistogram(50, 43, []float64{1}, []uint64{41, 9}), }, }, { @@ -961,7 +961,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts4), compareHistogramTimestamp(ts5), compareHistogramAttributes(map[string]string{"method": "post", "code": "300"}), - compareHistogram(5, 4, []uint64{4, 1}), + compareHistogram(5, 4, []float64{1}, []uint64{4, 1}), }, }, { @@ -969,7 +969,7 @@ func verifyTarget2(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc compareHistogramStartTimestamp(ts4), compareHistogramTimestamp(ts5), compareHistogramAttributes(map[string]string{"method": "post", "code": "400"}), - compareHistogram(59, 29, []uint64{34, 25}), + compareHistogram(59, 29, []float64{1}, []uint64{34, 25}), }, }, }), @@ -1146,7 +1146,7 @@ func verifyTarget3(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts1), - compareHistogram(13003, 50000, []uint64{10000, 1000, 1001, 1002}), + compareHistogram(13003, 50000, []float64{0.2, 0.5, 1}, []uint64{10000, 1000, 1001, 1002}), }, }, }), @@ -1158,7 +1158,7 @@ func verifyTarget3(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts1), - compareHistogram(10, 100, []uint64{10}), + compareHistogram(10, 100, nil, []uint64{10}), }, }, }), @@ -1212,7 +1212,7 @@ func verifyTarget3(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts2), - compareHistogram(14003, 50100, []uint64{11000, 1000, 1001, 1002}), + compareHistogram(14003, 50100, []float64{0.2, 0.5, 1}, []uint64{11000, 1000, 1001, 1002}), }, }, }), @@ -1224,7 +1224,7 @@ func verifyTarget3(t *testing.T, td *testData, resourceMetrics []pmetric.Resourc histogramPointComparator: []histogramPointComparator{ compareHistogramStartTimestamp(ts1), compareHistogramTimestamp(ts2), - compareHistogram(15, 101, []uint64{15}), + compareHistogram(15, 101, nil, []uint64{15}), }, }, }), @@ -1336,7 +1336,7 @@ func TestCoreMetricsEndToEnd(t *testing.T) { validateScrapes: true, }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } var startTimeMetricPage = ` @@ -1423,7 +1423,9 @@ func TestStartTimeMetric(t *testing.T) { validateFunc: verifyStartTimeMetricPage, }, } - testComponent(t, targets, true, false, "") + testComponent(t, targets, func(c *Config) { + c.UseStartTimeMetric = true + }) } var startTimeMetricRegexPage = ` @@ -1472,7 +1474,10 @@ func TestStartTimeMetricRegex(t *testing.T) { validateFunc: verifyStartTimeMetricPage, }, } - testComponent(t, targets, true, false, "^(.+_)*process_start_time_seconds$") + testComponent(t, targets, func(c *Config) { + c.StartTimeMetricRegex = "^(.+_)*process_start_time_seconds$" + c.UseStartTimeMetric = true + }) } // metric type is defined as 'untyped' in the first metric @@ -1501,7 +1506,7 @@ func TestUntypedMetrics(t *testing.T) { }, } - testComponent(t, targets, false, false, "") + testComponent(t, targets, nil) } func verifyUntypedMetrics(t *testing.T, td *testData, resourceMetrics []pmetric.ResourceMetrics) { diff --git a/receiver/prometheusreceiver/metrics_reciever_metric_rename_test.go b/receiver/prometheusreceiver/metrics_reciever_metric_rename_test.go index 70abdd2eba09..3c030a27978a 100644 --- a/receiver/prometheusreceiver/metrics_reciever_metric_rename_test.go +++ b/receiver/prometheusreceiver/metrics_reciever_metric_rename_test.go @@ -47,7 +47,7 @@ func TestMetricRenaming(t *testing.T) { }, } - testComponent(t, targets, false, false, "", func(cfg *promcfg.Config) { + testComponent(t, targets, nil, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.MetricRelabelConfigs = []*relabel.Config{ { @@ -90,7 +90,7 @@ func TestMetricRenamingKeepAction(t *testing.T) { }, } - testComponent(t, targets, false, false, "", func(cfg *promcfg.Config) { + testComponent(t, targets, nil, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.MetricRelabelConfigs = []*relabel.Config{ { @@ -232,7 +232,7 @@ func TestLabelRenaming(t *testing.T) { }, } - testComponent(t, targets, false, false, "", func(cfg *promcfg.Config) { + testComponent(t, targets, nil, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.MetricRelabelConfigs = []*relabel.Config{ { @@ -362,7 +362,7 @@ func TestLabelRenamingKeepAction(t *testing.T) { }, } - testComponent(t, targets, false, false, "", func(cfg *promcfg.Config) { + testComponent(t, targets, nil, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.MetricRelabelConfigs = []*relabel.Config{ {