Skip to content

feat(data_plane): forward mode: raw samples to a VictoriaMetrics raw store, unplanned queries proxied - #856

Closed
zzylol wants to merge 3 commits into
feat/tiered-view-storagefrom
feat/demo-forward-mode
Closed

zzylol wants to merge 3 commits into
feat/tiered-view-storagefrom
feat/demo-forward-mode

Conversation

@zzylol

@zzylol zzylol commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: the demo's data plane answers only the queries ASAPPlanner planned. Any other query (Grafana's label pickers, ad-hoc PromQL) needs a separate Prometheus, which today receives no samples.
  • Change: an optional forward mode (--raw-store-url, off by default). Each accepted Remote Write request is also delivered, unchanged, to a VictoriaMetrics single-node used as the raw store. Unplanned queries and every other API path are proxied to it, with x-asap-execution saying who answered.
  • Effect: in a run against a real VictoriaMetrics v1.155.0 (1,000 series × 2 metrics at 10 Hz for 150 s):
    • the data plane accepted 3,000,000 samples and delivered all 3,000 requests to VictoriaMetrics, with 0 retries and 0 refusals;
    • count_over_time(data[10m]), answered by VictoriaMetrics (forwarded), returned 1,000 series × 1,500 samples;
    • the planned sum by (job) (rate(data_total[5m])) was answered by ASAP (plan).

Review guide

Behavior: before → after

The data plane started with data_plane --plan plan.json --listen :8088 --raw-store-url http://127.0.0.1:8428 (VictoriaMetrics on :8428):

Request Before (no forward mode) After (forward mode)
POST /api/v1/write (accepted) 204; the samples are in ASAP only 204; ASAP has the samples, and VictoriaMetrics' copy is queued and delivered
POST /api/v1/write while the forward queue is full – 503, and the engine never sees the request (a retry duplicates nothing)
planned GET /api/v1/query?query=sum by (job) (rate(data_total[5m])) ASAP, x-asap-execution: plan unchanged
GET /api/v1/query?query=count_over_time(data[10m]) (unplanned) forwarded to --prometheus-url answered by VictoriaMetrics, x-asap-execution: forwarded
GET /api/v1/labels, /api/v1/series, /api/v1/label/job/values 404 answered by VictoriaMetrics, x-asap-execution: forwarded

It serves the demo plan's §10 step 1: every query is answered, with the planned ones by ASAP. Resources are reported as ASAP + VictoriaMetrics, because both run in the forward-mode arm's cgroup.

Interfaces

data_plane/src/raw_forward.rs (new module)

+/// How raw samples are forwarded (built by `--raw-store-url` and the two flags below).
+pub struct RawForwardOptions {
+    /// Base URL of the raw store; bodies go to `{url}/api/v1/write`.
+    pub url: String,
+    /// Bytes queued or in flight beyond which writes get 503 (default 256 MiB).
+    pub max_queued_bytes: u64,
+    /// Requests delivered at once (default 4).
+    pub concurrency: usize,
+    /// Bound on one delivery attempt (default 30 s).
+    pub timeout: Duration,
+}
+impl RawForwardOptions {
+    /// The defaults above for `url`.
+    pub fn new(url: impl Into<String>) -> Self;
+}
+/// Delivers accepted Remote Write bodies to the raw store on its own thread.
+pub struct RawForwarder { /* ... */ }
+impl RawForwarder {
+    /// Starts the delivery workers.
+    pub fn start(options: RawForwardOptions) -> std::io::Result<Self>;
+    /// Room for one body, or `None` (counted as a refusal) when the queue is full.
+    pub fn reserve(&self, bytes: u64) -> Option<Reservation<'_>>;
+    /// The raw store's base URL.
+    pub fn url(&self) -> &str;
+    /// The counters as JSON (`raw_forward` in `/api/v1/status/asap`).
+    pub fn status(&self) -> serde_json::Value;
+    /// The `asap_raw_forward_*` metrics.
+    pub fn render(&self, out: &mut String);
+}
+/// Reserved queue room; released on drop unless committed.
+pub struct Reservation<'a> { /* ... */ }
+impl Reservation<'_> {
+    /// Queues the body for delivery.
+    pub fn commit(self, body: Bytes);
+}

