fix: warm-tier topk preserves per-element label keys - #127
Merged
Merged
Conversation
#124's warm-tier topk reducer synthesizes an `"item"` label key for each top-k entry (the item identity), but the `warm_tier_result_to_query_result` adapter then collapsed the result's `BTreeMap<key,value>` to a `KeyByLabelValues` (values only — `Vec<String>`). The HTTP serializer pairs those values with KEYS from a query-scoped `KeyByLabelNames`, which carries the PromQL group-by clause — and the PromQL `topk(5, foo)` has NO group-by. So the synthesized `"item"` key disappeared and the PromQL response showed `"metric": {}` for every top-k entry. Fix: - `RangeVectorElement` gains an optional `label_keys_override: Option<Vec<String>>` field. Default `None` — all existing constructors unaffected. - `convert_range_result_to_prometheus` uses the override when present, falls back to the query-scoped `label_names` otherwise. - `warm_tier_result_to_query_result` populates the override from the BTreeMap's keys (BTreeMap iteration is key-sorted, so it pairs correctly with the values). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.
Summary
#124's warm-tier topk reducer synthesizes an
"item"label key for each top-k entry (the item identity), but thewarm_tier_result_to_query_resultadapter collapsed the result'sBTreeMap<key,value>to aKeyByLabelValues(values only —Vec<String>). The HTTP serializer pairs those values with KEYS from a query-scopedKeyByLabelNames, which carries the PromQL group-by clause — andtopk(5, foo)has NO group-by. So the synthesized"item"key disappeared and the PromQL response showed"metric": {}for every top-k entry.This is the bug surfaced in the MVP demo's smoke run:
topk(5, top_endpoint_qps)returned 5 anonymous{}objects instead of named items.Fix
RangeVectorElementgains an optionallabel_keys_override: Option<Vec<String>>field. DefaultNone— all existing constructors unaffected, no breaking change.RangeVectorElement::with_label_keys_override(keys)builder.convert_range_result_to_prometheususes the override when present, falls back to the query-scopedlabel_namesotherwise.warm_tier_result_to_query_resultpopulates the override from the BTreeMap's keys (BTreeMap iteration is key-sorted, so it pairs correctly with the values pulled frominto_values()).This applies to every warm-tier path, not just topk —
Capability::FrequencyTopksynthesizes"item", butQuantileApprox/CardinalityApproxpaths also benefit when the sketch instance'sgroup_by_keysdiffers from the query's group-by clause.Verification
cargo build --release -p query_engine_rustcleancargo test --release -p query_engine_rust --lib -- engines::warm_tier engines::query_result— 30/30 passDiff
🤖 Generated with Claude Code