promql: fix avg_over_time for single native histogram#18058
Merged
beorn7 merged 2 commits intoprometheus:mainfrom Feb 11, 2026
Merged
promql: fix avg_over_time for single native histogram#18058beorn7 merged 2 commits intoprometheus:mainfrom
beorn7 merged 2 commits intoprometheus:mainfrom
Conversation
Add regression test for the bug where avg_over_time with a single histogram sample would produce +Inf count/sum and NaN zero bucket due to division by zero. The test verifies that both regular exponential histograms and native histograms with custom buckets (NHCB) correctly return the histogram unchanged when averaging a single sample. Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
avg_over_time would produce +Inf count/sum and NaN zero bucket when averaging a single histogram, because the count variable was initialized to 0 instead of 1. This caused a division by zero at the end of the function. The float version of avg_over_time already correctly initializes count to 1, this change makes the histogram version consistent with that. Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
linasm
approved these changes
Feb 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When running avg_over_time for a single native histogram, we get infinite count and sum due to a divide by 0 error, which we fix by initialising count to 1 (similar to what we do for float samples).
Commits generated with Copilot.
Which issue(s) does the PR fix:
N/A
Does this PR introduce a user-facing change?