Skip to content

Collector views: exact Sum, Count, Min and Max per series and window - #63

Draft
zzylol wants to merge 1 commit into
feat/collector-views-lineage-framefrom
feat/collector-views-exact-accumulators
Draft

zzylol wants to merge 1 commit into
feat/collector-views-lineage-framefrom
feat/collector-views-exact-accumulators

Conversation

@zzylol

@zzylol zzylol commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: a control plane placed no collector view for sum_over_time(data[1m]), count_over_time, avg_over_time, min_over_time or max_over_time on a gauge, so the backend kept reading data raw. The collector built sketches only (DDSketch, KLL).
  • Change: the collector now builds the exact Sum, Count, Min and Max states per series and tumbling window (end − w, end] on ASAPPlanner's executor. On-time samples go to the window's own state, and late samples within retention go to a correction state. Every state is a record of its lineage: a full first, then a delta for each emission of an open window and for each correction, behind the same frame as sketch states. Each state is sent as the executor's view-layout record, which is the same bytes ASAPQuery-backend stores for that view. --print-capabilities goes to version 2: the executor block is read with the planner's own meaning, and that meaning already covers these four exact families.
  • Effect: with the matching control-plane change (Collector views of exact accumulators: control-plane placement and data-plane ingest (sum/count/avg/min/max_over_time) ASAPQuery-backend#895), sum_over_time(data[1m]) gives backend_reads_raw: {"data": false} and one collector view. Building the view costs 568 ns/sample for one Sum view, against 749 ns/sample for q01's DDSketch view (10,000 series, 10 samples/s each, one core).

Review guide

Behavior: before → after

Workload: sum_over_time(data[1m]), evaluated every 5 s, on a gauge data (10,000 series, 100 ms interval). Deployment: raw_data_retained: false.

before after
asap-collector --print-capabilities capabilities_version: 1, sketches only capabilities_version: 2, same executor JSON; under the planner's meaning it supports exact Sum/Count/Min/Max and excludes Counter/IRate
control plane (--emit-collector-views) collector views [], backend reads raw {"data": true} collector views [1], backend reads raw {"data": false}
collector (no view) one OTLP Summary point per series and 5 s window on data.asap_view.1; sketch.envelope holds a 24-byte Sum record, and count is the window's number of samples

Same result for count_over_time, min_over_time and max_over_time (one view each), avg_over_time (the Sum and Count views), and the trial mix quantile_over_time(0.99, …) + sum_over_time (DDSketch + Sum, data: false).

Interfaces

otap/capabilities.rs

 /// The version of this format; a reader refuses one it does not know.
+/// Version 2: `executor` is read with the planner's semantics in full, so
+/// the exact accumulator families it does not exclude are built.
-pub const CAPABILITIES_VERSION: u32 = 1;
+pub const CAPABILITIES_VERSION: u32 = 2;

+impl CollectorCapabilities {
+    /// The capability of `executor` that rules out `node` in the planner's
+    /// reading (the source of the first matching exclusion); `None` for an
+    /// ingestion-time exact `Sum` chain.
+    pub fn exclusion_of(&self, node: &PhysicalASAPDAGNode) -> Option<ExclusionSource>;
+}

otap/planner_views.rs

 /// One checked collector view (type stays).
 pub struct CollectorView {
     pub identity: Arc<ViewIdentity>,
     pub source_metric: String,
     pub scan_node: PhysicalASAPNodeId,
     pub output_metric_name: String,
-    /// The chain's sketch.
-    pub sketch: SketchAlgorithm,
+    /// The chain's summary family: a sketch, or an exact accumulator.
+    pub summary: SummaryFamily,
     pub tumbling_window_width_ms: u64,
     pub retention_ms: u64,
 }

Wire format (sketch.envelope of a view whose key has no θ, SketchType::Exact): the executor's StateColumn::view_bytes record, as little-endian 8-byte words. Sum: sum, compensation, seen (24 B). Count: count (8 B). Min/Max: present, value (16 B).

Usage. The control plane runs control_plane --workload w.json --collector-capabilities caps.json --emit-collector-views cv.json, where caps.json comes from asap-collector --print-capabilities. Its rule accepts the ExactAggregate(Sum) chain because no exclusion of executor matches it, and it writes cv.json with that chain as an output. The collector's planner_views::load(cv.json) reads the view as summary: Exact(Sum); exact() checks the sample-value input, that there is no θ, and exclusion_of. ViewExecutor then runs one executor ingestion run per 5 s window. When a window closes, each series' state is encoded by state_bytes (view layout) and encode (with count from the window's tally), and sent as data.asap_view.1.

Algorithm

None new. The executor builds the states, exactly as it does for sketches. This PR only reads exact states out in the executor's view layout and counts the samples it sends per series for each window. The tally exists only in run groups that have an exact view, at one vector increment per sample.

Decisions and open questions

Needs reviewer decision

  • How exact accumulators are declared. ASAPPlanner's DeploymentCapabilities cannot list an exact family. supported_summaries is Vec<SupportedSummary> with summary_type: SketchAlgorithm, and its docs say "Exact accumulators and plain exact execution are always supported". The only way to narrow them is through exclusions (counter_semantics, state_not_mergeable_across_windows, excluded_candidates). So this PR adds no field. It bumps capabilities_version instead, because the JSON is unchanged but its meaning now includes exact families. Two things are not expressible in the planner's vocabulary: a positive list of the exact families an executor builds, and the input an exact accumulator reads (a sketch entry has input; an exact family has no entry). The control plane therefore assumes the sample value, and the collector refuses any other input.
  • State bytes. For exact states the collector sends the executor's view layout (StateColumn::view_bytes) rather than an ASAPv1 encoding, since there is no ASAPv1 for exact states. ASAPQuery-backend persists exact view columns in exactly this layout (its compact form rebuilds it byte for byte).

Decided (approved design): capabilities in the planner's vocabulary; asap-executor as a thin driver; Prometheus (end − w, end] windows; states byte-equal to the backend's for the same view; no ASAPPlanner change.

Verification

cargo test --features otap-engine --lib -- otap::capabilities otap::planner_views otap::view_executor otap::codec passes all 65 tests (0 failed, 0 newly failing). cargo clippy --features otap-engine --all-targets and cargo fmt --check are clean. Integration suites were not run locally; the changed paths are covered by the lib tests.

New tests:

  • capabilities::exact_accumulators_are_in_the_printed_capabilities: the printed executor, expanded with the planner's exclusions(), rules out no Sum/Count/Min/Max and does rule out Counter/IRate.
  • capabilities::exact_chains_match_no_exclusion_but_a_counters_does: the fixture's four chains match no exclusion; the same chain as a Counter matches counter_resets_not_handled.
  • planner_views::exact_views_load, an_excluded_exact_family_is_refused and an_exact_chain_needs_the_sample_value_and_no_theta.
  • view_executor::exact_views_build_per_window_states_on_prometheus_boundaries: samples at T−5 s, T−4999, T−2500, T, T+1 and T+5 s land in the windows (end − 5 s, end]. Each state equals a hand-written golden vector of the view-layout bytes (for example Sum 7.5 = 0000000000001e40 0000000000000000 0100000000000000), and count is 1, 3 and 2.
  • view_executor::exact_states_are_the_executors_own_build: the states are byte-equal to one ingestion run per window over all of the window's samples (how the backend builds the view), for 1, 7 or 100 samples per flush, and they hold the window's sum, count, min and max.
  • view_executor::exact_corrections_merge_into_the_on_time_state: late samples within retention become one correction per view and series (count 1). The window's state merged with its correction (add, add, min, max) equals the all-on-time state.
  • codec::exact_view_state_round_trips_through_otap_arrow: a key without θ decodes as Exact, with its bytes and count.
  • view_executor::exact_deltas_and_equal_corrections_carry_distinct_sequences: per exact view, a full (0), a delta of the open window (1), then two corrections of one late sample of value 5.0 each. The two corrections are byte-equal records (Count 1, Sum 5.0, …) with sequences 2 and 3, all from one epoch, and each has count 1. The backend merges both (ASAPQuery-backend#895, equal_bytes_corrections_with_distinct_sequences_both_merge).

Fixture provenance: tests/fixtures/collector-views/exact/ is control_plane --workload planner-workload.json --deployment-capabilities {raw_data_retained: false, query_time_results_retained: false} --emit-collector-views, from the ASAPQuery-backend control-plane draft. Output: collector views [1, 6, 12, 16], backend reads raw {"data": false}.

CPU per sample, from asap-views-bench VIEWS executor 10000 10 20 5 (median of 5, one pinned core, release build):

views ns/sample states VmHWM
q01: DDSketch α 0.05 748.7 30,000 68.5 MB
Sum 568.0 30,000 48.6 MB
Sum + Count (avg_over_time) 790.3 60,000 60.7 MB
Sum, Count, Min, Max 1216.6 120,000 85.5 MB

The sketch path does not change. Groups without an exact view keep no tally.

Follow-ups

  • End to end: Collector views of exact accumulators: control-plane placement and data-plane ingest (sum/count/avg/min/max_over_time) ASAPQuery-backend#895 (on #897, with lineage) makes the data plane ingest these states. In a local run of this PR at its head and a data plane on #895, fed the same seeded samples (10,000 series at 1 sample/s for 240 s) as a raw-ingest data plane: all five queries (sum, count, avg, min, max over data[1m]) answered identically at 32 evaluation times × 10,000 series. The collector arm's data plane received 0 raw samples (raw arm: 2,400,000), and raw_forward dropped all 240 data messages.
  • Deltas: an exact delta is the state of the samples since the last emission: an increment for Sum/Count, a partial for Min/Max. Both merge into the window, in lineage order, by the same merge as a correction.
  • Counter/IRate stay in the backend: they are order-sensitive, and counter_semantics excludes them.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf

@zzylol zzylol added the enhancement New feature or request label Nov 30, 2026
@zzylol
zzylol force-pushed the feat/collector-views-exact-accumulators branch from 19bd8d4 to fac8f03 Compare November 30, 2026 16:55
@zzylol
zzylol changed the base branch from feat/collector-views-late-corrections to feat/collector-views-lineage-frame November 30, 2026 16:55
The planner's DeploymentCapabilities supports every exact accumulator
family unless an exclusion rules it out; the collector's capabilities
exclude only the counter states (counter_semantics), so they already
claimed Sum/Count/Min/Max, but the collector built sketches only.

- capabilities: version 2 (executor read with the planner's semantics in
  full); CollectorCapabilities::exclusion_of checks a node against the
  planner's expansion of executor.
- planner_views: a leaf chain of an exact family is a view
  (CollectorView::summary is the planner's SummaryFamily); it must fold
  the sample value, have no theta and match no exclusion.
- view_executor: an exact state is sent as the executor's view layout
  (StateColumn::view_bytes), the bytes ASAPQuery-backend stores for the
  state it builds of the same view; its count comes from the window's
  per-series sample tally. Late samples go to correction states as for
  sketches.
- codec: a view state key without theta decodes as an Exact state.
- tests/fixtures/collector-views/exact: the control plane's cut of
  sum/count/avg/min/max_over_time(data[1m]).

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-views-exact-accumulators branch from fac8f03 to 3acfc6a 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

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant