MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / should_sample_statement

Function should_sample_statement

src/adapter/src/statement_logging.rs:744–757  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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.
744pub(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.
760fn serialize_params(params: &Params) -> Vec<Option<String>> {

Callers 2

Calls 1

expectMethod · 0.80

Tested by

no test coverage detected