Fix traceql exemplar distribution #5129
Closed
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 this PR does:
Adds a new package
exemplardist
that implements an algorithm to fix the issue where TraceQL metrics exemplars cluster on one side of the visualization instead of being distributed homogeneously across the time range. This package provides a bucketing algorithm to evenly distribute exemplars across the time range while preserving their representative quality.Which issue(s) this PR fixes:
Fixes #4856
Checklist
CHANGELOG.md
updated - Not updated since this is a standalone utility packageAdditional Notes
This PR only adds the
exemplardist
package without modifying the core Tempo code. Direct integration into the core codebase was attempted but caused test failures due to the complex interactions with existing code.The package provides a clean API that can be used at various integration points:
This solution uses a bucketing algorithm that:
The implementation is tested to work with various distributions (uniform, left-skewed, right-skewed, clustered) and correctly improves the distribution quality in all cases.