From d81dd5ec9c3a8549c72b4b389ab2b2aff8fbb208 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 20 May 2020 02:49:49 +0300 Subject: [PATCH] Increase value precision in histograms from 5e-3 to 1e-12 Previously values could go into lower bucket because of too coarse precision. Updates https://github.com/VictoriaMetrics/metrics/issues/8 --- histogram.go | 2 +- histogram_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/histogram.go b/histogram.go index 6a72cc5..c187999 100644 --- a/histogram.go +++ b/histogram.go @@ -14,7 +14,7 @@ const ( decimalMultiplier = 2 bucketSize = 9 * decimalMultiplier bucketsCount = e10Max - e10Min - decimalPrecision = 0.01 / decimalMultiplier + decimalPrecision = 1e-12 ) // Histogram is a histogram for non-negative values with automatically created buckets. diff --git a/histogram_test.go b/histogram_test.go index 47edb5c..8001665 100644 --- a/histogram_test.go +++ b/histogram_test.go @@ -55,6 +55,12 @@ func TestGetBucketIdxAndOffset(t *testing.T) { f((1+prec)*math.Pow10(e10Max), -1, 2) f((1+3*step+prec)*math.Pow10(e10Max), -1, 2) f(math.Inf(1), -1, 2) + + f(999, 11, 17) + f(1000, 11, 17) + f(1001, 12, 0) + f(1002, 12, 0) + f(1003, 12, 0) } func TestGetVMRange(t *testing.T) {