-
Notifications
You must be signed in to change notification settings - Fork 584
feat(opentelemetry-sampler-aws-xray): Add Rate Limiter and Sampling Targets Poller Logic #2924
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
base: main
Are you sure you want to change the base?
Conversation
…argets Poller Logic
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2924 +/- ##
==========================================
+ Coverage 88.99% 89.04% +0.04%
==========================================
Files 188 188
Lines 9181 9181
Branches 1889 1889
==========================================
+ Hits 8171 8175 +4
+ Misses 1010 1006 -4 🚀 New features to boost your workflow:
|
|
||
import { SamplingRuleApplier } from './sampling-rule-applier'; | ||
import { PACKAGE_NAME } from './version'; |
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.
How this file is generated? I tried 'npm run setup:dev' and 'npm run compile', none of them generate this file and that is causing build failure.
|
||
constructor() { | ||
this.fixedRateSampler = new TraceIdRatioBasedSampler(0.05); | ||
this.rateLimitingSampler = new RateLimitingSampler(1); |
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.
Consider allowing these values to be passed as params with default value. That will it more reusable.
this.rateLimitingSampler = new RateLimitingSampler(1); | |
constructor(rateLimit: number = 1, ratio: number = 0.05) { | |
this.fixedRateSampler = new TraceIdRatioBasedSampler(ratio); | |
this.rateLimitingSampler = new RateLimitingSampler(rateLimit); | |
} |
if ( | ||
sampler.shouldSample( | ||
context.active(), | ||
'1234', |
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.
Is it true that we intentionally use an invalid trace ID to avoid being sampled by the Fixed Rate Sampler? If that is the case, can we use an const variable instead of the magic string? Or maybe a comment here. That will make it easier to understand the purpose of the UT.
'1234', | |
const InvaidTraceIdToAvoidFixedRateSampler = '1234', |
|
||
const quotaPerMillis: number = this.quota / 1000.0; | ||
|
||
// assume divide by zero not possible |
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.
How about combine line 45 and 48: = (cost * 1000) / quota; so you don't need this comment.
} | ||
|
||
public toString(): string { | ||
return `RateLimitingSampler{rate limiting sampling with sampling config of ${this.quota} req/sec and 0% of additional requests}`; |
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.
nit: do we need 'and 0% of additional requests' in the context of rate limiting?
@@ -45,7 +45,7 @@ export class AWSXRaySamplingClient { | |||
this.makeSamplingRequest<GetSamplingTargetsResponse>( | |||
this.samplingTargetsEndpoint, | |||
callback, | |||
this.samplerDiag.debug, | |||
this.samplerDiag.debug.bind(this.samplerDiag), |
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.
nit. lambda is modern, more readable.
(message: string, ...args: unknown[]) => this.samplerDiag.debug(message, ...args)
targetDocuments: TargetMap, | ||
lastRuleModification: number | ||
): [boolean, number] { | ||
let minPollingInteral: number | undefined = undefined; |
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.
typo: do you mean 'interval'?
Which problem is this PR solving?
Short description of the changes
This PR is a followup to #2824
SamplingRuleApplier
.SamplingRuleApplier
will sample the requests.GetSamplingTargets
call to determine the next targetRateLimitingSampler
(applied before the fixed rate sampler) to be used in each rule applier.FallbackSampler
is updated to be a combination of above samplers to sample1 req/sec
and5%
of additional requests in that second.This PR's implementation was tested against X-Ray's Centralized Sampling Integration tests.