histograms: Improve comment

Oversight during review of #12525.

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2023-07-12 14:52:49 +02:00
parent 5da638d527
commit 162612ea86
1 changed files with 4 additions and 3 deletions

View File

@ -205,9 +205,10 @@ func histogramQuantile(q float64, h *histogram.FloatHistogram) float64 {
return bucket.Upper return bucket.Upper
} }
// if there are NaN observations in the histogram (h.Sum is NaN), use the forward iterator // NaN observations increase h.Count but not the total number of
// if the q < 0.5, use the forward iterator // observations in the buckets. Therefore, we have to use the forward
// if the q >= 0.5, use the reverse iterator // 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 { if math.IsNaN(h.Sum) || q < 0.5 {
rank -= count - bucket.Count rank -= count - bucket.Count
} else { } else {