Skip to content

Commit 923c214

Browse files
committed
Optimize for the common case (100% sampling) by skipping RNG
Use `rand::random_bool` to simplify the sampling logic.
1 parent cc8c7a4 commit 923c214

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

bin/router/src/pipeline/usage_reporting.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ pub fn collect_usage_report(
4949
usage_config: &UsageReportingConfig,
5050
execution_result: &PlanExecutionOutput,
5151
) {
52-
let mut rng = rand::rng();
53-
let sampled = rng.random::<f64>() < usage_config.sample_rate.as_f64();
54-
if !sampled {
52+
let sample_rate = usage_config.sample_rate.as_f64();
53+
if sample_rate < 1.0 && !rand::rng().random_bool(sample_rate) {
5554
return;
5655
}
5756
if client_request_details

0 commit comments

Comments
 (0)