Skip to content

feat(monitor): whole-sketch F2 functional + unify sampling to the ε-floor - #381

Merged
zzylol merged 2 commits into
mainfrom
feat/monitor-f2-live
Jun 17, 2026
Merged

zzylol merged 2 commits into
mainfrom
feat/monitor-f2-live

Conversation

@zzylol

@zzylol zzylol commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Two coherent changes to the CDM monitor, on top of the merged #377/#378/#379:

1. Whole-sketch F2 functional (round-trip)

Adds Functional::F2 and publishes the monitor's functional in the streaming-config entry so the edge auto-learns its reporting mode. MonitorSpec gains a pass-through functional field. F2 = whole-sketch L2 (‖f‖₂², no per-point key, identity (agg_id,"")); the edge reports its local F2_i = Σ_x f(x)².

2. Unify coordinated sampling to the whole-sketch ε-floor

Retire the per-key √(f_i/rate_i) KKT allocation. The single coordinated-sampling law for a sketch is the whole-sketch ε-floor

p_i = 1 / (1 + ε²·rate_i)

Why: sampling protects the warm SKETCH, whose point/L2 estimate error is bounded by the stream norm (rate/L2 — NitroSketch), never by a single key's f(x). The only accuracy a per-edge p buys is keeping that edge's mass within ε (ε_s=√((1−p)/(p·rate))≤ε ⇒ the floor). √(f/rate) only holds when a key is EXACT-counted outside the sketch — pointless to sample — so it is not a valid sketch-sampling regime. The monitored functional (cms_point/f2/sum) still drives the threshold/alert (known_value→global_estimate); it no longer drives sampling.

  • coordinator::allocate_p → ε-floor only (drop var_budget + allocate_sample_rates).
  • sampling_alloc: delete allocate_sample_rates + uniform_sample_rate; keep epsilon_sample_floor. Module doc states the law + applicability: Count-Min, Count-Sketch, DDSketch, KLL, Sum — NOT HLL (update-sampling biases cardinality, not 1/p-correctable).
  • f2: delete DistributedF2Monitor::{allocate_p, sampling_var_budget} + EdgeF2.rate → now a pure F2 threshold monitor (CountSketchF2 + geometric kept).
  • mod.rs doc: the two orthogonal axes (what-to-monitor vs how-to-sample). (Supersedes the closed docs(monitor): when to use whole-sketch (agg_id) vs single-point (agg_id,key) #380.)

Validated live (8-node, both monitor types collapse to one law)

monitor rate (hot→quiet) before after (ε-floor)
cms_point 600k/120k/24k 0.0010/0.0022/0.0049 (√rate) 0.0001/0.0003/0.0013
whole-sketch F2 38400/9600/2400 0.0102/0.0026/0.0007 (unchanged)

28/28 monitor tests pass; data-plane image rebuilt + re-run, auto-learn + hot-reload green.

🤖 Generated with Claude Code

zz_y and others added 2 commits June 17, 2026 09:31
…e-sketch)

Adds Functional::F2 (whole-sketch L2 = ‖f‖₂², no per-point key) and publishes
the monitor's functional in the streaming-config entry so the edge can auto-learn
its reporting mode. MonitorSpec gains a pass-through functional field. The
coordinator allocation is unchanged: it allocates on the reported scalar value,
and p_i ∝ √(value/rate) IS the F2 allocation when the edge reports value=‖f_i‖²
(per data_plane::monitor whole-sketch decision rule, PR #380). This is the B1
(scalar-F2) live path; the sketch-shipping + geometric DistributedF2Monitor
(f2.rs) stays as the comm-efficient B2 follow-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…loor

Retire the per-key √(f_i/rate_i) KKT allocation; the single coordinated-sampling
law for a sketch is the whole-sketch ε-floor p_i = 1/(1+ε²·rate_i).

Why: sampling protects the warm SKETCH, whose point/L2 estimate error is bounded
by the stream norm (rate/L2 — NitroSketch), never by a single key's f(x). So the
only accuracy a per-edge p buys is keeping that edge's mass within ε
(ε_s=√((1−p)/(p·rate))≤ε ⇒ the floor). The √(f/rate) allocation only holds when a
key is EXACT-counted OUTSIDE the sketch — and sampling one exact counter is
pointless — so it is not a valid sketch-sampling regime. The monitored functional
(cms_point/f2/sum) still drives the THRESHOLD (known_value→global_estimate/alert);
it no longer drives sampling.

- coordinator::allocate_p → ε-floor only (drop var_budget + allocate_sample_rates).
- sampling_alloc: delete allocate_sample_rates + uniform_sample_rate (+ tests);
  keep epsilon_sample_floor. Module doc states the law + applicability: additive
  sketches (Count-Min L1, Count-Sketch L2, DDSketch/KLL rank, Sum); NOT HLL
  (update-sampling biases cardinality, not 1/p-correctable).
- f2: delete DistributedF2Monitor::{allocate_p, sampling_var_budget} + EdgeF2.rate;
  it is now a pure F2 THRESHOLD monitor (CountSketchF2 + geometric kept).
- mod.rs doc: separate the two orthogonal axes (what-to-monitor vs how-to-sample).

28/28 monitor tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@zzylol
zzylol merged commit 6e4ae98 into main Jun 17, 2026
@zzylol
zzylol deleted the feat/monitor-f2-live branch July 17, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant