TraceQL Metrics: Fix incorrect optimization for some queries#4887
Merged
mdisibio merged 3 commits intografana:mainfrom Mar 25, 2025
Merged
TraceQL Metrics: Fix incorrect optimization for some queries#4887mdisibio merged 3 commits intografana:mainfrom
mdisibio merged 3 commits intografana:mainfrom
Conversation
stoewer
approved these changes
Mar 25, 2025
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 this PR does:
A bug was identified with traceql metrics where some queries return incorrect data, see screenshot:
In this example it is returning other values for
http.flavoreven though it is clearly restricted to a single value in the query.The bug is that traceql metrics engine has optimizations for performance that expect behavior from the storage layer that wasn't happening. Specifically, the parquet layer isn't (and never has) honored AllConditions=true when there are multiple attributes of the same type being filtered in the generic attribute columns. It requires the engine callback to finalize the resultset, which traceql metrics is trying to optimize away.
This fix excludes these queries from optimization and fixes their output. Because this is not the first bug in this area, see #4409, going ahead and over-excluding to err on the side of correctness, but still able to support many queries, including all of the ones in the benchmark.
Affected queries will definitely be slower, but it might not be too bad. Because it's also processing fewer spans, it could mostly even out. Add a benchmark for an affected query, and it's only 1.6% slower overall.
It's tempting to disable this optimization altogether, but it still has a significant benefit, ~50% faster for simple queries like `{} | rate() by (resource.service.name).
Which issue(s) this PR fixes:
Fixes #
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]