From f8f1d41cc5881d208831451b21c246ec5b9f871f Mon Sep 17 00:00:00 2001 From: Eugene Ma Date: Mon, 4 Nov 2024 20:25:48 -0800 Subject: [PATCH] add metadata and histograms to benchmark --- .../exporter_test.go | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/exporter/prometheusremotewriteexporter/exporter_test.go b/exporter/prometheusremotewriteexporter/exporter_test.go index d8647057a8f3..ca9789f97aeb 100644 --- a/exporter/prometheusremotewriteexporter/exporter_test.go +++ b/exporter/prometheusremotewriteexporter/exporter_test.go @@ -1214,17 +1214,51 @@ func benchmarkExecute(b *testing.B, numSample int) { return samples } + generateHistograms := func(n int) []prompb.Histogram { + histograms := make([]prompb.Histogram, 0, n) + for i := 0; i < n; i++ { + histograms = append(histograms, prompb.Histogram{ + Timestamp: int64(i), + Count: &prompb.Histogram_CountInt{CountInt: uint64(i)}, + PositiveCounts: []float64{float64(i)}, + }) + } + return histograms + } + reqs := make([]*prompb.WriteRequest, 0, b.N) const labelValue = "abcdefg'hijlmn234!@#$%^&*()_+~`\"{}[],./<>?hello0123hiOlá你好Dzieńdobry9Zd8ra765v4stvuyte" for n := 0; n < b.N; n++ { num := strings.Repeat(strconv.Itoa(n), 16) req := &prompb.WriteRequest{ - Timeseries: []prompb.TimeSeries{{ - Samples: generateSamples(numSample), - Labels: []prompb.Label{ - {Name: "__name__", Value: "test_metric"}, - {Name: "test_label_name_" + num, Value: labelValue + num}, - }}}, + Metadata: []prompb.MetricMetadata{ + { + Type: prompb.MetricMetadata_COUNTER, + Unit: "seconds", + Help: "This is a counter", + }, + { + Type: prompb.MetricMetadata_HISTOGRAM, + Unit: "seconds", + Help: "This is a histogram", + }, + }, + Timeseries: []prompb.TimeSeries{ + { + Samples: generateSamples(numSample), + Labels: []prompb.Label{ + {Name: "__name__", Value: "test_metric"}, + {Name: "test_label_name_" + num, Value: labelValue + num}, + }, + }, + { + Histograms: generateHistograms(numSample), + Labels: []prompb.Label{ + {Name: "__name__", Value: "test_histogram"}, + {Name: "test_label_name_" + num, Value: labelValue + num}, + }, + }, + }, } reqs = append(reqs, req) }