Repository navigation
Conversation
…s (layout step 8)
Ports ASAPQuery's ClickHouse (/clickhouse/query) and Elasticsearch
(POST /_sql, POST /_search) query adapters into
crates/adapters/query/{clickhouse-http,elastic-http}, each with a
fallback client implementing common::FallbackClient. The data plane
serves the routes when --clickhouse-url / --elastic-url is given: each
request becomes a common::QueryRequest, goes through the new
QueryDispatcher::dispatch, and what the plan does not answer is sent to
the route's fallback. Only PromQL can be planned today, so every such
query is forwarded. Existing endpoints are unchanged.
zzylol
force-pushed
the
refactor/layout-ingest-adapters
branch
from
November 28, 2026 00:56
93d4d49 to
11a1c3a
Compare
zzylol
force-pushed
the
refactor/layout-query-adapters
branch
from
November 28, 2026 00:56
2a2b6bb to
1c2d5d1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/clickhouse/query) and Elasticsearch (POST /_sql,POST /_search) clients and forwards what it cannot answer to that protocol's server. The backend serves only the Prometheus API. Step 8 ofdocs/design/repo-layout.md(docs(design): repository layout and engine boundaries #874) brings both query adapters and their fallback clients over.crates/adapters/query/clickhouse-http(clickhouse_http): reads the query (thequeryparameter of the URL or a form, else the plain SQL body), writes TabSeparated, andClickHouseHttpFallbackposts the query to/?database=<db>.crates/adapters/query/elastic-http(elastic_http): reads_sqland_searchbodies, writes_searchhits and Elasticsearch error bodies, andElasticHttpFallbackposts to/_sqlor/<index>/_search.common::FallbackClient. Both crates depend oncommononly.data-plane:--clickhouse-url/--clickhouse-databaseand--elastic-url/--elastic-indexserve the routes. Each request becomes acommon::QueryRequest, goes through the newQueryDispatcher::dispatch, and what the plan does not answer goes to the route'sFallbackClient. This is the first production caller of the trait.ClickHouseHttpFallback,ElasticHttpFallback) and #937'sQueryRequest(already incommon).Review guide
refactor/layout-ingest-adapters(feat: VictoriaMetrics Remote Write and OTLP ingest adapters (layout step 7) #882). Stacked draft.answer_or_forwardand the three handlers incrates/data-plane/src/lib.rs(the seam).QueryDispatcher::dispatchincrates/data-plane/src/dispatcher.rs(the language guard).fallback.rsfiles.lib.rs.Dependency graph
No new lockfile package besides the two crates.
Behavior: before → after
/metrics, forward-mode proxying/clickhouse/query,/_sql,/_searchwithout the new flagsGET/POST /clickhouse/querywith--clickhouse-urlqueryfrom the URL, a form or the plain body; posted to ClickHouse with the client'sAuthorization; ClickHouse's status,Content-Typeand body returned (x-asap-execution: forwarded). 400 with no query, 502 when ClickHouse cannot be reachedPOST /_sql,POST /_searchwith--elastic-url/_sql({"query", "fetch_size": 1000}, trailing;dropped) or/<index>/_search(body as sent); response returned as is. A body that does not parse: 400parsing_exception;GET: 400illegal_argument_exception; 502 when unreachable--no-forwardwith either flag is refused (clap, and the builder).Interfaces
crates/data-plane/src/dispatcher.rsimpl QueryDispatcher { pub async fn instant(&self, query: &str, time_ms: i64) -> QueryOutcome<Answer>; pub async fn range(&self, query: &str, times_ms: impl Iterator<Item = i64>) -> QueryOutcome<Vec<(i64, Answer)>>; + /// Through ExecutorQueryEngine::execute. Only a PromQL request can be the plan's; + /// any other language is Unmatched. + pub async fn dispatch(&self, request: &QueryRequest) -> QueryOutcome<QueryResult>; }crates/data-plane/src/lib.rsimpl DataPlane { + /// Serves /clickhouse/query; refused with --no-forward. + pub fn with_clickhouse_fallback(self, fallback: impl FallbackClient + 'static) -> anyhow::Result<Self>; + /// Serves POST /_sql and POST /_search; refused with --no-forward. + pub fn with_elastic_fallback(self, fallback: impl FallbackClient + 'static) -> anyhow::Result<Self>; }crates/adapters/query/clickhouse-http(new)crates/adapters/query/elastic-http(new)crates/data-plane/src/main.rsTests
clickhouse_http(6): parsing from the URL, a form and a plain body, and refusals (from ASAPQuery'stest_parse_get_request,test_parse_post_request_form,test_missing_query_parameter); TabSeparated of an instant vector (ASAPQuery'stest_format_success_responsefixture:host1\t91,host2\t77.5), of a table with escapes andnan/-inf, and of series with different labels; ranges and scalars refused. Fallback against a mock ClickHouse: the query posted to/?database=…withAuthorization, the response and a ClickHouse exception (404) returned unchanged; ranges, other languages and an unreachable server refused (ASAPQuery'stest_execute_query_*,test_range_query_not_implemented).elastic_http(6):_sqlkeeps onlyquery(ASAPQuery'stest_parse_sql_query*);_searchkeeps the body byte for byte and refuses non-objects (test_parse_json_post_request,test_parse_query_with_timestamp,test_invalid_json); error bodies (test_format_error_response); hits (test_format_success_response). Fallback against a mock Elasticsearch:/_sqlbody withfetch_size,/<index>/_searchand/_search,Authorization; ranges, other languages and an unreachable server refused.data_planedispatcher (+1): throughExecutorQueryEngine::execute, a planned PromQL request is answered with the values the Prometheus path gives, is not ready where that path is not, and the same text in ClickHouse SQL is unmatched.data_planetests/query_protocols.rs(+5, end to end through the router with a mock upstream):Authorization; a ClickHouse exception comes back as sent; no query is 400 and not forwarded./api/v1/query, while the same text on/clickhouse/queryis forwarded to ClickHouse._sqland_searchare forwarded; bad bodies andGETare 400 without forwarding.--no-forwardrefuses either server, an unreachable server is 502./_searchstill goes to Elasticsearch, other paths are still proxied to the raw store.Gate on the restacked head (1c2d5d1):
cargo fmt --all -- --checkandcargo clippy --workspace --all-targets --locked -- -D warningsclean,cargo test --workspace --locked: 236 passed, 0 failed, 3 ignored (56 suites;planner_executor_parity::push_precompute_stores_the_window_paths_view_rowsfailed once under load and passed alone) (#882: 218 passed, 0 failed, 3 ignored (51 suites); +18 new).Parity
The uncommitted dump test from #880–#882, with
/clickhouse/query,/_sql,/_searchand/clickhouse/pingadded (not configured). Fixture: the plan ofsum by (job) (sum_over_time(data[10s])), 3 series written through 60 s; planned instant and range queries, cached steps, not-ready and unplanned queries, malformed and empty Remote Write bodies,/api/v1/status/asap, with and without--no-forward, headers exceptdate, and the/metricsnames and label sets. The dump is byte-identical to #882's head (32,469 bytes both; stable over 4 runs).Benchmarks
Release builds, same host, cores 0–15, #882's head and this branch alternating. No code on these paths changed; the differences are within run-to-run spread.
view_read_bench 10000 40 15, cold mmap (ms per window, 8 runs)offset_bench 1000 5, through the router and dispatcher (ms, 3 queries × 3 runs)tier_bench 2000 70,RESULT_CACHE=0, through the router (ms, rounds 2–5 × 3 runs):quantile_over_time(0.99, lat[1h])max_over_time(lat[30m])topk(10, sum by (job) (rate(reqs[1h])))sum by (job) (increase(reqs[1h]))range_bench 1000 views 15fails the same way on both trees (a 422 forquantile_over_time(0.99, lat[1h]): a view window not tiling the range), so it is not compared here.Deviations from ASAPQuery
Content-Typeand body are returned as sent. ASAPQuery turned a ClickHouse exception into an empty 400, sent Elasticsearch errors with HTTP 200, and answered network errors with 500; here they are the server's own status, or 502.Parse error:/Protocol error:prefixes.Authorizationis forwarded on GET and POST, to both servers. ASAPQuery forwarded it on POST only and never to ClickHouse.X-ClickHouse-User/X-ClickHouse-Keyanduser/passwordURL parameters are not forwarded.--forward-timeout-seconds(default 120 s) instead of a fixed 30 s._searchtakes only a JSON object and forwards it byte for byte (ASAPQuery accepted any JSON value and re-serialized it).Content-Typeis not checked.\, tab, newline, carriage return and NUL; floats use Rust's shortest round-trip digits (no exponent form). Vector columns are every label name, sorted./clickhouse/ping,/_cluster/health; docs(query-engine): design engine boundaries for ASAPPlanner plans ASAPQuery#935's T4) and the always-failing range routes (/clickhouse/query_range,/_search_range).Why the fallback clients repeat code
ClickHouseHttpFallback,ElasticHttpFallbackandPrometheusHttpFallbackeach convert headers, turn the response into aFallbackResponse(with theapplication/octet-streamdefault) and build a reqwest client, andUnsupportedResultis defined in both new adapters. This is deliberate: adapters may depend only oncommon, on nothing, or on the adapter whose wire format they extend, never on each other, andcommonholds no HTTP crate. Sharing the code would need an adapter-to-adapter dependency or HTTP types incommon; please do not "fix" it that way.Deferred
Tablescans (and refuses Elasticsearch SQL; it has no Query DSL frontend), whilestorageholds time series only. A planned ClickHouse query needs table sources end to end (ingest, a raw table store, a SQL catalog for the control plane). Until thendispatchreturnsUnmatchedfor any language but PromQL, and the encoders and the plan branch ofanswer_or_forwardare reached only in unit tests. They are kept so the routes answer a planned query without change once one exists.Content-Type(X-Elastic-Product,X-ClickHouse-*) are not passed through;FallbackResponsecarries only the content type. Some Elasticsearch clients checkX-Elastic-Product._sqlcursors,params,?format=, and ClickHouse settings parameters (default_format, …) are not forwarded.