Skip to content

Commit 1901853

Browse files
changkunmknyszek
authored andcommitted
runtime/metrics: fix panic in readingAllMetric example
medianBucket can return if the total is greater than thresh. However, if a histogram has no counts, total and thresh will both be zero and cause panic. Adding an equal sign to prevent the potential panic. Fixes #44148 Change-Id: Ifb8a781990f490d142ae7c035b4e01d6a07ae04d Reviewed-on: https://go-review.googlesource.com/c/go/+/290171 Trust: Ian Lance Taylor <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Run-TryBot: Michael Knyszek <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent ed3e4af commit 1901853

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/runtime/metrics/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func medianBucket(h *metrics.Float64Histogram) float64 {
8888
total = 0
8989
for i, count := range h.Counts {
9090
total += count
91-
if total > thresh {
91+
if total >= thresh {
9292
return h.Buckets[i]
9393
}
9494
}

0 commit comments

Comments
 (0)