Fix panic when topk() reduces series below maxSeries in QueryRange - #6010
Merged
mdisibio merged 3 commits intoDec 1, 2025
Merged
Conversation
Syedowais312
requested review from
carles-grafana,
electron0zero,
ie-pham,
javiermolinar,
joe-elliott,
mapno,
mattdurham,
mdisibio,
ruslan-mikhailov,
stoewer,
yvrhdn and
zalegrala
as code owners
November 27, 2025 17:15
Contributor
|
Thanks for taking care of this. Fix looks good, can you add a changelog.md entry? And we'll merge. |
Contributor
Author
Changelog entry added. Let me know if anything else is needed! |
mdisibio
reviewed
Dec 1, 2025
mdisibio
approved these changes
Dec 1, 2025
mdisibio
enabled auto-merge (squash)
December 1, 2025 13:08
mattdurham
pushed a commit
to mattdurham/tempo
that referenced
this pull request
Jun 18, 2026
…rafana#6010) * fix(query-range): prevent slice panic when truncating series after topk() * docs: Update CHANGELOG.md for metrics-topk-maxseries fix * Update CHANGELOG.md --------- Co-authored-by: Martin Disibio <mdisibio@gmail.com>
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.
Fixes #6000
Summary
Fixes a crash in QueryRange when the internal series limit is reached while using
topk()orbottomk().These functions reduce the series count before truncation, causing an out-of-bounds slice.
Root Cause
MaxSeriesReached()triggers truncation using:resp.Series = resp.Series[:maxSeries]But after topk(10), the response may contain fewer series than maxSeries, leading to:
panic: slice bounds out of rangeFix
Added a conditional check:
This prevents slicing beyond available series.
Tests