Skip to content

test(planner): counter rate and increase answers, installed and at query time - #1343

Merged
zzylol merged 1 commit into
mainfrom
test/1338-counter-rate-answers
Nov 16, 2026
Merged

zzylol merged 1 commit into
mainfrom
test/1338-counter-rate-answers

Conversation

@zzylol

@zzylol zzylol commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: sum by (job)(rate(requests_total[5m])) and sum by (job)(increase(requests_total[5m])) return no rows when the selected plan runs in one query run over the raw samples. Nothing tests this.
  • Change: tests only. They check counter rate and increase per series, per job and in total against hand-worked answers. Each query is answered two ways (as installed, and in a query run over the raw samples), on a deployment that keeps raw data and on one that does not.
  • Effect: the query-run test fails on main for 8 of 12 cases. Example: sum by (job)(increase(requests_total[5m])) answers []; the expected answer is j1: 60, j2: 140. The fix PR stacked on this one makes it pass.

Refs #1338.

Review guide

Rebased onto main 863153e3c

Head 697178e05 (was 49703618e) is rebased onto main 863153e3c (after #1237, #1242, #1309, #1339, #1330, #1324 and #1300). Conflicts and resolutions, all in the tests:

  • crates/planner/tests/runtime_install.rs: main moved the sample, run, answers and assert_answers_near helpers into the shared tests/time_series module and deleted CountingStore. This PR's copies are dropped. counter_samples and counter_queries now build their samples and label sets with time_series::sample and labels. installed_answers builds one store (time_series_tables plus append_materialized_view for each view's windows), so the WindowState alias is gone.
  • crates/planner/tests/time_series/mod.rs: run takes views: &[MaterializedView], the views it binds as materialized view slots. Its callers in metricsql_workloads.rs and reduce_aggregates.rs pass &[]. Since the runtime change in main (fix(executor): run each node by its plan Lifetime, so roots drain in any order #1300), it runs an ingestion scope through execute_ingestion and a query scope through execute.

Example and cause (what the tests show)

The workload: one query every 10 s within relative error 0.01. The source is 1,000 requests_total counter series sampled every second. The test data is four series, a..d. Jobs j1 = {a, b} and j2 = {c, d}. Each series has one sample every 15 s over the 8 minutes before T. Series i counts (i + 1) * step.

The selected plan for the grouped query:

0 Scan requests_total
1 SummaryTumblingWindowChain ExactAggregate(Increase) PerEntity, 10 s windows   (ingestion time, materialized view)
2 TimeRange 300s → 3 SummaryMerge → 4 FinalizeExactAccumulator → 5 SummaryAgg Sum by job → 6 Finalize
How it is answered sum by (job)(increase(..[5m])) at T
As installed: chain built in 30 ingestion runs, read from its view j1: 60, j2: 140 (correct)
One query run over raw samples, no view bound no rows

In the query run, the chain at ingestion time is built as an ingestion run builds it: only its newest window, (T − 10 s, T]. Each series has at most one sample there, and the finalize drops a counter with fewer than two samples. This is the harness that #1338 and the MetricsQL test use (compile(&plan.dag, &[], roots)).

Interfaces

None (tests only).

Algorithm changes

None.

Design scope

No new types or files. The new helpers stay inside the existing runtime_install.rs test file, which tests installing and running plans as a deployment runtime does: plan_counter_query, counter_samples, counter_queries, installed_answers and counter_query_mismatches.

Decisions and open questions

None.

Verification

On 697178e05, compared by test name with main 863153e3c built the same way:

Scope This PR main Newly failing
cargo check --workspace --all-targets clean clean
cargo fmt --all -- --check clean clean
cargo clippy -p asap-executor -p asap-planner --all-targets -- -D warnings clean clean
cargo nextest run -p asap-executor 311 passed 311 passed none
cargo nextest run -p asap-planner --test planner (includes runtime_install, metricsql_workloads, reduce_aggregates over time_series) 51 passed, 2 failed 50 passed, 1 failed only the intended runtime_install::counter_rates_and_increases_answer_at_query_time_from_raw_samples (8 of 12 cases answer []). summary_sharing::identical_ungrouped_queries_share_their_producers fails on main too

New tests:

  • counter_rates_and_increases_answer_from_views_built_at_ingestion_time: each chain view is refreshed window by window in ingestion runs, then the query run reads the views. Passes on main, so the installed path was already correct.
  • counter_rates_and_increases_answer_at_query_time_from_raw_samples: the whole plan runs in one query run over the raw samples. Fails on main.

Hand-worked answers: over [5m] each series has 20 samples (steps 13..=32), (i + 1) * 19 apart over 285 s. The start gap is 15 s, which is under 1.1 sample intervals, so the increase extrapolates to the full 300 s: (i + 1) * 20. The rate is that divided by 300 s. So increase is j1 60, j2 140, total 200, and rate is j1 0.2, j2 0.4667, total 0.6667.

Follow-ups

The fix PR stacked on this one.

@zzylol zzylol added promql PromQL front-end lowering (L1→L2) testing Corpus, regression, differential, or benchmark tests labels Nov 15, 2026
…ery time

Hand-worked answers of rate and increase over a counter, per series, per
job and in total, on deployments that keep raw data and that do not,
answered two ways: as installed (each tumbling-window chain built window
by window in ingestion runs and read from its materialized view) and with
the whole plan run in the query run from the raw samples.

The query-run test fails today: a chain placed at ingestion time and run
in the query run builds only its newest 10 s window, so a counter's
per-series rows are dropped (fewer than two samples) and the grouped
query answers no rows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

promql PromQL front-end lowering (L1→L2) testing Corpus, regression, differential, or benchmark tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sum by (job)(rate|increase(counter[5m])) plans and installs but answers no rows

1 participant