Repository navigation
Conversation
A planned /api/v1/query_range runs one evaluation per step, start + k*step through end, and returns a Prometheus matrix. Each query-time raw range is fetched from Prometheus once for all steps and sliced per step; each kept definition's missing panes are fetched once, so a kept pane built at one step is reused by the later ones. Stored panes are read per step. If any step cannot be answered, the whole request is forwarded with the reason. start/end accept Unix seconds or RFC 3339 (now also for instant queries), step float seconds or a Prometheus duration; requests Prometheus would reject, and requests with a nonzero limit, are forwarded unchanged.
This was referenced Oct 19, 2026
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.
Stack 7/7. Base: #824.
Why
The data plane forwarded every
/api/v1/query_rangerequest, so a dashboard panel was never answered by the selected plan, even when the plan would answer each of its steps as an instant query. The design's query engine section defines range queries as one evaluation per step that shares raw samples, stored panes and kept results across steps.What
query_rangeruns one evaluation per step,T = start + k·stepthroughend(inclusive), and returns a Prometheus matrix withx-asap-execution: plan.(start − offset − range, end − offset], and sliced per step.MatAtIngestion) as an instant evaluation would.MatAtQueryKeptAcrossEvaluations), the panes no evaluation has kept are fetched in one request covering all steps. A pane built at one step is reused by the later steps. feat(query): keep query-time panes across evaluations #824's rules still apply with one watermark for the whole request: a pane is kept only once it is closed, so an open pane is recomputed at each step that reads it, and eviction is measured from the newest evaluation.x-asap-forward-reason. A range query that partly reads evicted panes is forwarded whole, as the design says. Unplanned range queries are forwarded unchanged with no reason.start/endtake Unix seconds or RFC 3339.steptakes float seconds or a Prometheus duration (30s,1h30m; unitsy w d h m s ms, in order). A request Prometheus would reject is forwarded unchanged so Prometheus returns its own error: a missing parameter,end < start,step ≤ 0, or more than 11,000 steps. A nonzerolimitis also forwarded unchanged, for both endpoints. Instant queries now accept RFC 3339timetoo.How
QueryEngine::raw_ranges_for_stepschecks every step's stored panes. It returns oneRawRangeper query-time raw input, spanning all steps, and one per kept definition, spanning its missing panes (keyed by the definition'sraw_input). The HTTP side fetches each range once.QueryEngine::evaluate_stepssplits each fetched vector into per-series runs once. It then walks the steps in order, slices each step's samples by binary search within each run, and callsevaluatefor that step. Series order matches the instant path, so every step's input matches the input of the same instant query. The engine thread runs the request as two commands,RawRangesForStepsandEvaluateSteps, with the precompute watermark as of the request.Key code interfaces added / modified
Cost, for a request with S steps
R is the number of query-time raw ranges the root reads. K is the number of kept definitions with a pane not yet kept at request time (0 or 1 in B3). Each step slices its samples in O(series · log n + slice). A pane that is still open is rebuilt at every step that reads it. Samples fetched per raw input cover
end − start + range, againstS · rangefor instant queries. So whenstep > rangethe single fetch also reads samples that no step uses.Before this PR
Every range query went to Prometheus, including planned ones.
After this PR
The same request is answered by the plan. Its 7 steps read one raw range from Prometheus, and each step equals the instant query at that time.
Usage
Run on this PR's tree. A Prometheus 2.53.2 is backfilled (
promtool tsdb create-blocks-from openmetrics) with Example 1's threehttp_requests_totalseries, one sample every 15 s for 10 minutes fromT0 = 1792332000, each a quadratic counter(i+1)·(t−T0)².Prometheus 2.53 answers the same
ratequery with 900, 1080, …, not 945, 1125, …. That gap comes from #821, not from this PR. Prometheus 2 includes the sample atT − 1min the range, while the plan's ranges are left-open(T − 1m, T], the PromQL range convention the Planner executor uses.Forwarding with a reason needs a plan with stored panes, so it is covered over HTTP in
answers.rs. For Example 4b at 90 to 100 min,step=5mis forwarded with… is not on the 600000 ms pane grid, andstart=80mwithpane ending at … is not stored.End-to-end numbers
cargo test -p data_plane --test e2e_examples -- --nocaptureruns thedata_planebinary over HTTP against a stand-in Prometheus that counts raw range reads. Each step is compared with the Planner executor's reference (the selected plan run entirely at query time) and with the same instant query.sum by (job) (rate(...[1m]))30stopk by (job) (10, sum_over_time(...[1m]))30s[60m]10m[5m]60In
data_plane/tests/range.rs, the B3 range over 10 to 14 min givesKeptResultStats { built: 9, reused: 16 }, against 25 builds for five unshared evaluations. Run again, it gives{ built: 15, reused: 35 }. With the watermark at 12 min it gives{ built: 10, reused: 15 }: the open panes ending at 13 and 14 min are rebuilt.Planner notes (no Planner change)
stepequal to a pane width shares panes across steps, and can't price a range query's span. Kept retention also covers only the newest evaluation's window (largest offset plus two widths), so a dashboard refreshing[now − 1h, now]rebuilds the panes of its early steps on every refresh.Limitations
step > range, that fetch includes samples no step reads.timeoutparameter is ignored, as for instant queries.Verification
Tests were written first. Each failed against interface stubs (
Unsupported("range queries"), or a forwarded response) before the implementation. The two forwarding-unchanged HTTP tests already passed, because forwarding was the old behavior; they guard it. The implementation author also designed these tests, so they are not independent.data_plane/src/prometheus.rsunit tests (4 new): parsing ofstart/end/step(float, RFC 3339, durations), rejected requests (missing parameters,end < start,step ≤ 0, bad duration, more than 11,000 steps, nonzerolimit), end-inclusive steps, and the matrix format.data_plane/tests/range.rs(4 tests): (b) Example 1 fetches one raw range(2 min, 6 min]for 7 steps, and each step equals its instant query. (c) Example 4b steps read stored panes only, with no raw ranges. A step off the grid, or a step reading an evicted pane, isMissingPane. (d) B3 reuses kept panes, withkept_statsas above, and an open pane is recomputed at each step.data_plane/tests/answers.rs(3 new, HTTP): a planned range query returns a matrix whose values equal the instant queries, forstepgiven as10m,600or600.0. (e) An off-grid step, or a step reading an evicted pane, forwards the whole request with a reason. (f) Unplanned or invalid range queries are forwarded unchanged with no reason.data_plane/tests/e2e_examples.rs(3 new): (a)example1_range,example4b_rangeandexample4_b3_rangecompare against the executor reference and the instant queries, with read counts as in the table.cargo test -p control_plane -p data_plane: all pass (e2e: 9 tests in 376 s, debug).cargo fmt --all -- --checkandcargo clippy --workspace --all-targets --locked -- -D warningspass.