Skip to content

feat(monitor): dynamic coordinator→edge sampling coupling (coordinator half) - #368

Merged
zzylol merged 1 commit into
mainfrom
feat/coordinator-sampling-coupling
Jun 11, 2026
Merged

zzylol merged 1 commit into
mainfrom
feat/coordinator-sampling-coupling

Conversation

@zzylol

@zzylol zzylol commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Coordinator half of the dynamic coordinator↔sampling coupling

Completes the loop: the coordinator tracks each edge's reported per-window rate, computes a per-edge update-sampling probability p_i that minimizes total edge update work at a target accuracy, and ships it in each edge's SlackGrant.sample_porthogonal to the slack countdown (sampling is an additive grant field; alert logic untouched).

sampling_alloc.rs (new — port of the Go AllocateSampleRates)

  • p_i = clamp(√λ·√(f_i/rate_i), 0, 1], λ tuned by bisection so the merged sampling-variance Σ f_i(1−p_i)/p_i ≤ var_budget binds.
  • epsilon_sample_floor: p ≥ 1/(1 + ε²·rate) — the ε_cdm ≳ ε_s coupling rule made pointwise, so sampling noise can't exceed the CDM tolerance.
  • Edge cases mirror the Go impl (rate≤0/freq≤0 ⇒ p=1).

Coordinator wiring

  • EdgeView.rate tracked from MonitorReport.rate (on_report).
  • allocate_p() builds the per-edge rate vector, calls the allocator, clamps each p_i up to the ε-floor; rebroadcast grants p_i only with ≥2 edges (single-edge/unknown ⇒ p=1).
  • server.rs threads rate through and sets SlackGrant.sample_p from Action::Grant.
  • var_budget = (ε·τ)² — the CDM tolerance on the monitored value, in quantities the coordinator already holds (ε, τ from MonitorConfig).

Tests

Allocation (skewed fleet beats uniform-p at equal variance; flat fleet no win; floor/edge cases); coordinator (single edge ⇒ p=1; skewed rates ⇒ differentiated sample_p, hot < quiet, both ≥ ε-floor, slack untouched); plus the cross-language wire gate (crates/asap_otel_proto/tests/coupling_wire_compat.rs): Go-encoded SlackGrant.sample_p + MonitorReport.rate decode field-exact here. cargo build -p data_plane clean; monitor (22) + full --lib suite green.

Pairs with the edge half in ASAPCollector (reports rate; applies the granted sample_p via WithSampleP at the epoch boundary, family-gated to CMS/Count-Sketch/DDSketch). Validated end-to-end across the wire, both directions.

🤖 Generated with Claude Code

…r half)

Wires the coordinator side: it tracks each edge's reported per-window rate,
computes a per-edge update-sampling probability p_i that minimizes total edge
update work at a target accuracy, and ships it in each edge's SlackGrant.sample_p
— orthogonal to the slack countdown (sampling is an additive grant field).

Proto: SlackGrant.sample_p (field 6) + MonitorReport.rate (field 8); prost
regenerates the bindings at build.

- sampling_alloc.rs (new): Rust port of the Go AllocateSampleRates —
  p_i = clamp(sqrt(λ)·sqrt(f_i/rate_i), 0, 1] with λ tuned by bisection so the
  merged sampling-variance Σ f_i(1−p_i)/p_i ≤ var_budget binds; uniform_sample_rate;
  and epsilon_sample_floor (p ≥ 1/(1+ε²·rate)) — the ε_cdm ≳ ε_s coupling rule
  made pointwise. Edge cases mirror the Go impl (rate≤0/freq≤0 ⇒ p=1).
- coordinator.rs: EdgeView.rate tracked from MonitorReport.rate via on_report;
  Action::Grant carries sample_p; allocate_p() builds the per-edge rate vector,
  calls allocate_sample_rates, clamps each p_i up to the ε-floor; rebroadcast
  grants p_i only with ≥2 edges (single-edge/unknown ⇒ p=1). Slack/alert logic
  untouched.
- server.rs: apply_report/handle_msg thread rep.rate → on_report; dispatch sets
  SlackGrant.sample_p from Action::Grant.
- var_budget = (ε·τ)²: the CDM tolerance on the monitored value, in quantities
  the coordinator already holds (ε, τ from MonitorConfig) — the design doc's
  ε_cdm ≳ ε_s coupling. The per-edge floor enforces it pointwise too.

Tests: allocation (skewed fleet beats uniform-p at equal variance; flat fleet
no win; floor/edge cases); coordinator (single edge ⇒ p=1; skewed rates ⇒
differentiated sample_p, hot<quiet, both ≥ ε-floor, slack untouched). Plus the
cross-language wire gate (crates/asap_otel_proto/tests/coupling_wire_compat.rs):
Go-encoded SlackGrant.sample_p + MonitorReport.rate decode field-exact here.
cargo build -p data_plane clean; monitor + full --lib suite green.

Pairs with the edge half in ASAPCollector. See
docs/distributed-nitrosketch-coordinated-sampling.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit a1fe4a5 into main Jun 11, 2026
@zzylol
zzylol deleted the feat/coordinator-sampling-coupling branch June 11, 2026 18:43
zzylol added a commit that referenced this pull request Jun 11, 2026
…ield

test(monitor): fix monitor_grpc integration-test compile (rate field from #368)
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