Skip to content

mvp step 2.3: backend HTTP-forward to thanos-query for Path A2 archive - #97

Merged
zzylol merged 2 commits into
mainfrom
mvp/step2.3-backend-thanos-forward
May 7, 2026
Merged

zzylol merged 2 commits into
mainfrom
mvp/step2.3-backend-thanos-forward

Conversation

@zzylol

@zzylol zzylol commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Wires the post-Step-1 backend to HTTP-forward archive-tier PromQL queries to a thanos-query sidecar, gated by ASAP_THANOS_QUERY_URL. This is the smallest piece left to complete the Path A2 dispatch chain (Step 2.1 PR #311 emits Prometheus TSDB blocks; Step 2.2 PR #310 adds the thanos sidecar to the demo overlay).

  • ThanosForwardEngine (new file engines/gorilla/thanos_forward.rs) — implements QueryEngine, POSTs PromQL to ${ASAP_THANOS_QUERY_URL}/api/v1/query, parses the Prometheus-format response, wraps it with an exact accuracy envelope. Tolerates 5xx / timeouts as ThanosForwardError::UnreachableEngineError::Backend so the router falls through to the warm-tier sketch on a DoubleWrite deploy.
  • EngineRouter::register_aliased(id, engine) + HttpServer::with_query_engine_aliased — register a single engine instance under multiple data_source_ids. The binary uses this to register ThanosForwardEngine under both thanos_archive (native id, for explicit X-ASAP-Engine overrides) and gorilla_archive (the legacy archive slot the existing failover sequence walks).
  • Binary startup (main.rs + bin/precompute_engine.rs) — env set → register thanos forwarder, skip legacy in-process GorillaQueryEngine. Env unset → fall back to existing ASAP_GORILLA_S3_* registration verbatim. Dev environments without thanos still work.

Engine ID naming

thanos_archive for the native id (explicit overrides); aliased onto gorilla_archive so the existing compatible_storage_backends(...) failover sequence finds it without modifying asap_types or routing/backend_storage_routing.rs. Path A2 re-uses the archive tier slot — only the engine answering changes.

Test plan

  • 12 unit tests in engines/gorilla/thanos_forward.rs (forwarder success path, capabilities, alias override, 503-quirk, env-var parsing, payload parsing)
  • 2 unit tests in routing/engine_router.rs (register_aliased lookup + dispatch)
  • 3 integration tests in drivers/query/servers/http.rs (full HTTP path → mock thanos sidecar → wrapped response; unreachable upstream → 5xx with thanos_unreachable marker; X-ASAP-Engine: thanos_archive override → data_source: thanos_archive)
  • cargo test --release --lib --no-fail-fastquery_engine_rust 873 passed / 33 failed (matches pre-existing 33-failure baseline; no new regressions)

Step 2.4 (full e2e demo) hand-off notes

  • Env var: ASAP_THANOS_QUERY_URL (default http://thanos-query:10903 per Step-2.2 overlay).
  • Engine ids: thanos_archive (explicit override target), gorilla_archive (failover dispatch target — same engine instance).
  • Wire data_source annotations: failover-dispatch path → data_source: gorilla_archive (the tier); explicit override → data_source: thanos_archive (the engine implementation).
  • Fallback behaviour: env unset → legacy in-process GorillaQueryEngine registered iff ASAP_GORILLA_S3_* is also set; otherwise router serves warm-tier metrics only.

🤖 Generated with Claude Code

zzylol and others added 2 commits May 7, 2026 17:02
…er slot

Step-2.3 core abstraction. `ThanosForwardEngine` is a `QueryEngine`
that POSTs PromQL to a `thanos-query` sidecar at
`${ASAP_THANOS_QUERY_URL}/api/v1/query`, parses the
Prometheus-format response, and wraps it in ASAP's
`QueryResult` shape with an exact accuracy envelope. Tolerates 5xx
/ network errors / timeouts as `ThanosForwardError::Unreachable`,
which the trait impl folds into `EngineError::Backend` so the
router's failover sequence falls through to the warm-tier sketch
on a `DoubleWrite` deploy.

`EngineRouter::register_aliased(id, engine)` registers an engine
under an explicit `data_source_id` instead of the one its
`capabilities()` reports. Step-2.3's binary wiring uses this to
register a single `ThanosForwardEngine` instance under both
`thanos_archive` (its native id, for explicit `X-ASAP-Engine`
overrides) and `gorilla_archive` (the legacy archive slot the
existing `compatible_storage_backends` failover sequence walks).

12 unit tests cover the forwarder (success path, capabilities,
unreachable upstream → 503-quirk, env-var parsing, payload
parsing); 2 unit tests cover the new router alias path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…tests

When `ASAP_THANOS_QUERY_URL` is set, both `main.rs` (full backend)
and `bin/precompute_engine.rs` (deploy/docker image) register a
`ThanosForwardEngine` under both `thanos_archive` (its native id)
and `gorilla_archive` (the legacy archive slot the failover
sequence walks). The legacy in-process `GorillaQueryEngine` is
skipped in this mode. When the env var is unset, the binary falls
back to the existing `ASAP_GORILLA_S3_*` registration path
verbatim — dev environments without thanos still work.

`HttpServer::with_query_engine_aliased(id, engine)` is the
builder-side surface for the new `EngineRouter::register_aliased`
slot; the binary calls it twice with the same `Arc<dyn
QueryEngine>` to register under both ids.

3 HTTP integration tests pin the full wire path:
* Failover dispatch → forwards to mock thanos → 2xx with
  `data_source: gorilla_archive` (Path A2 re-uses the archive
  tier slot).
* Unreachable upstream → 5xx with `thanos_unreachable` marker in
  the error body.
* `X-ASAP-Engine: thanos_archive` override → 2xx with
  `data_source: thanos_archive` annotation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol force-pushed the mvp/step2.3-backend-thanos-forward branch from 6256315 to 2001914 Compare May 7, 2026 21:04
@zzylol
zzylol merged commit 75299d2 into main May 7, 2026
zzylol added a commit that referenced this pull request May 7, 2026
The repo is now the backend query engine of the ASAP observability
system, not a standalone Prometheus-front query accelerator. Reflects
the architecture that landed via:

- Step 1 (#95) — engines/{simple,gorilla}/ tier-co-located layout,
  routing/ split out from drivers/, JSONL legacy code deleted
- Phase α (#314 controller, #96 backend) — controller emits
  BackendStorageRouting JSON; backend hot-loads via HTTP push
- Phase β (#315) — asap-planner-rs library's 5 PromQL patterns +
  11 archive-only intents migrated into ASAPCollector controller's
  L3 intent_algebra + L4 sketch_algebra
- Step 2.3 (#97) — ThanosForwardEngine in
  engines/gorilla/thanos_forward.rs; HTTP-forwards archive queries
  to thanos-query for full PromQL surface (Path A2)

Key narrative changes:
- Lead with two-engine architecture (warm sketch tier + archive
  via Thanos), not the single-tier query-accelerator framing
- Explicit "Where the planner lives" section pointing at the
  ASAPCollector controller (was previously asap-planner-rs in
  this repo)
- Repository layout reflects the new engines/{simple,gorilla}/
  + routing/ split
- Configuration via env vars (ASAP_THANOS_QUERY_URL,
  ASAP_GORILLA_S3_*, CONTROLLER_BACKEND_ENDPOINT) matching the
  current code
- Query response infos shows the three data_source values
  (warm / gorilla_archive / thanos_archive)
- "What's NOT in this repo" section enumerates the migrations
  and deletions for reviewers landing here from old docs
- "What's still planned" tracks Phase δ (backend pure executor),
  per-tenant routing, hot-reload signal

Drops: 100x latency reduction headline (was the asap-quickstart
v0.1.0 framing — still true qualitatively but not the lede); the
4-component repo-structure diagram (most of those components
either moved or have changed scope).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zzylol added a commit that referenced this pull request May 7, 2026
The repo is now the backend query engine of the ASAP observability
system, not a standalone Prometheus-front query accelerator. Reflects
the architecture that landed via:

- Step 1 (#95) — engines/{simple,gorilla}/ tier-co-located layout,
  routing/ split out from drivers/, JSONL legacy code deleted
- Phase α (#314 controller, #96 backend) — controller emits
  BackendStorageRouting JSON; backend hot-loads via HTTP push
- Phase β (#315) — asap-planner-rs library's 5 PromQL patterns +
  11 archive-only intents migrated into ASAPCollector controller's
  L3 intent_algebra + L4 sketch_algebra
- Step 2.3 (#97) — ThanosForwardEngine in
  engines/gorilla/thanos_forward.rs; HTTP-forwards archive queries
  to thanos-query for full PromQL surface (Path A2)

Key narrative changes:
- Lead with two-engine architecture (warm sketch tier + archive
  via Thanos), not the single-tier query-accelerator framing
- Explicit "Where the planner lives" section pointing at the
  ASAPCollector controller (was previously asap-planner-rs in
  this repo)
- Repository layout reflects the new engines/{simple,gorilla}/
  + routing/ split
- Configuration via env vars (ASAP_THANOS_QUERY_URL,
  ASAP_GORILLA_S3_*, CONTROLLER_BACKEND_ENDPOINT) matching the
  current code
- Query response infos shows the three data_source values
  (warm / gorilla_archive / thanos_archive)
- "What's NOT in this repo" section enumerates the migrations
  and deletions for reviewers landing here from old docs
- "What's still planned" tracks Phase δ (backend pure executor),
  per-tenant routing, hot-reload signal

Drops: 100x latency reduction headline (was the asap-quickstart
v0.1.0 framing — still true qualitatively but not the lede); the
4-component repo-structure diagram (most of those components
either moved or have changed scope).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zzylol added a commit that referenced this pull request May 7, 2026
* mvp phase γ: delete asap-planner-rs workspace member + drop backend planner driver

Phase α (#96) made the ASAPCollector controller the sole emitter of
BackendStorageRouting; Phase β migrated all 5 PromQL pattern matchers
and 11 archive-only intents into the controller; Step 2.3 (#97) wired
the backend to forward archive queries to thanos-query. The
`asap-planner-rs/` library + CLI in this repo is now redundant.

Delete the entire `asap-planner-rs/` workspace member (49 files, ~5.1k
LOC) and surgically remove its only remaining importer in
`asap-query-engine`:

  - `src/planner_client.rs` — `LocalPlannerClient` was the in-process
    bridge that called `asap_planner::Controller::generate()` from the
    backend's query tracker.
  - `src/query_tracker/` — the passive auto-discovery loop that
    drained observed PromQL queries and called the planner client.
    Both are superseded by the controller observing queries via its
    own scrape side-channel and pushing plans / routing tables back
    via `POST /api/v1/streaming-config` and
    `POST /api/v1/storage_routing`.
  - `--enable-query-tracker` / `--tracker-observation-window-secs`
    CLI args and the `asap_planner` workspace dependency on
    `asap-query-engine` are dropped.
  - `HttpServer::new` loses its `Option<Arc<QueryTracker>>` arg; the
    `record_instant` / `record_range` hooks in instant- and
    range-query handlers are removed.
  - `asap-query-engine/Dockerfile` no longer COPYs `asap-planner-rs`
    sources or stubs them in the dependency cache layer.

Backend builds clean (`cargo build --release`); lib tests show the
same 34 pre-existing failures as origin/main with no new regressions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* mvp phase γ: refresh README + quickstart + docs after asap-planner-rs deletion

- `README.md`: drop the `asap-planner-rs/` entry from the repo-tree
  diagram; refine the "Where the planner lives" prose to say the
  legacy crate was deleted (not "CLI retained"); point external
  scripters at the controller's HTTP / CLI surface.
- `asap-quickstart/README.md`: rename the planner role to "Plan
  emitter (init container)" and note that the demo currently uses the
  published `ghcr.io/projectasap/asap-planner-rs:v0.2.0` image but
  will switch to a controller HTTP push under Phase δ. Update the
  "Edit the asap-planner-rs Config" subsection accordingly.
- `asap-quickstart/docker-compose.dev.yml`: drop the local
  `asap-planner-rs` build override (the source no longer exists in
  this repo); the base compose still pins the published image.
- `asap-quickstart/Dockerfile.queryengine-local`: drop the stale
  comment cross-referencing `asap-planner-rs/Cargo.toml`.
- `asap-summary-ingest/README.md`: redirect references to the
  controller in `ASAPCollector/`.
- `docs/`: refresh component indexes, architecture diagrams, the
  add-new-sketch guide, the bootstrap-config-from-query-log how-to,
  and the publishing-docker-images table to point at the
  ASAPCollector controller as the canonical planner location.
  Historical design docs that mention the old path are left as-is
  (they are records of past state).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zzylol added a commit that referenced this pull request May 7, 2026
Adds a `PrometheusForwardEngine` (HTTP-forwarder to Prometheus's
`/api/v1/query`) under the `prometheus_remote` engine id so the
controller's Mode 3 (`RawAtEdgePrometheusArchive`) routing entries
have a dispatchable target on the backend. Mirror of Step-2.3's
`ThanosForwardEngine` (PR #97), pointed at Prometheus's standard
HTTP API instead of a thanos-query sidecar.

Wiring is conditional on `ASAP_PROMETHEUS_QUERY_URL`: when set, the
binary registers the engine on the capability router (both `main.rs`
and `bin/precompute_engine.rs`); when unset, the engine is not
registered and a routing-table entry that references
`prometheus_remote` surfaces a clean `NoEngineRegistered` 503 from
the HTTP handler — the correct fail-loud behaviour for a
misconfigured deploy. Phase ε.1 (controller, separate repo) emits
`engine: prometheus_remote` in the `BackendStorageRouting` JSON;
this PR closes the loop by accepting that string in
`parse_engine_string` and resolving it to the new
`StorageBackend::PrometheusRemote` variant.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol deleted the mvp/step2.3-backend-thanos-forward branch May 9, 2026 18:00
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