Add WithBlockedStats SinkOption to drop stats by exact name - #177
Closed
th0114nd wants to merge 2 commits into
Closed
Add WithBlockedStats SinkOption to drop stats by exact name#177th0114nd wants to merge 2 commits into
th0114nd wants to merge 2 commits into
Conversation
net_sink now accepts an optional map[string]struct{} of blocked stat
names via WithBlockedStats. FlushCounter/FlushGauge/FlushTimer do an
O(1) lookup against it and silently drop matching stats before they're
buffered or written to the wire.
The lookup is against the name gostats itself resolves (dot-joined
scope path plus serialized tags) — it does not see any environment
prefix or aggregation-type suffix (:count, :rate, :p99, ...) that a
downstream metrics pipeline appends after ingestion. Callers populating
the map from an externally sourced blocklist (e.g. a Grafana Cloud
metric-blocklist export) need to strip those before use.
Motivated by matchingconfigset wanting to drop known-noisy matchingv2
metrics before they leave the process, rather than relying entirely on
downstream blocklist rules.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
internal/tags always appends serialized tags after a stat's name via ".__key=value" (sorted by key, sourced from TagSet.Serialize / SerializeTags) — never in the middle of it. So matching on the exact full resolved name meant one blocklist entry only covered one specific tag combination, which isn't viable for anything with per-instance or otherwise variable tags. Truncate at the first ".__" before the map lookup so a single entry matches a stat regardless of its tag values. Also adds TestNetSink_BlockedStats_IgnoresTags and BenchmarkFlushCounter_BlockedStats, which sweeps blocklist size from 0 to 100k entries for both the allowed and blocked paths. Confirms the lookup is genuinely O(1) (~57ns/op flat across all sizes) and zero allocations. Co-Authored-By: Claude Sonnet 5 <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.
Summary
WithBlockedStats(map[string]struct{})SinkOptiontonetSink.FlushCounter/FlushGauge/FlushTimerdo an O(1) map lookup against it and silently drop matching stats before they're buffered or written to the wire.Important caveat: what "name" actually is
The lookup is against the name gostats itself resolves — the dot-joined scope path plus any serialized tags (e.g.
service.subscope.stat_nameorstat_name.__tag=value), exactly as passed intoFlushCounter/FlushGauge/FlushTimer.It does not include:
production:,staging:) added by a downstream ingestion pipeline, or:count,:rate,:p99,:sum) added by a downstream aggregator/exporter.Motivation
Test plan
go build ./...go vet ./...go test ./...(124 passed)TestNetSink_BlockedStats,TestNetSink_BlockedStats_NilMap🤖 Generated with Claude Code