Helper function to decide whether to sample a statement execution. Returns `true` if the statement should be sampled based on the sample rate. If `reproducible_rng` is `Some`, uses the provided RNG for reproducible sampling (used in tests). If `reproducible_rng` is `None`, uses the thread-local RNG.
(
sample_rate: f64,
reproducible_rng: Option<&mut rand_chacha::ChaCha8Rng>,
)
| 742 | /// If `reproducible_rng` is `Some`, uses the provided RNG for reproducible sampling (used in tests). |
| 743 | /// If `reproducible_rng` is `None`, uses the thread-local RNG. |
| 744 | pub(crate) fn should_sample_statement( |
| 745 | sample_rate: f64, |
| 746 | reproducible_rng: Option<&mut rand_chacha::ChaCha8Rng>, |
| 747 | ) -> bool { |
| 748 | let distribution = Bernoulli::new(sample_rate).unwrap_or_else(|_| { |
| 749 | soft_panic_or_log!("statement_logging_sample_rate is out of range [0, 1]"); |
| 750 | Bernoulli::new(0.0).expect("0.0 is valid for Bernoulli") |
| 751 | }); |
| 752 | if let Some(rng) = reproducible_rng { |
| 753 | distribution.sample(rng) |
| 754 | } else { |
| 755 | distribution.sample(&mut rand::rng()) |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | /// Helper function to serialize statement parameters for logging. |
| 760 | fn serialize_params(params: &Params) -> Vec<Option<String>> { |
no test coverage detected