Skip to content

Commit e3cc4e4

Browse files
committed
fix: zero-lenght h.upperBounds
Signed-off-by: Ivan Goncharov <i.morph@gmail.com>
1 parent aaa3f32 commit e3cc4e4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

prometheus/histogram.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,13 +858,16 @@ func (h *histogram) Write(out *dto.Metric) error {
858858
// findBucket returns the index of the bucket for the provided value, or
859859
// len(h.upperBounds) for the +Inf bucket.
860860
func (h *histogram) findBucket(v float64) int {
861+
n := len(h.upperBounds)
862+
if n == 0 {
863+
return 0
864+
}
865+
861866
// Early exit: if v is less than or equal to the first upper bound, return 0
862867
if v <= h.upperBounds[0] {
863868
return 0
864869
}
865870

866-
n := len(h.upperBounds)
867-
868871
// Early exit: if v is greater than the last upper bound, return len(h.upperBounds)
869872
if v > h.upperBounds[n-1] {
870873
return n

0 commit comments

Comments
 (0)