Skip to content

mvp v7: dual-routing + freshness pattern registration - #91

Merged
zzylol merged 1 commit into
mainfrom
mvp/v7-dual-routing-and-freshness-pattern
May 7, 2026
Merged

zzylol merged 1 commit into
mainfrom
mvp/v7-dual-routing-and-freshness-pattern

Conversation

@zzylol

@zzylol zzylol commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes the v6.1 architectural gap that forced issue #46 criteria ④ (warm-tier accuracy) and ⑤ (cold-fallback) to be exclusive — under v6.1 every metric had to pick one engine, so quantile-on-warm and count(...{service=\"payments\"})-on-archive could not both succeed for the same metric.

Two backend changes land together:

(A) Dual-routing per metric

  • BackendStorageRouting now holds Vec<RoutingTarget> per metric, with an optional applies_to_query_shape: [count, topk, rate_post_hoc, quantile, sum, last_over_time, other] filter on each target.
  • New QueryShape taxonomy + classify_query_shape(parsed_ast) extracts a coarse-grained shape from the parsed PromQL.
  • lookup_with_shape(metric, shape) walks targets in two passes: explicit shape-match first, then default-slot fallback.
  • Backwards-compatible YAML loader — existing single-target metrics: map entries decode to single-element target lists; new routes: list lets one metric fan out to multiple targets. A metric in BOTH wins from routes:.
  • http.rs::resolve_metric_storage now classifies the parsed AST and passes the shape to lookup_with_shape, so http_requests_total can serve quantile_over_time(...) from the warm tier AND count(...)/topk(...)/rate(...) from the cold archive.

(B) Freshness pattern registration (GorillaQueryEngine)

  • Add LastOverTime to QueryStatistic + AdditiveOp::Last on the streaming-additive accumulator. The existing AdditiveAccumulator already tracks (last_ts, last_value); the finaliser just returns last_value.
  • Planner accepts last_over_time(<metric>[<range>]) and routes it through the streaming-additive path.
  • Issue chore(tls): reqwest rustls-tls — drop libssl, make Dockerfile base-agnostic #46 ⑥ freshness probes encode unix_ts_ms_of_emission in the cumulative counter value; this gives the replay client a usable observed_value to subtract.

(B) is option (b) from the v7 spec — hard-coded support in the existing engine — chosen because it's <100 LOC and the existing AdditiveAccumulator already tracks the right state.

Tests

  • 11 new routing-table unit tests (single-target preserved, multi-target shape selection, mixed metrics: + routes:, classify_query_shape over the canonical v6 demo PromQL shapes).
  • 2 production-path HTTP integration tests (http_v7_dual_routing_count_lands_on_archive, http_v7_dual_routing_quantile_stays_on_warm_tier) mirror the existing http_routes_archive_metric_to_gorilla_engine test.
  • 2 GorillaQueryEngine tests for last_over_time (basic + unordered-samples-pick-largest-ts).
  • Pre-existing 34 backend test failures unchanged.

Test plan

  • cargo build -p query_engine_rust — passes
  • cargo test -p query_engine_rust --lib backend_storage_routing — 20/20 pass
  • cargo test -p query_engine_rust --lib http_v7_dual — 2/2 pass
  • cargo test -p query_engine_rust --lib gorilla_engine — 27/27 pass (incl. 2 new last_over_time)
  • Full backend lib tests: 873 pass / 34 pre-existing fail / 9 ignored (vs origin/main: 854 pass / 34 fail / 9 ignored — +19 new passing tests, 0 new failures)
  • v7 demo rerun on collector side (separate PR) — landing this PR first because path-dep

🤖 Generated with Claude Code

Closes the v6.1 architectural gap that forced criteria ④ vs ⑤ to be
exclusive — one metric, one engine. v7 introduces two backend
changes:

(A) Dual-routing per metric (asap-query-engine):
- BackendStorageRouting now holds Vec<RoutingTarget> per metric, with
  optional applies_to_query_shape filter on each target.
- New QueryShape taxonomy (Count/Topk/RatePostHoc/Quantile/Sum/
  LastOverTime/Other) extracted from the parsed PromQL AST in
  classify_query_shape().
- lookup_with_shape() walks targets in two passes: explicit
  shape-match first, then default-slot fallback.
- Backwards-compatible YAML loader: existing single-target
  `metrics:` map entries decode to single-element target lists; new
  `routes:` list lets one metric fan out to multiple targets.
- http.rs::resolve_metric_storage now classifies the parsed AST and
  passes the shape to lookup_with_shape, so http_requests_total can
  serve quantile_over_time from the warm tier AND
  count(...)/topk(...)/rate(...) from the cold archive.

(B) Freshness pattern (asap-query-engine GorillaQueryEngine):
- Add LastOverTime to QueryStatistic + AdditiveOp::Last on the
  streaming-additive accumulator (the existing AdditiveAccumulator
  already tracks (last_ts, last_value); finaliser just returns
  last_value).
- Planner accepts last_over_time(<metric>[<range>]) and routes it
  through the streaming-additive path. Issue #46 ⑥ freshness probes
  encode unix_ts_ms in the cumulative counter value, so this gives
  the replay client a usable observed_value to subtract.

Tests:
- 11 routing-table unit tests (single-target preserved, multi-target
  shape selection, mixed metrics+routes, classify_query_shape over
  all the canonical v6 demo PromQL shapes).
- 2 production-path HTTP integration tests
  (http_v7_dual_routing_count_lands_on_archive,
  http_v7_dual_routing_quantile_stays_on_warm_tier) mirror the
  existing http_routes_archive_metric_to_gorilla_engine test.
- 2 GorillaQueryEngine tests for last_over_time (basic +
  unordered-samples-pick-largest-ts).

Pre-existing 34 backend test failures unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <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