data_plane/src/lib.rs

 pub struct DataPlane {
     pub queries: Vec<String>,
     pub engine: EngineHandle,
     pub prometheus_url: String,
     pub limits: remote_write::Limits,
     pub samples: AtomicU64,
     pub no_forward: bool,
     client: reqwest::Client,
+    /// Forward mode: delivers accepted Remote Write bodies to the raw store,
+    /// which also answers what the plan does not. `None`: off.
+    pub raw_forward: Option<raw_forward::RawForwarder>,
 }
 impl DataPlane {
+    /// Turns forward mode on: queries the plan does not answer, and any other path,
+    /// go to `options.url` in place of `prometheus_url`. Errors with `--no-forward`.
+    pub fn with_raw_forward(self, options: raw_forward::RawForwardOptions) -> anyhow::Result<Self>;
 }

data_plane/src/main.rs (CLI)

+    /// Forward mode (off by default): the raw store's base URL. Conflicts with --no-forward.
+    --raw-store-url <URL>
+    /// Bytes queued or in flight to the raw store beyond which writes get 503.
+    --raw-forward-queue-bytes <BYTES>        [default: 268435456]
+    /// Remote Write requests delivered to the raw store at once.
+    --raw-forward-concurrency <N>            [default: 4]

New metrics:

  • asap_raw_forward_queued_bytes and asap_raw_forward_queued_requests;
  • asap_raw_forward_requests_total{outcome="delivered|dropped"};
  • asap_raw_forward_retries_total;
  • asap_raw_forward_delivered_bytes_total;
  • asap_raw_forward_refused_writes_total.

Usage (the smoke run above, end to end):

# The raw store: a VictoriaMetrics single-node.
victoria-metrics -storageDataPath=vmdata -httpListenAddr=127.0.0.1:8428
# The data plane in forward mode: the plan's queries are answered from views; VictoriaMetrics gets every sample and every other query.
data_plane --plan plan.json --listen 10.10.1.2:8088 --raw-store-url http://127.0.0.1:8428 --stream-start-ms $START --allowed-lateness-ms 2000
# 1,000 series of data and data_total at 10 Hz for 150 s (examples/remote_write_load.rs from #854).
remote_write_load 10.10.1.2:8088 data,data_total 0 1000 10 150 $START 2   # -> {"acked": 3000000, "retries_503": 0, ...}
curl -s 10.10.1.2:8088/api/v1/status/asap   # raw_forward: delivered_requests 3000, queued_bytes 0, refused_writes 0
curl -sD- '10.10.1.2:8088/api/v1/query?query=count_over_time(data[10m])'   # x-asap-execution: forwarded; 1000 series x 1500
curl -sD- '10.10.1.2:8088/api/v1/labels'                                   # x-asap-execution: forwarded
curl -sD- '10.10.1.2:8088/api/v1/query?query=sum by (job) (rate(data_total[5m]))&time=...'   # x-asap-execution: plan

Algorithm changes

None: request routing and a delivery queue only.

Decisions and open questions

Needs reviewer decision: None.

