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.
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
[Sampler.AWS] Tested and Updated X-Ray Sampler #1887
[Sampler.AWS] Tested and Updated X-Ray Sampler #1887
Changes from all commits
bacaa3d
460eb76
32c7132
aef3219
4d0f7eb
8564aac
6f9e977
ae6da76
dd9f4c5
a10433c
14fdf9b
81f1122
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall this was done to "sort of" implement immutability of the
ruleApplier
instances (which is generally a good idea). But as we discussed offline this leads to some race conditions. Can you briefly explain either as a comment in the code or in this PR on why we need to break the immutability and mutate the instance now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was made mainly to address one race condition. Basically, with the previous implementation, whenever the RulesCache is periodically updated, it would pull in the list of rules available and if the rule already existed, the Statistics were carried over into a new instance of the rule applier. This caused a race condition. Say the rule had a reservoir of 500 requests/sec and FixedRateSampler with 1/sec after the reservoir is depleted. When creating a new instance of the rule, the constructor creates a new RateLimittingSampler with a reservoir of 1/s and fixedRateSampler with with 1/sec as well since that's in the rule definitio until UpdateTargets is called to set the reservoir according to how the rule is set in cloudwatch (500/s). Between creating a new instance and calling UpdateTargets, if we get a bunch of 200 requests/sec that match the rule, only 2 will be sampled, 1 due to reservoir sampler and the other due to falling back to the fixed rate sampler. If the sampler poling is set to refresh each second, then this will be a problem since it can be the case that the reservoir will mostly only be 1 and not the intended 500. With this change, it will retain the RateLimitingSampler with the correct reservoir while only the rule and it's definition will get updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense and lgtm.
Another thing we could have done to preserve immutability was to also pass in the current reservoir size here and create a new
RateLimitingSampler
with this reservoir size for a newSamplingRuleApplier
instance. Just a suggestion, not required right away.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any unit tests in OpenTelemetry.Sampler.AWS.Tests that need to be updated as part of this change?
I'm not hyper familiar with this code base, but this looks like a potential candidate: https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/main/test/OpenTelemetry.Sampler.AWS.Tests/TestSamplingRuleApplier.cs#L33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good callout. Let me run the unit tests to make sure they are passing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the unit tests and they are passing now.