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

Add rule Scope configuration option to rules-based sampler #440

Merged

Conversation

isnotajoke
Copy link
Contributor

@isnotajoke isnotajoke commented Apr 27, 2022

Which problem is this PR solving?

We'd like to be able to apply all of the conditions in a rules-based sampler rule to a single span. In other words, we'd like a rule to be considered matched only if all of the conditions in that rule are satisfied by a single span in the trace. This allows us to more accurately make per-service sampling decisions in a dataset written to by multiple services.

Short description of the changes

At a high level, we add a new Scope configuration option to the rule definition. By default (and if unspecified) it is "trace". If "span", all conditions in the rule must be satisfied together by some span in a trace. This is a subtle but important difference with the default behavior, effectively making a rule more strict than it would otherwise be.

Scope introduces some complexity to the rule based sampler. While many of the operations performed within the
GetSampleRate method (extracting a value, checking for a match) are similar between the two approaches, the shape of the logic to compute a match is totally different when Scope is 'trace' than when it is 'span'. To avoid duplication, we refactor the common methods into private functions; this also makes the logic to loop through & compute a match a little easier to understand at a glance.

I added a basic spec to cover the new behavior.

This can be used to tell the rules sampler to apply rules to a trace as
a whole (the current behavior: a rule matches if each of its conditions
is satisfied by a span in the trace – it doesn't have to be the same
span) or to individual spans (meaning that a rule is matched only if
some span in the trace satisfies each of its conditions)
This preps for adding alternate ways to evaluate a rule (in the next
commit)
@isnotajoke isnotajoke requested a review from a team April 27, 2022 20:10
@@ -62,6 +62,7 @@ type RulesBasedSamplerRule struct {
SampleRate int
Sampler *RulesBasedDownstreamSampler
Drop bool
MatchSpan bool
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably need to add this to the documentation + example rule configurations.

Copy link
Contributor

Choose a reason for hiding this comment

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

How would you feel about using a string to determine type? I think Scope works well, and would have either "trace" or "span", with "trace" being default.

@isnotajoke isnotajoke changed the title Experiment new sampler target Add new MatchSpan configuration option to rules-based sampler Apr 27, 2022
@MikeGoldsmith MikeGoldsmith self-assigned this Apr 28, 2022
@MikeGoldsmith MikeGoldsmith added type: enhancement New feature or request version: bump minor A PR that adds behavior, but is backwards-compatible. status: oncall Flagged for awareness from Honeycomb Telemetry Oncall labels Apr 28, 2022
Copy link
Contributor

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Hey @isnotajoke - thank you for putting this together. Sorry for the delay in getting it reviewed.

Overall, I really like what you've done and think it's a great solution. I've left a suggestion for changing the configuration option - let me know you thoughts.

@@ -62,6 +62,7 @@ type RulesBasedSamplerRule struct {
SampleRate int
Sampler *RulesBasedDownstreamSampler
Drop bool
MatchSpan bool
Copy link
Contributor

Choose a reason for hiding this comment

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

How would you feel about using a string to determine type? I think Scope works well, and would have either "trace" or "span", with "trace" being default.

@JamieDanielson JamieDanielson added the status: revision needed Waiting for response to changes requested. label May 9, 2022
@isnotajoke
Copy link
Contributor Author

@MikeGoldsmith makes sense to me. I'll go ahead and make that change.

@isnotajoke
Copy link
Contributor Author

We're planning to test this PR in our infra this week. Will update with any concerns/follow up tweaks after that, and then it should be good for final review.

MikeGoldsmith
MikeGoldsmith previously approved these changes May 10, 2022
Copy link
Contributor

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @isnotajoke.

Yes, please do test and report back any findings. We'll hold back on merging this for your feedback.

sample/rules.go Outdated Show resolved Hide resolved
@MikeGoldsmith MikeGoldsmith added status: info needed Further information is requested. and removed status: revision needed Waiting for response to changes requested. labels May 10, 2022
@JamieDanielson JamieDanielson dismissed MikeGoldsmith’s stale review May 10, 2022 15:42

accidental approval, holding off for further testing!

rules_complete.toml Outdated Show resolved Hide resolved
@MikeGoldsmith MikeGoldsmith changed the title Add new MatchSpan configuration option to rules-based sampler Add rule Scope configuration option to rules-based sampler May 12, 2022
rules_complete.toml Outdated Show resolved Hide resolved
@MikeGoldsmith
Copy link
Contributor

FYI the test failure is coming from config_test - you just need to update the number of rules in the dataset to be 5.

@MikeGoldsmith
Copy link
Contributor

We're planning to test this PR in our infra this week. Will update with any concerns/follow up tweaks after that, and then it should be good for final review.

Hey @isnotajoke - just wanted to check in to see how your testing went?

@isnotajoke
Copy link
Contributor Author

@MikeGoldsmith still ongoing. Should be complete this week.

isnotajoke and others added 2 commits May 18, 2022 16:27
Co-authored-by: Mike Goldsmith <goldsmith.mike@gmail.com>
Co-authored-by: Mike Goldsmith <goldsmith.mike@gmail.com>
@MikeGoldsmith
Copy link
Contributor

Hey @isnotajoke - just wanted to check in to see if you've completed your internal testing?

We're eager to move forward with this feature and value your feedback.

@MikeGoldsmith
Copy link
Contributor

Hey @isnotajoke - I'm going to look to move ahead with this change this week. Let me know if you have any additional feedback.

@isnotajoke
Copy link
Contributor Author

@MikeGoldsmith sorry for the radio silence here. We completed our testing and didn't see any issues. No concerns with moving ahead.

Copy link
Contributor

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Thanks @isnotajoke - we really appreciate your contribution and feedback.

@MikeGoldsmith MikeGoldsmith merged commit 50ca884 into honeycombio:main Jun 10, 2022
@JamieDanielson JamieDanielson added status: blocked and removed status: oncall Flagged for awareness from Honeycomb Telemetry Oncall labels Jun 13, 2022
@robbkidd robbkidd removed status: info needed Further information is requested. status: blocked labels Jun 21, 2022
ghost pushed a commit to opsramp/tracing-proxy that referenced this pull request Jul 5, 2024
…io#440)

We'd like to be able to apply all of the conditions in a rules-based sampler rule to a single span. In other words, we'd like a rule to be considered matched only if all of the conditions in that rule are satisfied by a single span in the trace. This allows us to more accurately make per-service sampling decisions in a dataset written to by multiple services.

Co-authored-by: Mike Goldsmith <goldsmith.mike@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request version: bump minor A PR that adds behavior, but is backwards-compatible.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants