Skip to content

feat(sketches): per-metric sample_p knob on the CMS + HLL warm processors - #441

Merged
zzylol merged 1 commit into
mainfrom
feat/sample-p-agent
May 25, 2026
Merged

zzylol merged 1 commit into
mainfrom
feat/sample-p-agent

Conversation

@zzylol

@zzylol zzylol commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Plumb a per-sketch sampling probability through the EDGE agent so an operator can activate the recently merged warm-sketch sampling per metric.

  • asap-precompute-go/sketches: the CMS and HLL wrappers gain a WithSampleP(p) fluent setter that calls sketchlib-go's CountMinSketch.WithSampleP(p, seed) / HyperLogLog.WithSampleP(p), and preserve the probability across the Reset / Merge / ApplyDelta re-construction paths (centralised in a newSketch() helper).
  • countminsketchprocessor + hllprocessor: a new sample_p config field (mapstructure:"sample_p"); Config.Validate normalises 0/unset to 1.0 and rejects out-of-range values; the processor passes it into wrapper construction.

Default 1.0 everywhere is an exact no-op (sketchlib-go never touches the RNG at p>=1), so an agent with no sample_p configured emits byte-identical wire bytes to today.

Sampling API used (sketchlib-go #59)

  • CountMinSketch.WithSampleP(p float64, seed int64) — geometric admission.
  • HyperLogLog.WithSampleP(p float64) — hash-threshold element sampling.

Test plan

  • go build ./... green for asap-precompute-go, countminsketchprocessor, hllprocessor.
  • go test ./... green for asap-precompute-go (incl. new sketches/sampling_test.go).
  • New test proves a configured p<1 reaches the underlying sketchlib-go builder (read off the owned sk, not just the wrapper field) and thins admitted updates; default 1.0 unchanged.

NOTE: countminsketchprocessor / hllprocessor go test (the full package) currently fails to compile on main due to a pre-existing stale-test vs pdata skew (processor_test.go references removed dp.SampleCount/Rows/Cols/Cardinality/Precision fields) — unrelated to this PR, which only touches config.go + processor.go. The production go build is green and the reaches-builder proof lives in the asap-precompute-go/sketches package, which tests green.

Merge order

Merge this PR first. The companion control-plane PR (ProjectASAP/ASAPQuery-backend feat/sample-p-control-plane) emits the sample_p agent config and depends on these processor fields existing.

Out of scope / follow-up

Dynamic, optimizer-driven p (tuned online against an accuracy/bandwidth budget) — this PR ships only the static per-metric knob.

🤖 Generated with Claude Code

…sors

Plumb a per-sketch sampling probability through the agent so an operator
can activate the recently added warm-sketch sampling per metric. The CMS
and HLL precompute wrappers gain a WithSampleP fluent setter that calls
sketchlib-go's CountMinSketch.WithSampleP / HyperLogLog.WithSampleP and
preserves the probability across the Reset / Merge / ApplyDelta
re-construction paths. The countminsketch and hll processors expose a
sample_p config field (mapstructure: "sample_p") that the control plane
sets per metric and pass it into wrapper construction.

Default 1.0 everywhere (0/unset normalises to 1.0 in Config.Validate,
which rejects out-of-range values) is an exact no-op, so an agent with no
sample_p configured emits byte-identical wire bytes to today. Adds a
sketches test proving a configured p<1 reaches the underlying sketchlib-go
builder (read off the owned sketch, not just the wrapper field) and thins
admitted updates, while the default 1.0 is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit 005ad3a into main May 25, 2026
zzylol added a commit that referenced this pull request May 26, 2026
… crash) (#444)

The fused asap_edge processor's per-metric config struct did not define
sample_p, so the collector's strict mapstructure decode rejected the key
the control plane emits when a metric's workload sample_p < 1, crash-looping
the agent. Add SampleP to MetricFamily (validated to (0,1], 0/unset => 1.0 =
no sampling) and wire it into the warm sketch-build: HLL and CountMinSketch
factories call sketchlib-go's WithSampleP(p). WithSampleP(1.0) is an exact
no-op, so the unset/1.0 path stays byte-identical to today. DDSketch/KLL/
CountSketch (no sampling support) ignore it. Mirrors the standalone
hll/countminsketch processors' sample_p wiring (#441) for the fused path.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol deleted the feat/sample-p-agent branch May 26, 2026 11:33
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