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

Sample rate config for dogstatsd #739

Merged
merged 6 commits into from
Nov 28, 2023
Merged

Sample rate config for dogstatsd #739

merged 6 commits into from
Nov 28, 2023

Conversation

GeorgeHahn
Copy link
Contributor

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

@GeorgeHahn GeorgeHahn requested a review from a team as a code owner November 20, 2023 19:44
@GeorgeHahn GeorgeHahn force-pushed the george/sampling-config branch from 599f503 to bacbed6 Compare November 20, 2023 19:46
@GeorgeHahn GeorgeHahn force-pushed the george/sampling-config branch from bacbed6 to fdf81e4 Compare November 20, 2023 19:47
type Error = ZeroToOneError;

fn try_from(value: f32) -> Result<Self, Self::Error> {
if (value - 1.0).abs() < f32::EPSILON {
Copy link
Contributor

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.

Copy link
Contributor

@scottopell scottopell left a 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

lading_payload/src/dogstatsd.rs Outdated Show resolved Hide resolved
lading_payload/src/dogstatsd.rs Outdated Show resolved Hide resolved
lading_payload/src/dogstatsd.rs Outdated Show resolved Hide resolved
lading_payload/src/dogstatsd.rs Outdated Show resolved Hide resolved
Comment on lines +95 to +96
let prob: f32 = OpenClosed01.sample(&mut rng);
let sample_rate = if prob < self.sampling_probability {
Copy link
Contributor

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.

Copy link
Contributor

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.)

Copy link
Contributor Author

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.

@GeorgeHahn GeorgeHahn enabled auto-merge (squash) November 28, 2023 08:44
@GeorgeHahn GeorgeHahn merged commit 4f58c0c into main Nov 28, 2023
16 checks passed
@GeorgeHahn GeorgeHahn deleted the george/sampling-config branch November 28, 2023 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants