From a9d0066408f653a4cd88a4303bbfad976fe20f1d Mon Sep 17 00:00:00 2001 From: beorn7 Date: Mon, 13 Apr 2020 16:43:23 +0200 Subject: [PATCH] Add note about pow-of-10 precision issue Signed-off-by: beorn7 --- prometheus/histogram.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/prometheus/histogram.go b/prometheus/histogram.go index e7aed2b..d73b28e 100644 --- a/prometheus/histogram.go +++ b/prometheus/histogram.go @@ -531,6 +531,11 @@ func (h *histogram) observe(v float64, bucket int) { case v < -h.sparseThreshold: whichSparse = -1 } + // TODO(beorn7): This sometimes gives inaccurate results for + // floats that are actual powers of 10, e.g. math.Log10(0.1) is + // calculated as -0.9999999999999999 rather than -1 and thus + // yields a key unexpectedly one off. Maybe special-case precise + // powers of 10. sparseKey = int(math.Ceil(math.Log10(math.Abs(v)) * float64(h.sparseResolution))) } // We increment h.countAndHotIdx so that the counter in the lower