Skip to content

chore: range step cap in the query engine, one plan test helper, QueryOutcome as Result - #888

Draft
zzylol wants to merge 1 commit into
fix/otlp-ingest-conformancefrom
chore/layout-cleanups
Draft

zzylol wants to merge 1 commit into
fix/otlp-ingest-conformancefrom
chore/layout-cleanups

Conversation

@zzylol

@zzylol zzylol commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: four leftovers from the layout stack.
    • ExecutorQueryEngine::execute (the query engine's QueryRequest entry point, which the ClickHouse and Elasticsearch routes use) had no range step cap. A QueryEval::Range from 0 to 11,001 s at a 1 s step was evaluated at 11,002 step times (11,001 steps after the start), while the Prometheus routes refuse anything over 11,000 steps.
    • The one-query plan test helper was copied in three crates.
    • QueryOutcome<T> repeated Result.
    • A test checked only the type system.
  • Change:
    • common::MAX_RANGE_STEPS (11,000) is the one constant. Both the Prometheus routes' RangeQuery::parse and execute refuse a longer range.
    • control_plane::test_support::one_query_plan (dev-dependency feature test-support) replaces the three copies.
    • QueryDispatcher returns Result<T, NotAnswerableReason>.
    • common/tests/trait_shapes.rs is deleted.
  • Effect: that range now gets the error exceeded maximum resolution of 11000 points per timeseries before any step runs. Answers and /metrics are otherwise byte-identical to fix(otlp): OTLP/HTTP replies, Prometheus resource-attribute labels, DELTA sums rejected, in-place decoder #887 (parity dump).

Review guide

Behavior: before → after

Request Before After
ExecutorQueryEngine::execute with QueryEval::Range { start_ms: 0, end_ms: 11_001_000, step_ms: 1_000 } for a planned PromQL query evaluates 11,002 step times (NotReady while data is missing) Err(QueryEngineError { message: "exceeded maximum resolution of 11000 points per timeseries" }) at once
The same at end_ms: 11_000_000 (11,000 steps after the start) evaluated evaluated (unchanged; Prometheus allows exactly 11,000)
execute with step_ms: 0, before a plan is installed Ok(NotReady) Err("range step 0 ms is not positive") (the check moved before the install lookup)
GET /api/v1/query_range over 11,000 steps 400 bad_data unchanged (same constant, now common::MAX_RANGE_STEPS)

Today no HTTP route reaches the new check. The ClickHouse and Elasticsearch routes send execute instant queries only, and the Prometheus routes call the dispatcher's range after RangeQuery::parse has already applied the cap. The check guards the engine's public QueryRequest interface, so a range sent by a future protocol route cannot run unbounded.

Interfaces

crates/common/src/lib.rs

+/// The most steps after its start one range query may have, as Prometheus allows (`(end - start) / step`).
+pub const MAX_RANGE_STEPS: i64 = 11_000;

crates/adapters/query/prometheus-http/src/lib.rs

-const MAX_RANGE_STEPS: i64 = 11_000;

crates/control-plane/src/test_support.rs, Cargo.toml

+/// Cargo feature: the test helper below; enabled only by the other crates' dev-dependencies.
+[features] test-support = []
+#[cfg(feature = "test-support")]
+pub mod test_support;
+/// The plan of `query`, evaluated every 10 s over the gauge `data` (one series, one sample a second).
+pub fn one_query_plan(query: &str, raw_data_retained: bool) -> InstallablePlan;

crates/data-plane/src/dispatcher.rs (crate-private, except dispatch)

-pub(crate) enum QueryOutcome<T> {
-    Ready(T),
-    NotAnswerable(NotAnswerableReason),
-}
 impl QueryDispatcher {
-    pub(crate) async fn instant(&self, query: &str, time_ms: i64) -> QueryOutcome<Answer>;
+    pub(crate) async fn instant(&self, query: &str, time_ms: i64) -> Result<Answer, NotAnswerableReason>;
-    pub(crate) async fn range(&self, query: &str, times_ms: impl Iterator<Item = i64>) -> QueryOutcome<Vec<(i64, Answer)>>;
+    pub(crate) async fn range(&self, query: &str, times_ms: impl Iterator<Item = i64>) -> Result<Vec<(i64, Answer)>, NotAnswerableReason>;
-    pub async fn dispatch(&self, request: &QueryRequest) -> QueryOutcome<QueryResult>;
+    pub async fn dispatch(&self, request: &QueryRequest) -> Result<QueryResult, NotAnswerableReason>;
 }

QueryOutcome had exactly Result's two cases. With Result, map_err(NotAnswerableReason::new) replaces two hand-written matches, and answer_range uses ?.

Removed: crates/common/tests/trait_shapes.rs and common's tokio dev-dependency. The test implemented FallbackClient on a fake and called it through Arc<dyn FallbackClient>. The data plane's clickhouse_fallback and elastic_fallback fields are Option<Arc<dyn FallbackClient>> holding the adapters' real implementations, so object safety and implementing the trait outside common are still checked at compile time.

Usage (crates/query/src/engine.rs::the_query_engine_installs_once_and_reports_not_ready, run at this commit):

// The plan of `sum_over_time(data[10s])`, from the shared helper, installed in the engine.
let plan = one_query_plan(QUERY, false);
assert_eq!(engine.install(installed(1)), Ok(()));
// A range of `steps` 1 s steps after 0 for the planned query.
let steps = |steps: i64| request(QueryEval::Range { start_ms: 0, end_ms: steps * 1_000, step_ms: 1_000 });
// 11,000 steps: evaluated (not ready: no data stored).
assert_eq!(engine.execute(&source(1), &steps(common::MAX_RANGE_STEPS)).await, Ok(EngineQueryResult::NotReady));
// 11,001 steps: refused before any step runs.
let refused = engine.execute(&source(1), &steps(common::MAX_RANGE_STEPS + 1)).await.unwrap_err();
assert!(refused.message.contains("exceeded maximum resolution of 11000 points"));

Algorithm changes

None.

Decisions and open questions

  • Needs reviewer decision: none.
  • Decided (2026-11-28):
    • The constant lives in common next to MAX_TIME_MS and is shared, not duplicated.
    • The helper lives in control_plane, which every caller already has as a dev-dependency and which owns plan_workload, behind a feature so production builds do not compile it. A separate test-support crate was rejected: it would only re-export control_plane.

Verification

Scope Result vs base (#887) Notes
cargo fmt --all -- --check clean
cargo clippy --workspace --all-targets --locked -- -D warnings clean
cargo test --workspace --locked (ulimit -n 65536) 248 passed, 0 failed, 3 ignored (head b192642, rebased onto #887 f895b85, which fixes the flaky ingest_shards::a_shard_running_ahead_does_not_close_windows_early; see #887 "Flaky test fixed") #887: 249 passed; same names except the_fallback_client_is_usable_as_a_trait_object (deleted) that test: 50/50 alone, 20/20 under full-suite and CPU load
Parity dump vs #887 byte-identical (69,468 bytes, at b192642 vs #887 f895b85)

Test first: the new assertions in the_query_engine_installs_once_and_reports_not_ready fail on the base, because execute returned Ok(NotReady) for the 11,001-step range (unwrap_err panicked).

Follow-ups

  • execute still answers a range whose end is before its start with an empty matrix, where RangeQuery::parse refuses it with 400. This predates this PR; left as is.

@zzylol zzylol added area: query engine PromQL lowering, execution, result shaping, and fallback behavior area: data plane Runtime ingestion, storage, and query-serving data paths feature: range evaluation Range-query steps, windows, timestamps, and temporal evaluation labels Nov 28, 2026
@zzylol
zzylol force-pushed the fix/otlp-ingest-conformance branch from c2de050 to d5c576b Compare November 28, 2026 05:56
@zzylol
zzylol force-pushed the chore/layout-cleanups branch from 0062957 to 5832a74 Compare November 28, 2026 05:56
…yOutcome as Result

- common::MAX_RANGE_STEPS (11,000, as Prometheus) is the one constant:
  the Prometheus routes' RangeQuery::parse refuses a longer range with
  400, and ExecutorQueryEngine::execute, which had no cap, now refuses it
  with an error before running any step. (The ClickHouse and
  Elasticsearch routes call execute with instant queries only today.)
- control_plane::test_support::one_query_plan (feature test-support,
  enabled by dev-dependencies only) replaces the copies in data-plane,
  query and precompute.
- QueryDispatcher returns Result<T, NotAnswerableReason>; QueryOutcome
  had the same two cases.
- common/tests/trait_shapes.rs deleted: it only checked that
  FallbackClient is object safe, which the data plane's
  Arc<dyn FallbackClient> fields already check at compile time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: data plane Runtime ingestion, storage, and query-serving data paths area: query engine PromQL lowering, execution, result shaping, and fallback behavior feature: range evaluation Range-query steps, windows, timestamps, and temporal evaluation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant