From 15211852406603495273ed745eab129a86965d13 Mon Sep 17 00:00:00 2001 From: Ivan <2103732+codebien@users.noreply.github.com> Date: Tue, 27 Jun 2023 15:49:12 +0200 Subject: [PATCH] cloudv2: Implement the protobuf changes --- output/cloud/expv2/flush.go | 16 ++++--- output/cloud/expv2/hdr.go | 2 - output/cloud/expv2/hdr_test.go | 2 - .../expv2/integration/testdata/metricset.json | 42 ++----------------- output/cloud/expv2/mapping.go | 9 ++-- 5 files changed, 13 insertions(+), 58 deletions(-) diff --git a/output/cloud/expv2/flush.go b/output/cloud/expv2/flush.go index bff946772d55..3add2432a305 100644 --- a/output/cloud/expv2/flush.go +++ b/output/cloud/expv2/flush.go @@ -63,9 +63,7 @@ func (f *metricsFlusher) flush(_ context.Context) error { } type metricSetBuilder struct { - MetricSet *pbcloud.MetricSet - TestRunID string - AggregationPeriodInSeconds uint32 + MetricSet *pbcloud.MetricSet // TODO: If we will introduce the metricID then we could // just use it as map's key (map[uint64]pbcloud.Metric). It is faster. @@ -92,15 +90,16 @@ type metricSetBuilder struct { } func newMetricSetBuilder(testRunID string, aggrPeriodSec uint32) metricSetBuilder { - return metricSetBuilder{ - TestRunID: testRunID, - MetricSet: &pbcloud.MetricSet{}, - AggregationPeriodInSeconds: aggrPeriodSec, + builder := metricSetBuilder{ + MetricSet: &pbcloud.MetricSet{}, // TODO: evaluate if removing the pointer from pbcloud.Metric // is a better trade-off metrics: make(map[*metrics.Metric]*pbcloud.Metric), seriesIndex: make(map[metrics.TimeSeries]uint), } + builder.MetricSet.TestRunId = testRunID + builder.MetricSet.AggregationPeriod = aggrPeriodSec + return builder } func (msb *metricSetBuilder) addTimeBucket(bucket timeBucket) { @@ -119,8 +118,7 @@ func (msb *metricSetBuilder) addTimeBucket(bucket timeBucket) { ix, ok := msb.seriesIndex[timeSeries] if !ok { pbTimeSeries = &pbcloud.TimeSeries{ - AggregationPeriod: msb.AggregationPeriodInSeconds, - Labels: mapTimeSeriesLabelsProto(timeSeries, msb.TestRunID), + Labels: mapTimeSeriesLabelsProto(timeSeries.Tags), } pbmetric.TimeSeries = append(pbmetric.TimeSeries, pbTimeSeries) msb.seriesIndex[timeSeries] = uint(len(pbmetric.TimeSeries) - 1) diff --git a/output/cloud/expv2/hdr.go b/output/cloud/expv2/hdr.go index 84ed6ffbb1d5..54ff939e4a18 100644 --- a/output/cloud/expv2/hdr.go +++ b/output/cloud/expv2/hdr.go @@ -184,8 +184,6 @@ func (h *histogram) appendBuckets(index uint32) { func histogramAsProto(h *histogram, time int64) *pbcloud.TrendHdrValue { hval := &pbcloud.TrendHdrValue{ Time: timestampAsProto(time), - MinResolution: 1.0, - SignificantDigits: 2, LowerCounterIndex: h.FirstNotZeroBucket, MinValue: h.Min, MaxValue: h.Max, diff --git a/output/cloud/expv2/hdr_test.go b/output/cloud/expv2/hdr_test.go index fdad798ef409..803dda2c2ce0 100644 --- a/output/cloud/expv2/hdr_test.go +++ b/output/cloud/expv2/hdr_test.go @@ -308,8 +308,6 @@ func TestHistogramAsProto(t *testing.T) { for _, v := range tc.vals { h.addToBucket(v) } - tc.exp.MinResolution = 1.0 - tc.exp.SignificantDigits = 2 tc.exp.Time = ×tamppb.Timestamp{Seconds: 1} assert.Equal(t, tc.exp, histogramAsProto(&h, time.Unix(1, 0).UnixNano()), tc.name) } diff --git a/output/cloud/expv2/integration/testdata/metricset.json b/output/cloud/expv2/integration/testdata/metricset.json index 7e43f01da131..4720f3522277 100644 --- a/output/cloud/expv2/integration/testdata/metricset.json +++ b/output/cloud/expv2/integration/testdata/metricset.json @@ -1,4 +1,6 @@ { + "testRunId": "my-test-run-id-123", + "aggregationPeriod": 3, "metrics": [ { "name": "metric_counter_1", @@ -6,20 +8,11 @@ "timeSeries": [ { "labels": [ - { - "name": "__name__", - "value": "metric_counter_1" - }, - { - "name": "test_run_id", - "value": "my-test-run-id-123" - }, { "name": "my_label_1", "value": "my_label_value_1" } ], - "aggregationPeriod": 3, "counterSamples": { "values": [ { @@ -37,20 +30,11 @@ "timeSeries": [ { "labels": [ - { - "name": "__name__", - "value": "metric_gauge_2" - }, - { - "name": "test_run_id", - "value": "my-test-run-id-123" - }, { "name": "my_label_2", "value": "my_label_value_2" } ], - "aggregationPeriod": 3, "gaugeSamples": { "values": [ { @@ -72,20 +56,11 @@ "timeSeries": [ { "labels": [ - { - "name": "__name__", - "value": "metric_rate_3" - }, - { - "name": "test_run_id", - "value": "my-test-run-id-123" - }, { "name": "my_label_3", "value": "my_label_value_3" } ], - "aggregationPeriod": 3, "rateSamples": { "values": [ { @@ -104,20 +79,11 @@ "timeSeries": [ { "labels": [ - { - "name": "__name__", - "value": "metric_trend_4" - }, - { - "name": "test_run_id", - "value": "my-test-run-id-123" - }, { "name": "my_label_4", "value": "my_label_value_4" } ], - "aggregationPeriod": 3, "trendHdrSamples": { "values": [ { @@ -128,9 +94,7 @@ ], "lowerCounterIndex": 6, "maxValue": 6, - "minResolution": 1, "minValue": 6, - "significantDigits": 2, "sum": 6 } ] @@ -139,4 +103,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/output/cloud/expv2/mapping.go b/output/cloud/expv2/mapping.go index 331b2b6b2aa9..7e083a3e6fba 100644 --- a/output/cloud/expv2/mapping.go +++ b/output/cloud/expv2/mapping.go @@ -10,15 +10,12 @@ import ( ) // TODO: unit test -func mapTimeSeriesLabelsProto(timeSeries metrics.TimeSeries, testRunID string) []*pbcloud.Label { - labels := make([]*pbcloud.Label, 0, ((*atlas.Node)(timeSeries.Tags)).Len()+2) - labels = append(labels, - &pbcloud.Label{Name: "__name__", Value: timeSeries.Metric.Name}, - &pbcloud.Label{Name: "test_run_id", Value: testRunID}) +func mapTimeSeriesLabelsProto(tags *metrics.TagSet) []*pbcloud.Label { + labels := make([]*pbcloud.Label, 0, ((*atlas.Node)(tags)).Len()) // TODO: move it as a shared func // https://github.com/grafana/k6/issues/2764 - n := (*atlas.Node)(timeSeries.Tags) + n := (*atlas.Node)(tags) if n.Len() < 1 { return labels }