Closed bw972 closed 1 year ago
Thanks for filing this. Rather than make it produce a zero, I made it produce a null value in this PR, since we can't compute a quantile at all in the absence of any observations: https://github.com/influxdata/flux/pull/5419
Description
There is an issue with the Flux
histogramQuantile()
function that causes it to display incorrect results. Specifically, when trying to calculate the quantile for a histogram with no new observations (therefore, a total count of observations in the buckets is zero), the function fails to return the expected result.Steps to Reproduce
histogramQuantile()
function.Expected Behaviour
The
histogramQuantile()
function should return nothing if the total count of the buckets is zero.Actual Behaviour
The
histogramQuantile()
function returns the value of the highest bucket. This is becauserankIdx
will always be the highest bucket, asrank ≥ b.count
will always be true ifrank := t.spec.Quantile * totalCount
is zero andb.count
is also zero. TherankIdx
switch case then assumes that the quantile lies above the highest upper bounds and returns the highest upper bound as the result.Possible Solution
Add a return condition to the
computeQuantile()
function inhistogram_quantile.go
that checks if thetotalCount
is zero.