New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google Cloud Monitoring: Fix bucket bound for distributions #56565
Conversation
"8", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not really represent reallity since in BucketCounts
if the rest of values are 0, it's just ommited for performance reasons (that's why usually BucketCounts.length is smaller than the ExplicitBounds) but it's helpful to represent the issue in a unit test.
Backend code coverage report for PR #56565
|
Frontend code coverage report for PR #56565 |
Drone build failed: https://drone.grafana.net/grafana/grafana-enterprise/36789 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code here looks fine to me. I'm not overly familiar on GCM so would benefit from a more in-depth explanation of the problem if possible 😊
The problem is basically that the number of "buckets" (metric) is bigger than the number of the bucket "bounds" or limits. Prior to this PR, it was not considered values over the last limit but it's something that can happen. A couple of examples to try to explain it.
For this case,
For this case, the Hopefully that is more clear, but let me know if you have more questions, we can jump into a call :) |
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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we simplify with ternary operator:
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) | |
} | |
i := n < len(bucketOptions.ExplicitBuckets.Bounds) ? n : len(bucketOptions.ExplicitBuckets.Bounds)-1 | |
bucketBound = fmt.Sprintf("%g+",bucketOptions.ExplicitBuckets.Bounds[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no ternary operator in Go :) Also, the +
of %g+
is only added for the case in which the index is outside bounds
(cherry picked from commit 65e56c9)
(cherry picked from commit 65e56c9)
What this PR does / why we need it:
In a DISTRIBUTION response, there are two values that affect this PR:
BucketCounts
andExplicitBuckets.Bounds
. For the following values:It means that the bucket {-Inf:0} has 0 values, {0:10} has 1, {10:20} has 2 and {20:+Inf} has 3.
Since we are using the upper bound to generate the frame name, frame names should be: 0, 10, 20 and 20+.
Prior to this PR, values outside the last bound were not taken into account causing a
panic
error.Which issue(s) this PR fixes:
Fixes #56181
Special notes for your reviewer: