fix(asapedgeprocessor): feed CountMinSketch KindBytes so it records frequencies - #449
Merged
Merged
Conversation
The fused sketch observe handed precompute.FloatValue to every family, but
sketches.CMSObserver only accepts KindBytes (it hashes the encoded attribute
key to count series cardinality, not the numeric value). So for a metric with
family=countminsketch, ObserveKeyed -> CMSObserver.Observe rejected every
sample with "expected KindBytes, got Float". The error was discarded with
`_ =`, and the series was still admitted (empty sketch), so an envelope shell
was emitted while no frequency was ever recorded.
Fix:
- For the CMS family, build the observation value as
BytesValue(AttributesKey(labels, nil)) — the full attribute key, matching the
standalone countminsketchprocessor shim. AggregateBy grouping is applied
separately by SeriesKeyFor, so the inserted key stays the full attribute set.
- Stop swallowing the ObserveKeyed error: retain it on the aggregator and log
once per aggregator. This is what hid the bug.
- Add TestCountMinSketchRecordsFrequency, which reconstructs the emitted CMS and
asserts the inserted key's estimated frequency (~N). It fails without the fix
("expected KindBytes, got Float") and passes with it.
CountSketch is unaffected (its observer takes KindFloat); only CMS required
KindBytes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
What
For
family: countminsketch, the fusedasap_edgeprocessor recorded nothing: it emitted a CountMinSketch envelope shell every window but never counted any frequencies. This fixes that and adds a regression test that asserts a real count.Root cause
warm_sketch.go'sobservebuiltValue: precompute.FloatValue(val)for every family. Butsketches.CMSObserveris the only observer that requiresKindBytes(cms.go:263) — it hashes the encoded attribute key to count series cardinality, not the numeric value. So for CMS:ObserveKeyed→CMSObserver.Observereturned"expected KindBytes, got Float"and never calledInsertHash.Drainemitted an envelope with data points._ =.Net: an envelope was emitted while zero frequencies were recorded — and the existing
all_familiessmoke test (assertsDataPointCount() != 0) stayed green, hiding it.Fix
BytesValue(AttributesKey(labels, nil))— the full attribute key, matching the standalonecountminsketchprocessorshim (shim_helpers.go:58).AggregateBygrouping is applied separately bySeriesKeyFor, so the inserted key stays the full attribute set (nil), preserving query-time parity.ObserveKeyederror: retain it on the aggregator and log it once. This silent_ =is exactly what hid the bug.CountSketchis unaffected — its observer takesKindFloat(countsketch.go:211). Only CMS neededKindBytes.Test
TestCountMinSketchRecordsFrequencydrives 40 CMS observations through the fusedobserve, reconstructs the emitted CMS from the envelope payload (ApplyDelta), and assertsEstimateCount(key) >= 40. It fails without the fix (CMSObserver: expected KindBytes, got Float) and passes with it.go build/vet/test ./...all green.Based on top of the reorg (#448), so the fix lives in
warm_sketch.go.🤖 Generated with Claude Code