Skip to content

Collector views of exact accumulators: control-plane placement and data-plane ingest (sum/count/avg/min/max_over_time) - #895

Draft
zzylol wants to merge 2 commits into
feat/collector-lineage-reorder-framefrom
feat/collector-exact-accumulators
Draft

zzylol wants to merge 2 commits into
feat/collector-lineage-reorder-framefrom
feat/collector-exact-accumulators

Conversation

@zzylol

@zzylol zzylol commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: sum_over_time, count_over_time, avg_over_time, min_over_time and max_over_time on a gauge never used the collector. The control plane's collector rule accepted sketch chains only. And even with a collector view placed, the data plane refused to start, because CollectorViews::new wanted an ASAPv1 decoder and exact states have none.
  • Change:
    • Control plane: rule (a) now accepts an exact accumulator build that reads the sample value, unless one of the exclusions executor expands into (the planner's own DeploymentCapabilities::exclusions) matches it. capabilities_version goes to 2.
    • Data plane: a Sum/Count/Min/Max collector view decodes its state, behind the collector's lineage frame, as the executor's view-layout record (StateColumn::from_views), the bytes this data plane already stores exact states as. Lineages (Collector view states: sequence numbers and deltas, incomplete windows, idle close from the declared delay #893) deduplicate and order the records exactly as they do for sketches.
  • Effect: for the plan of all five queries, every chain is a collector view and backend_reads_raw is {"data": false}. In an end-to-end run, with 10,000 series fed through collector feat(sketch-core,ingest): delta decode for CountSketch + CountMin #63, answers were identical to a raw-ingest data plane for all 5 queries at 32 evaluation times, and the collector-arm data plane received 0 raw samples (raw arm: 2,400,000).

Review guide

Behavior: before → after

control_plane --workload <query every 5 s on a gauge> --deployment-capabilities {raw_data_retained: false} --collector-capabilities <asap-collector --print-capabilities> --emit-collector-views cv.json:

query before after
sum_over_time(data[1m]) views [], data: true views [1] (exact Sum chain), data: false
count_over_time / min_over_time / max_over_time [], true [1], false
avg_over_time [], true [1, 5] (Sum, Count), false
the five together [], true [1, 6, 12, 16], false
quantile_over_time(0.99, …) + sum_over_time [1], true [1, 6], false

data_plane --plan plan.json --collector-views cv.json on an exact view: before, it exits at start-up with collector view 1: its state has no ASAPv1 encoding; after, it ingests the states and commits their windows.

Interfaces

control-plane/src/collector_views.rs

-/// The `capabilities_version` this control plane reads.
-const CAPABILITIES_VERSION: u32 = 1;
+/// The `capabilities_version` this control plane reads. Version 2 reads
+/// `executor` with the planner's semantics in full, exact accumulators
+/// included; version 1 meant sketches only, with the same JSON.
+const CAPABILITIES_VERSION: u32 = 2;

precompute/src/collector.rs (crate-private)

+/// How a collector view's state bytes are read into its kernel.
+enum StateDecoder {
+    /// A sketch: `asap_sketchlib`'s ASAPv1 bytes.
+    Asapv1(Asapv1Decoder),
+    /// An exact accumulator (`Sum`, `Count`, `Min`, `Max`): its one record in
+    /// the executor's view layout (`StateColumn::view_bytes`).
+    ViewLayout(FieldDataType),
+}
 struct CollectorView {
     group: usize,
     key: ViewStateKey,
     source_metric: String,
     width_ms: i64,
-    decoder: Asapv1Decoder,
+    decoder: StateDecoder,
     schema: SchemaRef,
     window_end_column: Option<usize>,
     identity_column: usize,
     state_column: usize,
 }

Wire format. On a view whose key has no θ, sketch.envelope holds the lineage frame followed by one record as little-endian 8-byte words:

  • Sum: sum, compensation, seen (24 B)
  • Count: count (8 B)
  • Min/Max: present, value (16 B)

A record of another size, or a presence word that is not 0 or 1, is rejected as decode. A Counter/IRate collector view is refused at start-up, because its state depends on sample order.

Usage. Control plane as in the table. The collector (#63) sends each series' state per 5 s window to /v1/metrics: a full first, then a delta for each emission of an open window and for each correction. CollectorViews::check unframes the lineage and decodes the record into an ExactAccumulator. Staging::stage applies it to its (epoch, series, window) lineage, merging with merge_with (add / add / min / max); a record already applied is a duplicate, and one that arrives early waits in the reorder buffer. The window commits when its request ends, and later records merge into it through the late path. A query reads the view's rows, exactly as it would rows the data plane built itself.

Algorithm

None. The control plane gets one more check in rule (a). The data plane decodes one more kind of bytes; lineages, the reorder buffer, merging and committing are unchanged, because they hold the decoded kernel state.

Decisions and open questions

Needs reviewer decision

  • Version 1 is now refused. The alternative is to keep reading version 1 as "no exact families". Every collector that prints capabilities is still a draft.
  • Exact input is assumed. The capabilities cannot say which input an exact accumulator reads, so the rule assumes the sample value. Stating it would need a planner vocabulary change or a collector-only field.

Decided

  • Exact views run only with lineage (2026-11-30). Before the restack, a state was told from a repeat by a hash of its bytes, and distinct exact partials often have equal bytes (two one-sample corrections are both Count 1). A pre-restack version of the partials test failed on exactly this: late_merged was 0 where 1 was expected. On Collector view states: sequence numbers and deltas, incomplete windows, idle close from the declared delay #893's lineages, a record is a duplicate only when its (epoch, sequence) was already applied. equal_bytes_corrections_with_distinct_sequences_both_merge checks this case.

Verification

scope result notes
cargo test -p control_plane --test collector_views 10 / 10 passed the 3 new tests failed before the rule change
cargo test -p precompute --lib -- collector::tests 7 / 7 passed the exact test failed before: its state has no ASAPv1 encoding
cargo test -p data_plane --test collector_exact_views (new) 4 / 4 passed the original 3 failed before, with the same error
cargo test -p data_plane --test collector_views (sketch views, #893/#897) 20 / 20 passed no regression
cargo clippy -p control_plane -p precompute -p data_plane --tests, cargo fmt clean

New tests:

  • a_leaf_exact_chain_is_the_collector_view, exact_and_sketch_views_of_one_metric_all_go_to_the_collector, an_excluded_exact_family_stays_in_the_backend (control plane).
  • an_exact_collector_view_decodes_its_view_layout_records: a Sum record decodes, two merge to 10.0, and the window's row holds that same record. A 16-byte or 3-byte record is no state.
  • exact_collector_states_answer_as_the_views_built_here: all four views' framed states answer all five queries exactly as a data plane building from the same samples. data's raw samples are not stored.
  • exact_partials_and_corrections_merge_and_repeats_are_duplicates: per view, the fulls of two collector instances merge and a repeat is a duplicate. A correction (a delta, sequence 1) after the commit is late_merged and its repeat is a duplicate. The answers then equal the on-time build.
  • equal_bytes_corrections_with_distinct_sequences_both_merge: two corrections with identical bytes (Count 1, Sum 42.5, …), sent as sequences 1 and 2, both merge (late_merged 2, duplicate 0), and count_over_time and sum_over_time include both late samples.
  • bytes_that_are_not_the_views_record_are_rejected.

End to end (local, release builds of #63 at 3acfc6a and this PR at 3ff92a0). Two arms were fed the same samples by the seeded paced feeder: 10,000 series at 1 sample/s for 240 s.

  • Arm A: collector (collector_views + raw_forward) → data plane with --collector-views.
  • Arm B: passthrough collector → data plane building every view from raw samples.
  • Plan: the five queries over data[1m]; the control plane cut it into collector views [1, 6, 12, 16] with data: false.
  • Queries: both arms were queried live every 5 s, at the newest evaluation time whose windows had closed (32 times from 67 s to 222 s after the feed started).
arm A (collector views) arm B (raw ingest)
answers, 5 queries × 32 times × 10,000 series identical to B (160 / 160 equal, 0 differ, 0 errors) reference
raw samples received (asap_samples_total{accepted}) 0 2,400,000
asap_raw_data_bytes 0 0 (the plan keeps no raw data)
collector states staged per view / windows committed 480,000 / 48 n/a
windows refreshed 4 groups × 48 1 group × 48
raw_forward messages dropped (data read only by views) all 240 n/a
asap_view_bytes at the end 51,536,736 39,053,760

View memory, A vs B. The gap is identical in two runs (+12.48 MB, +32 %), and both arms hold the same windows. It is not a correctness issue. I measured it by charging one window per exact view both ways (ViewStore::bytes, 50 series). A collector-built window costs more per row because with_view_layout_states keeps it in the view layout through StateColumn::from_views:

  • Every family: +4 B for the u32 offsets, which from_views charges although a record column drops them.
  • Min/Max only: a further +6.7 B, because the view record is 16 B (presence word, value) where the sealed column holds 9 B.

Per series-window across the four views that is +29.8 B, about 7 MB of the 12.5 MB at this plan's retention (60 s plus the 60 s margin). The rest is not yet explained. The backend cannot fix this alone: the executor has no public constructor that seals decoded exact states into its compact record column (StateColumn::sealed and from_exact are pub(crate)), and from_views charges the offsets inside ASAPPlanner. So it is not fixed here.

Follow-ups

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf

@zzylol zzylol added enhancement New feature or request area: control plane Planning, configuration, routing, and control-plane orchestration labels Nov 30, 2026
@zzylol zzylol added the area: data plane Runtime ingestion, storage, and query-serving data paths label Nov 30, 2026
@zzylol zzylol changed the title Control plane: place exact accumulator chains (sum/count/min/max_over_time) on the collector Collector views of exact accumulators: control-plane placement and data-plane ingest (sum/count/avg/min/max_over_time) Nov 30, 2026
The planner's DeploymentCapabilities lists no exact family: each is
supported unless an exclusion its fields expand into rules it out. The
collector rule read sketches only, so `sum_over_time(data[1m])` (an
exact Sum chain) stayed in the backend and `data` was read raw although
the collector's capabilities exclude only the counter states.

Rule (a) now accepts an exact accumulator build over the sample value
when no exclusion of `executor` matches the node. The capabilities
version goes to 2: the same JSON now means exact families are built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf
@zzylol
zzylol force-pushed the feat/collector-exact-accumulators branch from 863a6cf to 99932b0 Compare November 30, 2026 16:54
@zzylol
zzylol changed the base branch from feat/collector-views-file to feat/collector-lineage-reorder-frame November 30, 2026 16:55
A collector sends an exact accumulator's state as the executor's view
layout of it (StateColumn::view_bytes), the record this data plane
stores the state as, behind the lineage frame; there is no ASAPv1
encoding of an exact state, so CollectorViews::new refused every exact
view.

The view's decoder is now a StateDecoder: ASAPv1 for a sketch, and for
Sum/Count/Min/Max the one record read back with StateColumn::from_views
(a record of another size or a bad presence word is a decode reject).
Counter and IRate views are refused (their states depend on sample
order). Lineages, the reorder buffer, merging, commit on arrival and
late merges are unchanged: they hold the decoded kernel state. Two
corrections with equal bytes are distinct records of their lineage and
both merge (collector_exact_views tests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf
@zzylol
zzylol force-pushed the feat/collector-exact-accumulators branch from 99932b0 to 3ff92a0 Compare November 30, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: control plane Planning, configuration, routing, and control-plane orchestration 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