From 356883d0a5682bec3d7f489a6d3837533014a80e Mon Sep 17 00:00:00 2001 From: Andres Martinez Gotor Date: Mon, 10 Oct 2022 16:08:33 +0200 Subject: [PATCH] Google Cloud Monitoring: Fix bucket bound for distributions (#56565) (cherry picked from commit 65e56c9fb85f74ae86323e45699a1d9513d4c8f3) --- pkg/tsdb/cloudmonitoring/cloudmonitoring.go | 7 +++++- ...series-response-distribution-explicit.json | 22 +++++++++++++++++-- .../time_series_filter_test.go | 4 ++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/pkg/tsdb/cloudmonitoring/cloudmonitoring.go b/pkg/tsdb/cloudmonitoring/cloudmonitoring.go index 65f622737d91..d6d4277f9c5b 100644 --- a/pkg/tsdb/cloudmonitoring/cloudmonitoring.go +++ b/pkg/tsdb/cloudmonitoring/cloudmonitoring.go @@ -596,7 +596,12 @@ func calcBucketBound(bucketOptions cloudMonitoringBucketOptions, n int) string { case bucketOptions.ExponentialBuckets != nil: bucketBound = strconv.FormatInt(int64(bucketOptions.ExponentialBuckets.Scale*math.Pow(bucketOptions.ExponentialBuckets.GrowthFactor, float64(n-1))), 10) case bucketOptions.ExplicitBuckets != nil: - bucketBound = fmt.Sprintf("%g", bucketOptions.ExplicitBuckets.Bounds[n]) + if n < len(bucketOptions.ExplicitBuckets.Bounds) { + bucketBound = fmt.Sprintf("%g", bucketOptions.ExplicitBuckets.Bounds[n]) + } else { + lastBound := bucketOptions.ExplicitBuckets.Bounds[len(bucketOptions.ExplicitBuckets.Bounds)-1] + bucketBound = fmt.Sprintf("%g+", lastBound) + } } return bucketBound } diff --git a/pkg/tsdb/cloudmonitoring/test-data/4-series-response-distribution-explicit.json b/pkg/tsdb/cloudmonitoring/test-data/4-series-response-distribution-explicit.json index 98435294762b..c85be476c672 100644 --- a/pkg/tsdb/cloudmonitoring/test-data/4-series-response-distribution-explicit.json +++ b/pkg/tsdb/cloudmonitoring/test-data/4-series-response-distribution-explicit.json @@ -103,7 +103,16 @@ "4", "7", "12", - "8" + "8", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0" ] } } @@ -198,7 +207,16 @@ "5", "7", "11", - "8" + "8", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0" ] } } diff --git a/pkg/tsdb/cloudmonitoring/time_series_filter_test.go b/pkg/tsdb/cloudmonitoring/time_series_filter_test.go index 4fe5fda29ad1..81b3f8775706 100644 --- a/pkg/tsdb/cloudmonitoring/time_series_filter_test.go +++ b/pkg/tsdb/cloudmonitoring/time_series_filter_test.go @@ -185,8 +185,8 @@ func TestTimeSeriesFilter(t *testing.T) { require.NoError(t, err) frames := res.Frames require.NoError(t, err) - assert.Equal(t, 33, len(frames)) - for i := 0; i < 33; i++ { + assert.Equal(t, 42, len(frames)) + for i := 0; i < 42; i++ { if i == 0 { assert.Equal(t, "0", frames[i].Fields[1].Name) }