Decided:

  • No disk spool (2026-11-22, user decision). The forward queue stays in memory.
    • Known limit: if the data plane crashes, up to --raw-forward-queue-bytes (default 256 MiB) of samples it has already acknowledged with 204 are lost on the raw-store side.
    • Scope: those samples are still in ASAP (subject to ASAP's own persistence). Only VictoriaMetrics' copy, used for unplanned queries, is missing them.
    • Mitigation: a smaller --raw-forward-queue-bytes bounds the loss, at the cost of more 503s when VictoriaMetrics slows down.
  • Admission order (2026-11-22). A write reserves room in the forward queue before the engine admits it. Rejected alternatives:
    • forwarding after acknowledging, because VictoriaMetrics would miss samples whenever it is down;
    • acknowledging only after VictoriaMetrics acknowledges, because that puts VictoriaMetrics' latency on the write path.
  • Who answers what (2026-11-22). In forward mode, unplanned queries go to --raw-store-url in place of --prometheus-url. The proxy for every other path is added only when forward mode is on.

Verification

Scope Passed / failed / ignored New failures vs base Notes
cargo test -p data_plane --test forward_mode 8 / 0 / 0 – new, F1–F8
cargo test -p data_plane (every suite) all pass / 0 / 0 none parity and precompute-pool suites included
cargo fmt --all --check pass –
cargo clippy -p data_plane --all-targets no warning in the changed files – the existing warnings in prometheus.rs, series_ids.rs and tier_bench.rs are unchanged

New tests (data_plane/tests/forward_mode.rs; the raw store is a recording mock):

  • F1: with forward mode off, other paths answer 404 and no forward metric exists.
  • F2: bodies arrive byte for byte, snappy-encoded, and ASAP's answers equal those with forwarding off.
  • F3: planned queries are marked plan. Unplanned query and query_range, labels, series and label values are proxied with their query string and marked forwarded.
  • F4: a body answered 503 or 429 twice is retried and delivered once.
  • F5: bodies wait while the raw store is down and are delivered once it is up.
  • F6: with the queue full, a write gets 503 and the engine never sees it. The retried write is accepted, and each store has every sample exactly once.
  • F7: a body answered 400 is dropped and counted, and later bodies are still delivered.
  • F8: forward mode with --no-forward is refused.

End to end: the run against VictoriaMetrics v1.155.0 in Summary and Usage.

Follow-ups

  • Harness arm. An asap_forward arm in the benchmark harness, outside this repository, runs the data plane and VictoriaMetrics in one cgroup and reports both per component and summed. It is not yet run at demo scale.
  • Durability. No disk spool, by decision. A crash loses up to --raw-forward-queue-bytes of acknowledged samples on the raw-store side (see Decided).

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6bo6sg4cEjJJhktNtL9

@zzylol zzylol added area: data plane Runtime ingestion, storage, and query-serving data paths enhancement New feature or request labels Nov 22, 2026
@zzylol
zzylol force-pushed the feat/demo-forward-mode branch 2 times, most recently from 3ca52ef to 1153fc6 Compare November 23, 2026 22:37
…store, unplanned queries proxied

--raw-store-url URL turns it on (off by default, and refused with
--no-forward). With forward mode off, nothing changes.

- Writes. An accepted Remote Write request is acknowledged (204) only
  once the engine has admitted its samples and its body is queued for
  the raw store.
  - The queue is bounded in bytes (--raw-forward-queue-bytes, default
    256 MiB, in-flight bodies included). When it is full, the request
    gets 503 before the engine sees it, so a retry duplicates nothing in
    either store.
  - Workers on their own thread (--raw-forward-concurrency, default 4)
    deliver bodies unchanged to URL/api/v1/write. They retry 429, 5xx,
    timeouts and connection errors with a 100 ms to 5 s backoff, and drop
    and count any other 4xx.
- Queries. Queries the plan does not answer, and every other path
  (labels, series, label values, metadata), are proxied to the raw store
  with x-asap-execution: forwarded. Planned answers keep
  x-asap-execution: plan.
- Metrics. asap_raw_forward_* on /metrics, and raw_forward in
  /api/v1/status/asap.

Design and test plan: docs/design/demo-plan.md §10.1. Tests F1-F8 are in
tests/forward_mode.rs.
@zzylol

zzylol commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Replaced by #870: the same commits rebased onto main (#864 was squash-merged). The branch feat/demo-forward-mode is kept unchanged.

@zzylol zzylol closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: data plane Runtime ingestion, storage, and query-serving data paths enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant