Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[processor/tailsampling] Support hot sampling policy loading #37014

Merged
merged 5 commits into from
Jan 7, 2025

Conversation

portertech
Copy link
Contributor

@portertech portertech commented Jan 2, 2025

Description

Adding a feature. This pull-request adds support for hot sampling policy loading to the tail sampling processor. This allows the collector (or another service using the processor) to dynamically update tail sampling policy without needing to restart the processor (or the entire collector). This greatly minimizes the impact of sampling policy modifications on pipeline availability and processing. Changes to policy are safely applied on the next tick loop.

A collector (and/or other service) could use OpAMP to remotely manage sampling policy with little to no negative impact on pipeline availability and performance. This is what the https://tailctrl.io/ agent did.

Usage

Currently need to define a custom interface in order to set sampling policy.

type SamplingProcessor interface {
	processor.Traces

	SetSamplingPolicy(cfgs []tailsamplingprocessor.PolicyCfg)
}

factory := tailsamplingprocessor.NewFactory()

tsp, _ := factory.CreateTraces()
sp = tsp.(SamplingProcessor)

sp.SetSamplingPolicy(cfgs)

Testing

Added a test to ensure changes to policy are loaded. Using the changes in a private project.

@portertech portertech requested review from jpkrohling and a team as code owners January 2, 2025 23:05
@github-actions github-actions bot added the processor/tailsampling Tail sampling processor label Jan 2, 2025
@portertech
Copy link
Contributor Author

Will add that changelog entry.

Signed-off-by: Sean Porter <[email protected]>
initialDecisions := make([]sampling.Decision, lenPolicies)
for i := 0; i < lenPolicies; i++ {
initialDecisions[i] = sampling.Pending
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered this little chunk of no-op code, leftover from a decision refactor.

@portertech
Copy link
Contributor Author

@mwear thank you for the review, applied your suggested changes 👍

Copy link
Member

@mwear mwear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good to me. I'll let the codeowners weigh in on the feature addition.

Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thanks! I wonder if you have data about the performance before and after this change.

}

func (tsp *tailSamplingSpanProcessor) SetSamplingPolicy(cfgs []PolicyCfg) {
tsp.logger.Debug("Setting pending sampling policy", zap.Int("pending.len", len(cfgs)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a follow-up PR: it would be useful to have a counter, stating how many times the sampling policy has been set.

}
tsp.SetSamplingPolicy(cfgs)

assert.Len(t, tsp.policies, 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this confused me for a little moment, as I was expecting "3" here -- perhaps add another assertion, with Len(t, tsp.pendingPolicy, 3), to highlight that the cfgs has been accepted by SetSamplingPolicy?

@jpkrohling
Copy link
Member

I'm merging, the comments I left can be addressed on a follow-up PR.

@jpkrohling jpkrohling changed the title [tailsamplingprocessor] Support hot sampling policy loading [processor/tailsampling] Support hot sampling policy loading Jan 7, 2025
@jpkrohling jpkrohling merged commit 5f9d943 into open-telemetry:main Jan 7, 2025
162 checks passed
@github-actions github-actions bot added this to the next release milestone Jan 7, 2025
AkhigbeEromo pushed a commit to sematext/opentelemetry-collector-contrib that referenced this pull request Jan 13, 2025
…lemetry#37014)

#### Description

Adding a feature. This pull-request adds support for hot sampling policy
loading to the tail sampling processor. This allows the collector (or
another service using the processor) to dynamically update tail sampling
policy without needing to restart the processor (or the entire
collector). This greatly minimizes the impact of sampling policy
modifications on pipeline availability and processing. Changes to policy
are safely applied on the next tick loop.

A collector (and/or other service) could use OpAMP to remotely manage
sampling policy with little to no negative impact on pipeline
availability and performance. This is what the https://tailctrl.io/
agent did.

#### Usage

Currently need to define a custom interface in order to set sampling
policy.

``` go
type SamplingProcessor interface {
	processor.Traces

	SetSamplingPolicy(cfgs []tailsamplingprocessor.PolicyCfg)
}

factory := tailsamplingprocessor.NewFactory()

tsp, _ := factory.CreateTraces()
sp = tsp.(SamplingProcessor)

sp.SetSamplingPolicy(cfgs)
```

#### Testing

Added a test to ensure changes to policy are loaded. Using the changes
in a private project.

---------

Signed-off-by: Sean Porter <[email protected]>
Co-authored-by: Matthew Wear <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
processor/tailsampling Tail sampling processor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants