perf(metric): cache attribute-exclude filter decisions per key (mondaytweaks flag)#14
Draft
arutkowski00 wants to merge 1 commit into
Draft
perf(metric): cache attribute-exclude filter decisions per key (mondaytweaks flag)#14arutkowski00 wants to merge 1 commit into
arutkowski00 wants to merge 1 commit into
Conversation
…loop on every measurement Add CacheMetricAttributeExcludeDecisions flag (default true) in mondaytweaks. When enabled, both the Prometheus and OTEL attribute-filter closures use a sync.Map to memoize the regex-loop result per distinct attribute.Key. Attribute keys are a small, bounded, static set, so after warmup the hot path is a single map lookup (O(1), zero regex calls). Benchmarks (15 keys, 3 regexes, Apple M4 Pro): OTEL old: 1320 ns/op, 0 B/op, 0 allocs → new: 145 ns/op, 0 B/op, 0 allocs (~9x) Prom old: 2130 ns/op, 350 B/op, 15 allocs → new: 152 ns/op, 0 B/op, 0 allocs (~14x, all allocs eliminated) Semantics are identical: same regexes, same inputs, result cached per key.
Router image scan passed✅ No security vulnerabilities found in image: |
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
Caches the attribute-exclude filter decision for each attribute key so the regex loop runs once per unique key rather than on every metric measurement.
Without caching, every call to
AddCustomMetricAttributesiterates over all exclusion patterns for every attribute it receives — at high metric throughput this shows up as a measurable hot path. A 2026-07-10 production pprof analysis (12:00–12:05 UTC, 3 regions) confirmed the OTEL regex exclude filter at 4.4% CPU + 16.5 GB alloc/90 s.New mondaytweaks flag
CacheMetricAttributeExcludeDecisionsBenchmarks
Measured with
go test -bench=BenchmarkMetricAttributeExclude -benchmem -count=5on the same machine before and after the change.Before
After
~9× faster for OTEL, ~14× faster for Prometheus; Prometheus allocations eliminated.
Source
Derives from the 2026-07-10 production pprof analysis of the Cosmo router.