Repository navigation
refactor(distributor): extract profile stripping into sampling package - #5441
Merged
Merged
Conversation
Move stripProfileToTotals out of distributor.go into a Stripper component in pkg/distributor/sampling, called as d.stripper.StripToTotals. Upcoming work will make stripping recording-rules aware, which means more stripping mechanism; this gives it a home of its own so distributor.go stops growing. The strip-semantics unit tests move next to the code in the sampling package. The distributor tests keep verifying the accounting around stripping (discarded bytes, sampled label, language detection ordering) against an explicit golden fixture.
The bare agent-noun is ambiguous in isolation; the qualified compound follows the PDFTextStripper-style convention and matches the "rules-aware sample stripper" wording used by the follow-up work.
simonswine
approved these changes
Aug 5, 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.
What
Moves
stripProfileToTotals(and itshasNegativeValuehelper) out ofdistributor.gointo a newStrippercomponent inpkg/distributor/sampling. The distributor now holds it asd.stripperand the call site reads:No behavior change — pure code movement plus the component seam.
Why
Follow-up work will make stripping recording-rules aware (#5444, stacked on this PR): when a sampled-out profile is kept, samples whose stacktraces are targeted by a tenant's recording rules must survive stripping so rules keep producing correct metrics. That adds a fair amount of stripping mechanism (rule matching, symbol pruning) and a dependency on a recording-rules provider.
Landing all of that in
distributor.gowould grow an already large file with logic that has no distributor state in it. This PR creates the seam first: theStripperstruct is intentionally stateless for now and gains its dependencies (aRuler) in the follow-up, whiledistributor.gostays at a one-line call.Naming
Stripper, notSampler: the sampling decision (shouldSample, probabilities) stays in the distributor; this component only executes the post-decision transformation. It also avoids a second "sampler" on the distributor next toingestionLimitsSampler.Tests
pkg/distributor/sampling/stripper_test.go(TestStripper_StripToTotals*), including the edge cases (negative values, value-length mismatch, sample labels).TestPushSeries_KeepStrippedProfiles/_DropSampledOutProfiles) keep verifying the accounting around stripping — discarded-bytes bookkeeping, the__sampled__label, language detection running before the string table is stripped — against an explicit golden fixture. The input/expected fixtures are deliberately duplicated between the two test files so the integration test keeps an independent oracle.