Skip to content

refactor(distributor): extract profile stripping into sampling package - #5441

Merged
aleks-p merged 2 commits into
mainfrom
alsoba13/extract-sampling-stripper
Aug 5, 2026
Merged

aleks-p merged 2 commits into
mainfrom
alsoba13/extract-sampling-stripper

Conversation

@alsoba13

@alsoba13 alsoba13 commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

What

Moves stripProfileToTotals (and its hasNegativeValue helper) out of distributor.go into a new Stripper component in pkg/distributor/sampling. The distributor now holds it as d.stripper and the call site reads:

d.stripper.StripToTotals(req.Profile.Profile)

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.go would grow an already large file with logic that has no distributor state in it. This PR creates the seam first: the Stripper struct is intentionally stateless for now and gains its dependencies (a Ruler) in the follow-up, while distributor.go stays at a one-line call.

Naming

Stripper, not Sampler: 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 to ingestionLimitsSampler.

Tests

  • Strip-semantics unit tests move next to the code: pkg/distributor/sampling/stripper_test.go (TestStripper_StripToTotals*), including the edge cases (negative values, value-length mismatch, sample labels).
  • Distributor tests (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.

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.
@alsoba13
alsoba13 marked this pull request as ready for review July 30, 2026 14:16
@alsoba13
alsoba13 requested a review from aleks-p as a code owner July 30, 2026 14:16
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.
@aleks-p
aleks-p merged commit 290d6ae into main Aug 5, 2026
38 checks passed
@aleks-p
aleks-p deleted the alsoba13/extract-sampling-stripper branch August 5, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants