-
Notifications
You must be signed in to change notification settings - Fork 10
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
Sample rate config for dogstatsd #739
Conversation
599f503
to
bacbed6
Compare
bacbed6
to
fdf81e4
Compare
type Error = ZeroToOneError; | ||
|
||
fn try_from(value: f32) -> Result<Self, Self::Error> { | ||
if (value - 1.0).abs() < f32::EPSILON { |
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.
The value 1.0 is exactly representable in IEEE-754-conformant 32-bit floating-point arithmetic, so the epsilon check here should be unnecessary, though I appreciate the intent because it is usually good practice.
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.
Have some naming/doc suggestions, but functionality looks good
let prob: f32 = OpenClosed01.sample(&mut rng); | ||
let sample_rate = if prob < self.sampling_probability { |
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.
Minor pedantic nit: because floating-point arithmetic quantizes the range [0, 1], omitting zero here does have a small effect on the probability logic that would be material for small values of self.sampling_probability
(e.g., f64::MIN_POSITIVE
). Does this actually matter in practice? Probably not, unless our users are pedantic masochists.
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.
(To be clear, I don't think the range needs to be changed unless we think someone would actually fuzz our system with an outrageously small sampling probability.)
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.
Merged, but I'd still like to understand this better. Would one of the other provided distributions be more correct? https://docs.rs/rand/latest/rand/distributions/struct.Standard.html#floating-point-implementation The Standard
distribution stands out to me, but it seems like it would have the same issue on the opposite side.
Co-authored-by: Scott Opell <[email protected]>
Co-authored-by: Scott Opell <[email protected]>
Co-authored-by: Scott Opell <[email protected]>
What does this PR do?
Add sample rate & sample rate probability configs to the Dogstatsd payload generator.
Motivation
This parameter was previously randomly generated between
0..=1
, and we'd like more control over it.Related issues
SMPTNG-72