Repository navigation
Fix legendValue median, percentile and max on series data - #578
Merged
timtofan merged 2 commits intoOct 20, 2026
Merged
Conversation
Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
sebxt
requested review from
deniszh,
emadolsky,
grzkv and
timtofan
as code owners
October 20, 2026 12:02
timtofan
approved these changes
Oct 20, 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.
What issue is this change attempting to solve?
legendValue(x, 'median')andlegendValue(x, 'pNN')reorder the datapoints of the returned series and of the fetched source series, becausehelper.Percentilesorts its input in place andhelper.SummarizeValuespasses the series values to it directly. Themedian,pNNandmaxbranches ofSummarizeValuesalso include absent points (stored as 0), which gives a wrong median for series with gaps and a max of 0 for negative series with gaps.sortByMaximauses the samemaxbranch.How does this change solve the problem? Why is this the best approach?
SummarizeValuesnow builds a new slice of the non absent values before callingPercentile, and themaxbranch skips absent points likemin,avg,lastandcountalready do. This keeps the fix in the shared helper, so every caller gets the same behaviour.summarizealready passes only present values with allabsentflags false, so its results do not change.How can we be sure this works as expected?
Added three
legendValuecases toTestEvalExpression: median on an unsorted series (checks the values and that the source data is not modified), median on a series with gaps, and max on a negative series with a gap. They fail on master and pass with the change.go test -race ./...passes.Fixes #577