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
ddtrace/tracer: add sample_rate_limit field to startup log. #1230
Conversation
We want to know when the sample rate limit is in effect and what its value is. This commit adds that information to the tracer's startup log.
Added some |
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.
Ok, I cleaned this up a lot from a simple hack.
LMK what you all think.
// true if rules sampling is enabled. If not present it returns math.NaN() and false. | ||
func (rs *rulesSampler) limit() (float64, bool) { | ||
if rs.enabled() { | ||
return float64(rs.limiter.limiter.Limit()), true |
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.
We should be OK without nil
checks here. Other places throughout the rulesSampler code assume these fields are not nil
and all of the constructors populate them.
If we ever changed rulesSampler
to allow nil
members, we would be unlikely to miss this line, since it lives within the rulesSampler
methods.
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.
Looks good! 🎉
@@ -280,12 +280,16 @@ func newRateLimiter() *rateLimiter { | |||
} | |||
} | |||
|
|||
func (rs *rulesSampler) enabled() bool { |
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.
<3
if rs.enabled() { | ||
return float64(rs.limiter.limiter.Limit()), true | ||
} | ||
return math.NaN(), false |
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 works, but to remove complexity, I would probably return -1, false
in this case. Then 284 can just be rs.globalRate >= 0
. Unless the rate can actually be negative, which would be surprising.
Don't have a strong preference though.
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.
-1
would probably be a better choice, however we already use NaN
in various places in the sampler and elsewhere as the canonical "not present" float64 value so I would like to stay consistent.
We want to know when the sample rate limit is in effect and what its value
is. This commit adds that information to the tracer's startup log.