refactor(countminsketchprocessor): thin shim delegating to asap-precompute-go (Phase 2 step 2.9) - #230
Merged
Conversation
…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.
This was referenced May 4, 2026
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>
This was referenced May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) —cmsSketchWrapperimplementingSketch + FrequencySketchover sketchlib-go*cms.CountMinSketch;cmsSketchObserverfor KindBytes inputs.config_translate.go(~87 LoC) —Config.toPrecomputeConfig. PinsOmitResourceAttrs=true,GlobalAggregation=false,EmitWindowStats=false.DeltaTransmission=falseis 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, whileprecompute.SnapshotCacheonly refreshes when the wrapper signalsisFull=true. To preserve legacy delta-against-N-1 wire shape without modifyingasap-precompute-go,applyDeltaTransmissionrewrites 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 legacymetricName + "::" + encodeKey(dpAttrs)).GlobalAggregation=false— CMS emits per-series.EmitWindowStats=false— CMS does NOT emitsample_count/window_duration_secondsinside envelope Labels; shim's encode path stampsSampleCountonto the typedCountMinSketchDataPointfield 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.go test -count=1 ./...inintegration/parity).🤖 Generated with Claude Code