#[macro_export]
macro_rules! with_chaos {
( $x:expr) => {{
#[cfg(feature = "chaos")]
{
use rand::distributions::{Distribution, Uniform};
use std::env;
use tracing::{debug, warn};
let mut rng = rand::thread_rng();
let chaos_trigger: usize = env::var("SAFE_CHAOS_LEVEL")
.unwrap_or("20".to_string())
.parse()
.unwrap_or(20);
let die = Uniform::from(1..100);
let throw = die.sample(&mut rng);
debug!(
"Threshold for \"chaos\" to occur is < {}, we rolled: {}",
chaos_trigger, throw
);
if throw <= chaos_trigger {
warn!("Chaos!");
$x
}
}
}};
}