Skip to content

feat (thanos-ASAPCollector): implement /api/v1/query_range forwarding in ThanosQueryEngine - #309

Closed
SieDeta wants to merge 1 commit into
mainfrom
add-/api/v1/query_range-forwarding
Closed

SieDeta wants to merge 1 commit into
mainfrom
add-/api/v1/query_range-forwarding

Conversation

@SieDeta

@SieDeta SieDeta commented May 21, 2026

Copy link
Copy Markdown

Summary

This PR implements /api/v1/query_range forwarding in ThanosQueryEngine so that range queries against archive-tier metrics are served by Thanos instead of returning an error.


What Was Added

  • Added range_endpoint() to ThanosQueryConfig

    • Builds:
      {base_url}/api/v1/query_range
      
  • Added query_range() to ThanosQueryEngine

    • POSTs the query to Thanos
    • Forwards:
      • query
      • start
      • end
      • step
    • Converts timestamps from milliseconds to Unix seconds
  • Added execute_range() override on ThanosQueryEngine

    • Maps:
      • 4xxCapabilityMiss
      • 5xx / timeoutBackend
  • Added execute_range() default method to the QueryEngine trait

    • Returns CapabilityMiss by default
    • Existing engine implementations remain unchanged
  • Wired process_range_query_request() in http.rs

    • Falls through to ThanosQueryEngine when:
      ASAPQueryEngine::execute_range_promql_modern()
      returns:
      CapabilityMiss
  • Added:

    • 6 unit tests
    • 3 mock helpers
    • 1 HTTP e2e test
  • Updated:

    • verify_gorilla_compression.sh
    • README.md

Why

ThanosQueryEngine previously only forwarded instant queries through:

POST /api/v1/query

Range queries still went through:

ASAPQueryEngine::execute_range_promql_modern()

When the ASAP sketch tier had no warm data for the metric, the backend returned:

unsupported query

instead of falling through to Thanos.

This blocked:

  • Grafana panels using query_range
  • Direct /api/v1/query_range requests
  • Archive-tier / Gorilla-backed metric queries

even though Thanos already had the data available via:

  • thanos-store-gateway
  • gorilla-buffer-store

The ingest path and instant-query path are unchanged.


Flow Before

GET /api/v1/query_range
    -> ASAPQueryEngine::execute_range_promql_modern
    -> CapabilityMiss (no sketch data)
    -> 404 "unsupported query"

Flow After

GET /api/v1/query_range
    -> ASAPQueryEngine::execute_range_promql_modern
    -> CapabilityMiss (no sketch data)
    -> ThanosQueryEngine::execute_range
    -> POST thanos-query:10903/api/v1/query_range
    -> 200 matrix response

Test Results

Unit Tests

cargo test --manifest-path data_plane/Cargo.toml thanos_query_engine
test query_range_calls_range_endpoint_not_instant  ... ok
test query_range_passes_params_correctly           ... ok
test query_range_parses_matrix_response            ... ok
test query_range_4xx_returns_capability_miss       ... ok
test query_range_5xx_returns_backend_error         ... ok
test query_range_timeout_returns_backend_error     ... ok
... 11 pre-existing tests                          ... ok

test result: ok. 17 passed; 0 failed

HTTP End-to-End Test

cargo test http_query_range_forwards_to_thanos
test http_query_range_forwards_to_thanos_when_asap_misses ... ok

test result: ok. 1 passed; 0 failed

@SieDeta SieDeta changed the title feat (thanos): implement /api/v1/query_range forwarding in ThanosQueryEngine feat (thanos-ASAPCollector): implement /api/v1/query_range forwarding in ThanosQueryEngine May 21, 2026
@zzylol

zzylol commented May 26, 2026

Copy link
Copy Markdown
Contributor

Superseded by #347.

The Thanos /api/v1/query_range forwarding from this PR was carried forward — the implementation (forward.rs query_range/execute_range + tests) was ported into #347, thanks for it.

The difference is structural: a routing review concluded engine selection should live in one place (EngineRouter) rather than being inlined in http.rs. So #347 adds EngineRouter::execute_range (plus the QueryEngine::execute_range trait method and ASAPQueryEngine/ThanosQueryEngine overrides) and routes both instant and range queries uniformly through the router — ASAP/sketch tier first, archive (Thanos) fallback on CapabilityMiss — keeping http.rs a thin transport layer.

Closing in favor of #347.

@zzylol zzylol closed this May 26, 2026
@zzylol
zzylol deleted the add-/api/v1/query_range-forwarding branch May 26, 2026 15:57
zzylol added a commit that referenced this pull request May 26, 2026
…r; add range support (#347)

Routing decisions now live in one place (EngineRouter + compatible_storage_backends);
http.rs is a thin transport layer. Both instant and range queries try the ASAP sketch
tier first and fall back to the archive (thanos_query) on CapabilityMiss, except
accuracy==Exact goes straight to the archive. Supersedes PR #309's inline approach.

- QueryEngine: add `execute_range` (default returns CapabilityMiss).
- EngineRouter: add `execute_range` mirroring `execute()`'s failover over the shared
  `compatible_storage_backends` sequence.
- ASAPQueryEngine: `execute_range` delegates to `execute_range_promql_modern` so the
  router reaches the real warm-tier range path.
- ThanosQueryEngine: implement `execute_range` forwarding to `/api/v1/query_range`
  (4xx -> CapabilityMiss, 5xx/timeout -> Backend), ported from #309.
- compatible_storage_backends: ASAP-first (Approximate -> [SketchStore,
  GorillaObjectStore]); Exact -> archive only; PrometheusRemote unchanged. Tests updated.
- http.rs: `process_range_query_request` thinned to a single `query_router.execute_range`
  call; inline Thanos lookup removed.

accuracy is still hardcoded `Approximate` on the live path (matches the instant path);
the `Exact -> archive` gate is wired but dormant until a request can declare accuracy.

cargo check + routing/thanos/http/capability_matching tests green.

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.

2 participants