Skip to content

refactor(countminsketchprocessor): thin shim delegating to asap-precompute-go (Phase 2 step 2.9) - #230

Merged
zzylol merged 1 commit into
mainfrom
phase2/cms-shim
May 4, 2026
Merged

zzylol merged 1 commit into
mainfrom
phase2/cms-shim

Conversation

@zzylol

@zzylol zzylol commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

CMS processor reduces from ~739 LoC (single processor.go) to a thin shim split into:

  • processor.go (~236 LoC) — lifecycle + ConsumeMetrics dispatch + per-metric Precompute map.
  • shim_helpers.go (~313 LoC) — observeAll (KindBytes hash routing), tickAndEncode, applyDeltaTransmission (legacy-compatible always-refresh-snapshot), encodeTypedSketch / encodeGauge.
  • sketch_wrapper.go (~210 LoC) — cmsSketchWrapper implementing Sketch + FrequencySketch over sketchlib-go *cms.CountMinSketch; cmsSketchObserver for KindBytes inputs.
  • config_translate.go (~87 LoC) — Config.toPrecomputeConfig. Pins OmitResourceAttrs=true, GlobalAggregation=false, EmitWindowStats=false. DeltaTransmission=false is forced into the runtime; the shim handles delta itself (see below).
  • monitor.go (~63 LoC) — extracted selfmonitor wiring.

State machine (windowing, snapshot caching, series keying) moves to asap-precompute-go. The shim owns per-shim delta tracking — the legacy CMS processor refreshes its per-partition snapshot after EVERY emit, while precompute.SnapshotCache only refreshes when the wrapper signals isFull=true. To preserve legacy delta-against-N-1 wire shape without modifying asap-precompute-go, applyDeltaTransmission rewrites runtime-emitted full envelopes into deltas using a shim-owned per-series prev cache.

Per-config flags pinned in toPrecomputeConfig:

  • OmitResourceAttrs=true — series key excludes resource attrs (matches legacy metricName + "::" + encodeKey(dpAttrs)).
  • GlobalAggregation=false — CMS emits per-series.
  • EmitWindowStats=false — CMS does NOT emit sample_count / window_duration_seconds inside envelope Labels; shim's encode path stamps SampleCount onto the typed CountMinSketchDataPoint field directly.

Public test API: Shim.ProcessBatch / ProcessMetrics / FlushWindow.

Mirrors PR #226 (KLL) and PR #227 (DDSketch) layout.

Test plan

  • cd opentelemetry-collector-contrib-patch/processor/countminsketchprocessor && go test ./... — all green (config validation, batch / window mode, AggregateBy, LabelMatchers, DeltaTransmission round-trip + multi-window convergence, round-trip ingest of typed CountMinSketch input).
  • cd integration/parity && go test -v -run TestParity_CountMinSketch ./...parity OK: 602 envelopes matched byte-for-byte.
  • Full parity suite still green (go test -count=1 ./... in integration/parity).

🤖 Generated with Claude Code

…mpute-go

CMS processor reduces from ~739 LoC to a thin shim. State machine
moves to asap-precompute-go. sketch_wrapper.go implements
FrequencySketch over sketchlib-go CountMinSketch.

OmitResourceAttrs preserves legacy series-key semantics
(metric_name + dp-attrs only, no resource).

Public test API: Shim.ProcessBatch/ProcessMetrics/FlushWindow.

Parity harness: TestParity_CountMinSketch byte-identical (602 envelopes).

Phase 2 step 2.9.
@zzylol
zzylol merged commit ab081f9 into main May 4, 2026
@zzylol
zzylol deleted the phase2/cms-shim branch May 4, 2026 13:35
zzylol added a commit that referenced this pull request May 4, 2026
Each Phase-2 shim depends on github.com/ProjectASAP/asap-precompute-go,
a sibling private module with no module-proxy presence. Mirror the
sketchlib-go replace pattern so OCB resolves it to the local checkout.

Without this, the multi-plugin sketchcollector binary fails to build
once any shim PR (#226-#230) merges.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zzylol added a commit that referenced this pull request May 4, 2026
…n sketch wrappers (#232)

Correct SnapshotCache semantics — every ComputeDelta updates the cached
snapshot, matching all 5 legacy OTel processors. The previous
"refresh-only-on-full" path was a design error; no configurable policy
knob is needed because there's only one correct behavior.

Extract platform-independent sketch wrappers (DDSketch, KLL, HLL,
CountSketch, CountMinSketch) into asap-precompute-go/sketches/ so
Telegraf / Vector / OTAP adapters can reuse them.

Document delta-snapshot semantics in design doc.

Note: PR #229 (CountSketch) and PR #230 (CMS) workaround in
shim_helpers.go::applyDeltaTransmission becomes redundant after this
lands; those PRs can rebase to drop the workaround.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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