From 162612ea8627447be0b8fa170268b76524124bbc Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 12 Jul 2023 14:52:49 +0200 Subject: [PATCH] histograms: Improve comment Oversight during review of #12525. Signed-off-by: beorn7 --- promql/quantile.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/promql/quantile.go b/promql/quantile.go index 793a6629f..7f48b5945 100644 --- a/promql/quantile.go +++ b/promql/quantile.go @@ -205,9 +205,10 @@ func histogramQuantile(q float64, h *histogram.FloatHistogram) float64 { return bucket.Upper } - // if there are NaN observations in the histogram (h.Sum is NaN), use the forward iterator - // if the q < 0.5, use the forward iterator - // if the q >= 0.5, use the reverse iterator + // NaN observations increase h.Count but not the total number of + // observations in the buckets. Therefore, we have to use the forward + // iterator to find percentiles. We recognize histograms containing NaN + // observations by checking if their h.Sum is NaN. if math.IsNaN(h.Sum) || q < 0.5 { rank -= count - bucket.Count } else {