From 57c9db1bc36dbb6432817983c4d3af2aa6090b17 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 1 Mar 2021 16:46:59 +0200 Subject: [PATCH] properly handle Histogram.Update(1e-9) Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1096 --- histogram.go | 2 +- histogram_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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.