Skip to content

feat(query): InstantVectorElement carries per-element label_keys_override - #260

Merged
zzylol merged 1 commit into
mainfrom
instant-vector-element-label-keys
May 16, 2026
Merged

zzylol merged 1 commit into
mainfrom
instant-vector-element-label-keys

Conversation

@zzylol

@zzylol zzylol commented May 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes the InstantVectorElement label gap from PR #258. Adds an Option<Vec<String>> field (mirroring the existing field on RangeVectorElement) so per-element synthesized keys — notably ASAP-tier `topk(...)`'s `"item": ` — surface through the Prometheus adapter on instant-vector responses.

Changes

  • InstantVectorElement + with_label_keys_override helper (query_result.rs) — matches the existing RangeVectorElement shape exactly.
  • asap_tier_result_to_query_result's instant-vector branch stops discarding the BTreeMap keys at engine.rs:3443. Same fix PR fix(query): dispatch Vector vs Matrix in asap_tier_result_to_query_result #256 applied to the range-vector branch.
  • convert_query_result_to_prometheus picks element.label_keys_override over the query-scoped KeyByLabelNames, mirroring convert_range_result_to_prometheus.
  • Tests 8+9 strict-success tightening — assert metric.item == "gamma" for topk(3, top_endpoint_qps). The fact-check that previously couldn't run without this fix.

Test plan

  • cargo test --test e2e_controller_plans_and_backend_serves — all 9 pass with strict item: \"gamma\" assertion
  • cargo test --workspace --lib — 1549 pass, 0 fail

🤖 Generated with Claude Code

…ride

Mirrors `RangeVectorElement` — adds an optional `label_keys_override:
Option<Vec<String>>` field so per-element keys (synthesized by
ASAP-tier `topk(...)` as `"item": <key>`) surface through the
Prometheus adapter on instant-vector responses, not just range-vector.

Three-line change spanning three files:
  - `InstantVectorElement` gains the field + `with_label_keys_override`
    helper (query_result.rs).
  - `asap_tier_result_to_query_result`'s instant-vector branch stops
    discarding the BTreeMap keys (engine.rs:3443) — the same fix
    PR #256 applied to the range-vector branch.
  - `convert_query_result_to_prometheus` picks per-element override
    over the query-scoped `KeyByLabelNames`, mirroring
    `convert_range_result_to_prometheus` (http.rs).

Tests 8+9 in `e2e_controller_plans_and_backend_serves.rs` tighten
their `topk(3, top_endpoint_qps)` assertions to verify
`metric.item == "gamma"` is present in at least one returned series
— the strict invariant that previously couldn't be checked because
the adapter dropped the synthesized key.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit c34a1ac into main May 16, 2026
zzylol added a commit that referenced this pull request May 16, 2026
Closes the range-query gap I documented in PR #260's session
follow-up. Per-user direction (2026-05-16): count_over_time is
warm-tier-answerable by sampling; topk_over_time isn't standard
PromQL anyway and falls through to the cold tier (Thanos parse-
error is acceptable).

Sibling of PR #253's instant-query trait-dispatch fallback. New
`ASAPQueryEngine::execute_range_promql_modern(query, start_ms,
end_ms, step_ms)` mirrors the analyzer + reducer dispatch from
the `QueryEngine::execute(&str)` trait surface but returns
Matrix per the `/api/v1/query_range` wire-format spec.

Wire-up: `process_range_query_request` in `http.rs` tries
`handle_range_query_promql` first (legacy path, unchanged), and
on `None` calls the new modern method. If the modern path also
errors, it falls through to `format_unsupported_query_response`
(which the EngineRouter can route to a cold-tier fallback).

Prometheus semantics note: the spec says evaluate at each
`t = start, start+step, …, end`. The warm tier returns samples
at native window-close granularity instead — finer than the
user's step when window_size < step (more data, not less).
Step-precise evaluation is a future refinement; clients that
need exact step timestamps can downsample, or route step-
precise queries to the cold tier.

Test 10 (`controller_plan_to_range_query_count_over_time_cms`)
ingests heap-less CMS DPs via the same setup as Test 7, then
queries `count_over_time(endpoint_request_freq[10s])` via
`/api/v1/query_range`. Asserts `status=success`,
`resultType=matrix`, non-empty series.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol deleted the instant-vector-element-label-keys branch July 17, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant