Skip to content

collector_views: sequence numbers and delta emission (full, then deltas per window) - #61

Draft
zzylol wants to merge 1 commit into
feat/collector-views-late-correctionsfrom
feat/collector-views-lineage-deltas
Draft

zzylol wants to merge 1 commit into
feat/collector-views-late-correctionsfrom
feat/collector-views-lineage-deltas

Conversation

@zzylol

@zzylol zzylol commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What to review

Collector view states now carry sequence numbers, and a window can be sent more than once as deltas. The receiver rules are in ASAPQuery-backend's design doc (docs/design/collector-sketch-ingest.md, section 8). Its PR will be stacked on the collector-views-file PR.

  • Why: two different corrections with equal bytes (for example, two late samples with the same value) were deduplicated as one retry. ASAPQuery-backend also could not tell a lost record from one never sent.
  • Wire:
    • asap.producer_epoch: Metric metadata, decimal text of a u64. A random number drawn when the collector starts.
    • asap.sequence: int.
    • asap.state_kind: "full" or "delta".
    • asap.base_sequence: int, deltas only.
    • Record 0 of a (view, series, window) is a full. Record n ≥ 1 is a delta on record n − 1.
  • Behaviour: each emission of a window is the state of the samples taken since the previous emission. Sealing the window's run does this, and the next sample starts a new run. As a result:
    • Corrections are deltas.
    • The new optional setting open_window_emit_interval_ms (off by default) also emits open windows, so the backend can answer them with fresh partial states.
    • DDSketch delta = the new samples' bucket counts. A full plus its deltas is byte-equal to the at-close state.
    • KLL delta = a KLL of the new samples. It merges within the rank-error bound.
  • On-time path with the setting off: the states are unchanged apart from the lineage fields. The golden file tests/golden/collector-views-states.bin is unchanged. Its test strips the lineage and compares messages.
  • collector-views.json: accepts window_close_delay_ms and ignores it. ASAPQuery-backend's idle close reads it.

Interfaces

 // envelope.rs
+pub struct Lineage { pub producer_epoch: u64, pub sequence: u64 }
+impl Lineage { pub fn base_sequence(&self) -> Option<u64> }   // None for a full
 pub struct SketchEnvelope {
     ...
+    pub lineage: Option<Lineage>,   // None outside planner_views
 }

 // otap/schema.rs
+pub const META_PRODUCER_EPOCH: &str = "asap.producer_epoch";
+pub const ATTR_SEQUENCE: &str = "asap.sequence";
+pub const ATTR_STATE_KIND: &str = "asap.state_kind";   // "full" | "delta"
+pub const ATTR_BASE_SEQUENCE: &str = "asap.base_sequence";

 // otap/view_executor.rs
+impl ViewExecutor {
+    pub fn with_epoch(views: &PlannerViews, epoch: u64) -> Result<Self, Error>;
+    pub fn emit_open(&mut self) -> Closed;   // seal open windows' runs, windows stay open
+    pub fn epoch(&self) -> u64;
+}

 // otap/collector_views.rs
 pub struct CollectorViewsConfig {
     pub planner_views: PathBuf,
+    pub open_window_emit_interval_ms: Option<u64>,   // default None; 0 refused
 }
+// counter processor.collector_views/states.delta

 // otap/planner_views.rs
 pub struct CollectorViewsFile {
     ...
+    #[serde(default)]
+    pub window_close_delay_ms: Option<u64>,   // ignored
 }

The decoder reads the lineage back into SketchEnvelope::lineage, and the lineage attributes are not labels. If the epoch, sequence, kind and base are partial or disagree, decoding fails. On the OTAP Arrow path, a full's sequence 0 can be left out by the sparse int encoding, so the decoder reads a full with no sequence as sequence 0. OTLP keeps the 0.

Tests

Command: cargo test --features otap-engine --lib (158 passed) plus --test collector_views_e2e --test otap_pipeline_e2e --test runtime. cargo fmt and cargo clippy --all-targets --features otap-engine,stream-benchmark -- -D warnings are clean.

New tests:

  • ddsketch_full_and_deltas_equal_the_at_close_state: open-window emissions, the close and a correction, merged in order, give the at-close state byte for byte.
  • kll_full_and_deltas_are_within_the_bound_of_the_at_close_state: rank error ≤ 1.65 % (k = 200).
  • corrections_with_equal_bytes_have_distinct_sequences: equal payloads get sequence 1 (base 0) and sequence 2 (base 1).
  • a_restart_starts_each_window_with_a_full_of_a_new_epoch
  • open_window_emission_keeps_the_window_open
  • a_delta_round_trips_and_epochs_are_separate_metrics
  • an_inconsistent_lineage_is_refused_on_decode
  • a_file_with_the_window_close_delay_loads
  • emitted_states_match_the_golden_bytes (rewritten): the golden file is unchanged, and the emitted messages less the lineage equal it.
  • q01_otlp_body_matches_golden: the fixture tests/fixtures/collector-views/q01/otlp-body.pb is regenerated with fixed epoch 9241337045811906213 and the full's lineage attributes.

Decisions (2026-11-30, ASAPQuery-backend design doc §8, decisions 30–34)

  • Wire format follow-up. The three lineage attributes here are replaced by a binary lineage frame in sketch.envelope in collector_views: carry the lineage in a binary frame in sketch.envelope (48.7 → 3.8 B per state) #64, stacked on collector_views: find a point's series by its attribute bytes (1.27 → 1.11 µs/sample) #62. On the golden on-time states the lineage cost drops from 48.7 B per state to 3.8 B. The producer epoch stays in the metric metadata.
  • KLL delta = a partial KLL of only the new samples, merged at the receiver. This departs from the reference transmission protocol (which sends full KLL states). The departure is recorded in the backend design doc; the collector's protocol document is unchanged.
  • Delivery is at-least-once, via the exporter's retry. There is no resync request: the backend never asks for a full state. A record that is truly lost leaves its window incomplete, and the next window or a restart starts clean.
  • Out-of-order arrival is fine. The backend holds a delta until its base arrives, for up to the declared window_close_delay_ms, so a concurrent exporter does not produce false gaps.

Open questions

  • Lineage memory. Sequences are kept per run group, window and series while the window is within retention, keyed by a 64-bit hash of the series key: about 12 bytes plus map overhead per (series, window).

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf

…as per window)

Every collector view state now carries its lineage, the records one
collector instance sends for one (view, series, window):

- asap.producer_epoch (Metric metadata, decimal text of a u64): the
  instance, a random number drawn when the executor starts; states of two
  epochs are two Metric entries.
- asap.sequence (int), asap.state_kind ("full" | "delta") and
  asap.base_sequence (int, deltas only) on each point: record 0 is a full,
  record n >= 1 a delta on n - 1.

Each emission of a window is the state of the samples taken since the
previous one: the window's run is sealed and the next sample starts a new
run. So corrections of late samples are deltas, and the new optional
processor setting open_window_emit_interval_ms (default off: a window is
emitted at its close, as before) also emits open windows, as a full and
then deltas, so ASAPQuery-backend answers them with fresh partial states.
For DDSketch a delta is exactly the new samples' bucket counts; for KLL it
is a KLL of the new samples, which merges within the sketch's rank error.
Sequences are kept per run group, window and series (by a hash of the
series key, since series ids are reused) while the window is within
retention; the views of a group filter by labels only, so this is each
view's lineage. Two corrections with equal bytes now get sequences 1 and 2
instead of looking like one retry. A new counter states.delta counts the
deltas sent.

collector-views.json may carry window_close_delay_ms (copied by the
control plane for ASAPQuery-backend's idle close); the loader accepts and
ignores it, and still refuses unknown fields.

The golden on-time states file is unchanged: its test now strips the
lineage (epoch metadata, sequence 0, kind full) from the emitted messages
and compares them with the file's. The q01 wire example
tests/fixtures/collector-views/q01/otlp-body.pb is regenerated with a
fixed epoch (9241337045811906213) and the full's lineage attributes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf
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