fix(prometheus): guard family membership against metric-name prefix collisions - #309
Open
detail-app[bot] wants to merge 1 commit into
Conversation
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a narrowly scoped Prometheus filtering bug fix that prevents stale HELP/TYPE and policy metadata from crossing metric-family boundaries while preserving histogram and summary suffix handling. The implementation is self-contained and backed by targeted regression tests, with no schema, infrastructure, or sensitive-area changes. You can add or adjust custom eligibility rules. Learn more. |
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.
Detail bug report: View on Detail
Fixes ENG-710
Bug
PolicyStreamingFilter(the streaming Prometheus policy proxy insrc/signals/prometheus/streaming_filter.zig) associated each sample to the current metric family with a barestd.mem.startsWith(sample_name, current_metric_name)and never invalidated the stored family metadata (# HELP/# TYPE, description, type) when a family's samples were all policy-dropped. A later, different family whose sample name merely extended the dropped family's name (e.g.foo_extraafter a fully-droppedfoo) was treated as a member of the dropped family, causing:# HELP foo/# TYPE foolines emitted in front of the unrelatedfoo_extrasample.foo_extraagainstfoo's stale description/type — wrong-direction false drops (and, symmetrically, false keeps under KEEP policies).Fix
belongsToCurrentFamily, a type-aware membership predicate: exact name match for counter/gauge/untyped/# TYPE-less families, plus<name>_bucket/_sum/_countsuffixes for histograms and<name>_sum/_countfor summaries._totalis treated as part of the family name (this repo's convention), not a suffix, so a hardcoded suffix whitelist can't re-introduce the bug.maybeWriteMetadataandshouldKeepMetricnow use this predicate, so a dropped family's metadata is never emitted for a non-member and description/type fall back tonullfor non-members during policy evaluation.clearCurrentMetadatato invalidate stored metadata at a family boundary, an orthogonal safeguard against stale metadata leaking past a fully-dropped family.Testing
_totalsuffix footgun, histogram/summary suffix handling, and cross-family-boundary invalidation). Full unit suite passes (526 pass, 1 skipped).zig fmt --check,ziglint, andtask do(format + lint + ReleaseSafe tests) all pass.edge-prometheusbinary against a fake Prometheus upstream serving prefix-colliding exposition text, via GET/metrics:^foo$emits onlyfoo_extra 2with no orphan# HELP/# TYPE foo;foo's HELP still keeps the metadata-lessfoo_extra;go_memstats_alloc_bytesgauge vsgo_memstats_alloc_bytes_totalcounter under a description-DROP keeps the_totalcounter and a distinctbarfamily's own metadata;le="0.1"bucket emits the family# HELP/# TYPEexactly once before the first kept sample./_edge/metricsconfirmed the requests traversed the filter path.Not verified:
--test-filterflag and the build defines no per-name test step, so per-test isolation is evidenced by the mutation check rather than per-name runs.lines_kept/lines_dropped/bytes_forwardedstats over the wire: the server discards the filter'sFilterStatsreturn value, so these stats are only observable via the existing unit tests (which pass), not from a live response.Automatic Fixes PRs can be configured here.