Repository navigation
Conversation
Step 6 of docs/design/repo-layout.md. - crates/adapters/ingest/prometheus-remote-write (prometheus_remote_write): the Remote Write v1 decoder, with no workspace dependency. Decoder<S> is generic over the caller's series handle and sample type, so the data plane still decodes straight into storage's RawSample (no copy); its buffer and series cache move from two thread-locals into the decoder, which data-plane keeps in one thread-local (remote_write.rs). - crates/adapters/query/prometheus-http (prometheus_http): query parameters and response bodies, depending on common only, and the fallback client PrometheusHttpFallback: forward() proxies a request as received (the routes use it, as before), and it implements common::FallbackClient for a parsed QueryRequest. - ResultSample moves from query to common: the response writers need it. - The forward-mode ingest tee stays in data-plane.
decode_bench was 2% to 10% slower per sample after the move. The cause: Reader::varint_slow, an out-of-line method taking &mut Reader, is now a call into another crate, so the reader escaped and its position was reloaded from the stack on every field of the first-pass loop. It is a free function of (bytes, position) now, and sample_fast and sample_generic are #[inline], as the same-crate build inlined them. The decoder takes a SampleSink (series and sample types) in place of two closures: one type parameter, no closure arguments threaded through.
- PrometheusHttpFallback::forward returns the server's response as received (StatusCode, Option<HeaderValue>, Bytes): no body copy and a Content-Type passed through byte for byte, as before the move; only FallbackClient::execute converts to FallbackResponse. - with_timeout replaces the base_url getter. - common::Answer (Arc<Vec<ResultSample>>) replaces query's alias and the adapter's copy; common re-exports SqlDialect (prometheus_http drops its asap-types dev-dependency). - SampleSink is SampleBuilder; Decoder::new only; adapter docs name no data-plane type. - data_plane drops serde and thiserror, which only the moved code used.
…rnal Each series' labels are one Arc shared by every step's answer; the adapter need not know where storage builds them.
zzylol
force-pushed
the
refactor/layout-engines-traits
branch
from
November 28, 2026 00:56
4f5b4f8 to
7683fc9
Compare
zzylol
force-pushed
the
refactor/layout-adapters
branch
from
November 28, 2026 00:56
a64b54c to
5d5b323
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
data-plane. The Remote Write decoder (remote_write.rs) and the Prometheus HTTP API (prometheus.rs) can reach any engine or store type, and the forward-mode proxy is a set of private helpers inlib.rs. Steps 7–8 need adapter crates that depend oncommononly, as the design says.docs/design/repo-layout.md(docs(design): repository layout and engine boundaries #874).crates/adapters/ingest/prometheus-remote-write(prometheus_remote_write): the decoder. It depends on no workspace crate. It is generic over aSampleBuilder(the caller's series handle and sample type), so the data plane still decodes straight into storage'sRawSample, with no copy.crates/adapters/query/prometheus-http(prometheus_http): query parameters, response bodies, andfallback::PrometheusHttpFallback, the forward proxy. The routes call itsforward(the request as received). It also implementscommon::FallbackClientfor a parsedQueryRequest. It depends oncommononly.ResultSampleandAnswer(Arc<Vec<ResultSample>>) move fromquerytocommon, because the response writers need them.raw_forward.rs) stays indata-plane./metricsnames are byte-identical with feat: engines as concrete types; PlanInstaller and QueryDispatcher (layout step 5b) #880's head, with and without--no-forward. Remote Write decoding is 11–12% faster per sample (see Benchmarks); a first cut was 2–10% slower, and the cause is fixed here.Review guide
refactor/layout-engines-traits(feat: engines as concrete types; PlanInstaller and QueryDispatcher (layout step 5b) #880). Stacked draft.SampleBuilderin place of two closures.forwardreturns the response as received;common::Answer; names; unused dependencies.crates/data-plane/src/remote_write.rs(the seam, 40 lines), thenDecoderandSampleBuilderat the top ofcrates/adapters/ingest/prometheus-remote-write/src/lib.rs, thencrates/adapters/query/prometheus-http/src/fallback.rs, thenforward_pathincrates/data-plane/src/lib.rs.prometheus-http/src/lib.rsisdata-plane/src/prometheus.rswith imports and visibility changed (git diff -M <#880 head>..HEAD). The decoder's walk (decode_series,push_samples,Reader,SeriesCache) is the old code with the series type as a parameter. Tests and benchmarks change imports only.Old → new
data_plane::remote_write::{WriteRequest, TimeSeries, Label, Sample, Limits, RemoteWriteError, encode}prometheus_remote_write::…(same items)data_plane::remote_write::decode_samples(two thread-locals: buffer, series cache)data_plane::remote_write::decode_samples: one thread-localDecoder<Interned>,Interned: SampleBuilderinterning intostorage::series_idsdata_plane::prometheus::{InstantQuery, RangeQuery, BadParameter, VectorResponse, range_response_body, bad_data}prometheus_http::…;InstantQuery::parse,RangeQuery::parseandBadParameterarepub(werepub(crate))lib.rsNOT_FORWARDED,forwarded_headers,forward_client, the send/read half offorward_pathprometheus_http::fallback::PrometheusHttpFallback::{new, with_base_url, with_timeout, forward}DataPlane::{prometheus_url, client}DataPlane::fallback(private)impl common::FallbackClient for PrometheusHttpFallbackquery::ResultSample,query::result_cache::Answercommon::ResultSample,common::Answerasap_types::workload::SqlDialectcommon::SqlDialectDependency graph
data_planedropsahash,hashbrown,ryu,prost,serdeandthiserror(only the moved code used them);snapandahashbecome dev-dependencies (a reference-decoder test and a benchmark).Behavior: before → after
No change. The routes still forward the client's own request (method, path, URL query, body, end-to-end headers), and copy back the server's status, body and
Content-Typebyte for byte. With the plan ofsum by (job) (sum_over_time(data[10s])), 3 series written through 60 s and the barrier at 60 s, every response below is byte-identical with #880's head (headers exceptdate, then the body), and so are the/metricsnames and label sets:--no-forwardtime=60, and attime=50.000with surrounding spacesx-asap-execution: planplantime=90(window not stored), range 50–90 srefused, the reasonforwarding to Prometheus: …,x-asap-forward-reasonup(not planned)the installed plan has no query "up"Interfaces
crates/adapters/ingest/prometheus-remote-write/src/lib.rs(new crate; the message types,Limits,RemoteWriteErrorandencodemoved unchanged)crates/data-plane/src/remote_write.rs(now only the seam)pub fn decode_samples(body: &[u8], limits: &Limits) -> Result<Vec<RawSample>, RemoteWriteError>; +struct Interned; // SampleBuilder: Series = &'static storage::series_ids::Series, Sample = RawSamplecrates/adapters/query/prometheus-http/src/fallback.rs(new)crates/common/src/query_result.rscrates/data-plane/src/lib.rsExceptions and decisions
RawDataBatch, not incommon) holds aBTreeMap<String, String>per series per request; building it, then interning it, would copy every label on the ingest hot path. TheSampleBuilderparameter keeps the zero-copy decode and still keeps the adapter free of every workspace crate (it does not even needcommon). docs(design): repository layout and engine boundaries #874 says so.FallbackClient. The trait'sQueryRequestcannot carry the client's own method, extra parameters (timeout,limit,stats, …), raw times or body, and the catch-all proxy has no query at all. Sending a rebuilt request would change what Prometheus receives. SoPrometheusHttpFallback::forwardproxies the request as received, andFallbackClient::executeis the trait seam for callers that only have aQueryRequest(steps 7–8). Today only its tests call it.QueryOutcomeandNotAnswerableReasonstay indata-plane(deferred from feat: engines as concrete types; PlanInstaller and QueryDispatcher (layout step 5b) #880). No adapter needs them: the HTTP handlers that read them stay indata-plane.ResultSampleandAnswermove tocommon.prometheus_httpwrites them and may not depend onquery; they are the native answer the design's dispatcher returns on the hot path.Testing
ulimit -nraised), same toolchain flags as feat: engines as concrete types; PlanInstaller and QueryDispatcher (layout step 5b) #880's gate:cargo fmt --all -- --checkcargo build --workspace --all-targets --lockedcargo clippy --workspace --all-targets --locked -- -D warningscargo test --workspace --lockedplanner_executor_parity::push_precompute_stores_the_window_paths_view_rowsfailed once under load and passed alone)The sorted lists of passing test names differ from #880's head only by the 3 new tests below and by the 14 moved unit tests, which keep their names under their new crates' roots:
prometheus::tests::*(7) andremote_write::tests::*(7) are nowtests::*inprometheus_httpandprometheus_remote_write. In an earlier gate run under load (another build on the same host),planner_executor_parity::push_precompute_stores_the_window_paths_view_rowsfailed once with a window-expiry difference; it passed when run alone on #880's head, and it passed in this PR's final gate. It depends on timing; this change does not touch it.prometheus_http::fallback:sends_a_parsed_query_as_a_prometheus_request(instant and range requests, seconds to the millisecond including negative times, headers passed, response passed back),refuses_sql_and_reports_an_unreachable_server,forwards_end_to_end_headers_only. The decoder's unit tests now run against a testSampleBuilder, anddecoded_samples_match_the_full_decodealso checks that a repeated series is interned once.zz_parity_dump, imports updated) gives byte-identical output on both trees: planned, cached, not-ready and unplanned queries, with and without--no-forward, plus the/metricsnames and label sets.Benchmarks
Same quiet host, both trees built the same way, runs interleaved.
ingest_bench 10000 120 views 1 persist(3 runs; median [min–max]): every write acknowledgeddecode_bench(2,000 rounds, 5 digits, 1 core, interleaved): one series per sampleThe first cut was 2–10% slower in
decode_bench, with the same instruction count but lower IPC. The cause:Reader::varint_slow, an out-of-line method taking&mut Reader, became a call into another crate, so the reader escaped and its position was reloaded from the stack on every field of the first-pass loop. It is now a free function of(bytes, position), andsample_fast/sample_genericare#[inline](the same-crate build inlined them;decode_bench's first sample of each series has value and timestamp 0, both omitted by protobuf, so it takessample_generic).Whole-stack review fixes
range_response_body's doc comment no longer names a storage internal (series_ids::result_labels): "each series' labels are oneArcshared by every step's answer".impl FallbackClient for PrometheusHttpFallbackstays (the design requires it; steps 7–8 reach fallbacks through the trait), though today only its tests call it.Deferred to steps 7–8 and #874
ResultSample/Answerincommon, exception 1 and the routes' verbatimforward.FallbackClient; VictoriaMetrics Remote Write can reuseDecoderwith its ownSampleBuilder.Reader::varint(series of 128 bytes or more takevarint_slowfor their length, as before).