Skip to content

refactor(query-engine): replace ParsedQueryRequest with QueryRequest - #937

Draft
milindsrivastava1997 wants to merge 1 commit into
refactor/asap-adapters-cratefrom
refactor/query-request
Draft

milindsrivastava1997 wants to merge 1 commit into
refactor/asap-adapters-cratefrom
refactor/query-request

Conversation

@milindsrivastava1997

@milindsrivastava1997 milindsrivastava1997 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Plan step 2 of .design_docs/asapplanner-engine-boundaries.md, stacked on #936 (step 1).

Change

  • New query_engine_rust::engine_api::QueryRequest { language, query, eval }, where eval is QueryEval::Instant { time_ms } or QueryEval::Range { start_ms, end_ms, step_ms }, in epoch milliseconds. It replaces ParsedQueryRequest and ParsedRangeQueryRequest. It lives in the engine crate because the future QueryEngine::execute takes it. engine_api/ is the module the plan puts the interfaces in, and step 5 adds to it.
  • Adapters (Prometheus, ClickHouse, Elastic) fill language from their config and convert protocol seconds with secs_to_ms.
  • FallbackClient now has a single execute_query(&QueryRequest) (plus _with_headers). execute_range_query* is gone. Prometheus forwards to /api/v1/query or /api/v1/query_range depending on eval. ClickHouse and Elastic return 501 for range queries, which is what the removed default returned.
  • HttpServer takes the evaluation times out of eval and passes float seconds (ms_to_secs) to SimpleEngine and the query tracker, whose APIs don't change. If an adapter returns the wrong eval kind for an endpoint, the server logs it and returns a protocol error; it never falls back silently.

Deliberate behavior change (the only one)

A range step under 0.5 ms now fails validation with step must be positive, because it rounds to 0 ms. Before, such a step was accepted and forwarded. Everything else is bit-identical for ms-aligned input (see Behavior).

Behavior

Unchanged for millisecond-aligned input:

  • secs_to_ms rounds to the nearest ms. Truncation would break the round trip: 1095211880.820 * 1000.0 = 1095211880819.9998. With rounding, ms_to_secs(secs_to_ms(t)) is the exact f64 that parsing t gave before, so SimpleEngine, the tracker and the fallback strings see the same values. This held for 2M random ms values (years 1970–2100) and is covered by unit tests.
  • Sub-ms precision is rounded to ms. Prometheus evaluates at ms precision anyway.
  • Range validation (start < end, step > 0) runs on the ms values, so a step under 0.5 ms is rejected instead of reaching the engine as about 0.

Pre-existing, not changed here: SimpleEngine::convert_query_time_to_data_time truncates t * 1000.0, so about 0.6% of ms-aligned query times map to a data time 1 ms early.

Tests

  • New: engine_api round-trip and rounding; the Prometheus adapter fills language, converts time to ms and rejects a sub-ms step; the Prometheus fallback forwards the same time/start/end/step strings as f64::to_string() did; ClickHouse and Elastic fallbacks return 501 for range queries.
  • Changed beyond imports, mechanically, because the type replaced: adapter and fallback tests that built ParsedQueryRequest literals or read .time/.start. Their assertions are the same, expressed in ms.
  • cargo fmt, cargo clippy --workspace --all-targets --all-features -D warnings and cargo test --workspace --locked pass: 1537 passed (1529 + 8 new).

Docs: adding-fallback-backend.md and adding-protocol-adapter.md now name QueryRequest.

🤖 Generated with Claude Code

One QueryRequest {language, query, eval: Instant | Range} in the engine
crate's new engine_api module replaces ParsedQueryRequest and
ParsedRangeQueryRequest. Times are epoch ms: adapters round protocol
seconds to the nearest ms, so ms-aligned inputs round-trip to the exact
f64 SimpleEngine, the tracker and the Prometheus fallback saw before.

FallbackClient takes one execute_query(&QueryRequest); ClickHouse and
Elastic return NOT_IMPLEMENTED for range evaluation, as the removed
execute_range_query default did. Range validation runs on ms, so a step
under 0.5 ms is now rejected instead of reaching the engine as ~0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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