Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The histogramQuantile function returns an incorrect value when there are no observations in the histogram #5415

Closed
bw972 opened this issue May 6, 2023 · 1 comment · Fixed by #5419
Assignees

Comments

@bw972
Copy link

bw972 commented May 6, 2023

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

  1. There is a Prometheus histogram in InfluxDB (v2 mapping) that is not currently being incremented due to zero traffic condition.
  2. Try to plot the quantile of the histogram using the histogramQuantile() function.
  3. Notice that the resulting plot defaults the result to the value of the highest bucket boundary in the histogram, even though there have been no observations in this period.

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 because rankIdx will always be the highest bucket, as rank ≥ b.count will always be true if rank := t.spec.Quantile * totalCount is zero and b.count is also zero. The rankIdx 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 in histogram_quantile.go that checks if the totalCount is zero.

if totalCount == 0 {
    return 0, false, nil
  }
@wolffcm
Copy link

wolffcm commented May 26, 2023

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:
#5419

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants