We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aaa3f32 commit e3cc4e4Copy full SHA for e3cc4e4
prometheus/histogram.go
@@ -858,13 +858,16 @@ func (h *histogram) Write(out *dto.Metric) error {
858
// findBucket returns the index of the bucket for the provided value, or
859
// len(h.upperBounds) for the +Inf bucket.
860
func (h *histogram) findBucket(v float64) int {
861
+ n := len(h.upperBounds)
862
+ if n == 0 {
863
+ return 0
864
+ }
865
+
866
// Early exit: if v is less than or equal to the first upper bound, return 0
867
if v <= h.upperBounds[0] {
868
return 0
869
}
870
- n := len(h.upperBounds)
-
871
// Early exit: if v is greater than the last upper bound, return len(h.upperBounds)
872
if v > h.upperBounds[n-1] {
873
return n
0 commit comments