diff --git a/histogram.go b/histogram.go index ebdd00d..e1a168c 100644 --- a/histogram.go +++ b/histogram.go @@ -94,7 +94,7 @@ func (h *Histogram) Update(v float64) { h.upper++ } else { idx := uint(bucketIdx) - if bucketIdx == float64(idx) { + if bucketIdx == float64(idx) && idx > 0 { // Edge case for 10^n values, which must go to the lower bucket // according to Prometheus logic for `le`-based histograms. idx-- diff --git a/histogram_test.go b/histogram_test.go index 7da4045..dea989b 100644 --- a/histogram_test.go +++ b/histogram_test.go @@ -97,6 +97,8 @@ prefix_count 120 h.Update(math.Inf(-1)) h.Update(math.NaN()) h.Update(-123) + // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1096 + h.Update(math.Float64frombits(0x3e112e0be826d695)) // Make sure the histogram becomes visible in the output of WritePrometheus, // since now it contains values.