properly handle Histogram.Update(1e-9)

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1096
This commit is contained in:
Aliaksandr Valialkin 2021-03-01 16:46:59 +02:00
parent 16e4558792
commit 57c9db1bc3
2 changed files with 3 additions and 1 deletions

View File

@ -94,7 +94,7 @@ func (h *Histogram) Update(v float64) {
h.upper++ h.upper++
} else { } else {
idx := uint(bucketIdx) 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 // Edge case for 10^n values, which must go to the lower bucket
// according to Prometheus logic for `le`-based histograms. // according to Prometheus logic for `le`-based histograms.
idx-- idx--

View File

@ -97,6 +97,8 @@ prefix_count 120
h.Update(math.Inf(-1)) h.Update(math.Inf(-1))
h.Update(math.NaN()) h.Update(math.NaN())
h.Update(-123) 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, // Make sure the histogram becomes visible in the output of WritePrometheus,
// since now it contains values. // since now it contains values.