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

Update to rand 0.9 #556

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ quanta = { version = "0.12", default-features = false }
quickcheck = { version = "1", default-features = false }
quickcheck_macros = { version = "1", default-features = false }
radix_trie = { version = "0.2", default-features = false }
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] }
rand_distr = { version = "0.4", default-features = false }
rand = { version = "0.9", default-features = false, features = [ "thread_rng" ] }
rand_xoshiro = { version = "0.7", default-features = false }
ratatui = { version = "0.28", default-features = false }
sketches-ddsketch = { version = "0.3", default-features = false }
thiserror = { version = "1", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion metrics-exporter-dogstatsd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ tracing = { workspace = true }
[dev-dependencies]
proptest = { workspace = true }
rand = { workspace = true }
rand_xoshiro = { version = "0.6", default-features = false }
rand_xoshiro = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["fmt"] }
8 changes: 4 additions & 4 deletions metrics-exporter-dogstatsd/examples/dogstatsd_synchronous.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use metrics::{counter, gauge, histogram};
use metrics_exporter_dogstatsd::DogStatsDBuilder;
use rand::{thread_rng, Rng, SeedableRng as _};
use rand::{Rng, SeedableRng};
use rand_xoshiro::Xoshiro256StarStar;

fn main() {
Expand All @@ -18,14 +18,14 @@ fn main() {
let server_loops = counter!("tcp_server_loops", "system" => "foo");
let server_loops_delta_secs = histogram!("tcp_server_loop_delta_secs", "system" => "foo");

let mut rng = Xoshiro256StarStar::from_rng(thread_rng()).unwrap();
let mut rng = Xoshiro256StarStar::try_from_rng(&mut rand::rng()).unwrap();

// Loop over and over, pretending to do some work.
loop {
server_loops.increment(1);
server_loops_delta_secs.record(rng.gen_range(0.0..1.0));
server_loops_delta_secs.record(rng.random_range(0.0..1.0));

let increment_gauge = thread_rng().gen_bool(0.75);
let increment_gauge = rand::random_bool(0.75);
let gauge = gauge!("lucky_iterations");
if increment_gauge {
gauge.increment(1.0);
Expand Down
1 change: 1 addition & 0 deletions metrics-exporter-dogstatsd/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ mod tests {
);
}

#[cfg(target_os = "linux")]
mod linux {
use super::*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use metrics_exporter_prometheus::PrometheusBuilder;
use metrics_util::MetricKindMask;

use quanta::Clock;
use rand::{thread_rng, Rng};

fn main() {
tracing_subscriber::fmt::init();
Expand Down Expand Up @@ -59,7 +58,7 @@ fn main() {
histogram!("tcp_server_loop_delta_secs", "system" => "foo").record(delta);
}

let increment_gauge = thread_rng().gen_bool(0.75);
let increment_gauge = rand::random_bool(0.75);
let gauge = gauge!("lucky_iterations");
if increment_gauge {
gauge.increment(1.0);
Expand Down
3 changes: 1 addition & 2 deletions metrics-exporter-prometheus/examples/prometheus_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use metrics_exporter_prometheus::PrometheusBuilder;
use metrics_util::MetricKindMask;

use quanta::Clock;
use rand::{thread_rng, Rng};

fn main() {
tracing_subscriber::fmt::init();
Expand Down Expand Up @@ -47,7 +46,7 @@ fn main() {
histogram!("tcp_server_loop_delta_secs", "system" => "foo").record(delta);
}

let increment_gauge = thread_rng().gen_bool(0.75);
let increment_gauge = rand::random_bool(0.75);
let gauge = gauge!("lucky_iterations");
if increment_gauge {
gauge.increment(1.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use metrics_exporter_prometheus::PrometheusBuilder;
use metrics_util::MetricKindMask;

use quanta::Clock;
use rand::{thread_rng, Rng};

fn main() {
tracing_subscriber::fmt::init();
Expand Down Expand Up @@ -47,7 +46,7 @@ fn main() {
histogram!("tcp_server_loop_delta_secs", "system" => "foo").record(delta);
}

let increment_gauge = thread_rng().gen_bool(0.75);
let increment_gauge = rand::random_bool(0.75);
let gauge = gauge!("lucky_iterations");
if increment_gauge {
gauge.increment(1.0);
Expand Down
5 changes: 2 additions & 3 deletions metrics-exporter-tcp/examples/tcp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use metrics::{counter, describe_histogram, gauge, histogram, Unit};
use metrics_exporter_tcp::TcpBuilder;

use quanta::Clock;
use rand::{thread_rng, Rng};

fn main() {
tracing_subscriber::fmt::init();
Expand All @@ -30,7 +29,7 @@ fn main() {
histogram!("tcp_server_loop_delta_secs", "system" => "foo").record(delta);
}

let increment_gauge = thread_rng().gen_bool(0.75);
let increment_gauge = rand::random_bool(0.75);
let gauge = gauge!("lucky_iterations");
if increment_gauge {
gauge.increment(1.0);
Expand All @@ -40,7 +39,7 @@ fn main() {

last = Some(clock.now());

let sleep_time = thread_rng().gen_range(250..750);
let sleep_time = rand::random_range(250..750);

thread::sleep(Duration::from_millis(sleep_time));
}
Expand Down
5 changes: 2 additions & 3 deletions metrics-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ metrics = { version = "^0.24", path = "../metrics" }
ordered-float = { workspace = true, optional = true }
quanta = { workspace = true, optional = true }
rand = { workspace = true, optional = true }
rand_xoshiro = { version = "0.6", default-features = false, optional = true }
rand_xoshiro = { workspace = true, default-features = false, optional = true }
radix_trie = { workspace = true, optional = true }
sketches-ddsketch = { workspace = true, optional = true }

Expand All @@ -76,8 +76,7 @@ predicates-core = { workspace = true }
predicates-tree = { workspace = true }
quickcheck = { workspace = true }
quickcheck_macros = { workspace = true }
rand = { workspace = true, features = ["small_rng"] }
rand_distr = { workspace = true }
rand = { workspace = true }
sketches-ddsketch = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["fmt", "ansi"] }
Expand Down
6 changes: 3 additions & 3 deletions metrics-util/examples/bucket-crusher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::time::{Duration, Instant};

use getopts::Options;
use metrics_util::storage::AtomicBucket;
use rand::{thread_rng, Rng};
use rand::Rng;
use tracing::{debug, error, info};

const COUNTER_LOOP: usize = 1024;
Expand Down Expand Up @@ -102,7 +102,7 @@ fn run_producer(
) {
let mut counter_local = 0;
let mut total_local = 0;
let mut rand = thread_rng();
let mut rand = rand::rng();

loop {
// Every COUNTER_LOOP iterations, do housekeeping.
Expand All @@ -120,7 +120,7 @@ fn run_producer(

// Significantly speeds things up if we just push a bunch of values in a tight loop,
// which should really exercise the core bucket push logic more efficiently.
let value = rand.gen_range(0..1024);
let value = rand.random_range(0..1024);
let n = 32;
for _ in 0..n {
bucket.push(value);
Expand Down
6 changes: 3 additions & 3 deletions metrics-util/examples/segqueue-torture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::time::Duration;

use crossbeam_queue::SegQueue;
use getopts::Options;
use rand::{thread_rng, Rng};
use rand::Rng;
use tracing::{error, info};

const COUNTER_LOOP: usize = 1024;
Expand Down Expand Up @@ -102,7 +102,7 @@ fn run_producer(
) {
let mut counter_local = 0;
let mut total_local = 0;
let mut rand = thread_rng();
let mut rand = rand::rng();

loop {
// Every COUNTER_LOOP iterations, do housekeeping.
Expand All @@ -118,7 +118,7 @@ fn run_producer(
}
}

let value = rand.gen_range(0..1024);
let value = rand.random_range(0..1024);
queue.push(value);

total_local += value;
Expand Down
6 changes: 3 additions & 3 deletions metrics-util/src/storage/reservoir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use std::{
},
};

use rand::{rngs::OsRng, Rng as _, SeedableRng as _};
use rand::{rngs::OsRng, Rng, SeedableRng};
use rand_xoshiro::Xoshiro256StarStar;

thread_local! {
static FAST_RNG: UnsafeCell<Xoshiro256StarStar> = {
UnsafeCell::new(Xoshiro256StarStar::from_rng(OsRng).unwrap())
UnsafeCell::new(Xoshiro256StarStar::try_from_rng(&mut OsRng).unwrap())
};
}

Expand All @@ -25,7 +25,7 @@ fn fastrand(upper: usize) -> usize {
// SAFETY: We know it's safe to take a mutable reference since we're getting a pointer to a thread-local value,
// and the reference never outlives the closure executing on this thread.
let rng = unsafe { &mut *rng.get() };
rng.gen_range(0..upper)
rng.random_range(0..upper)
})
}

Expand Down
11 changes: 5 additions & 6 deletions metrics-util/src/storage/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ mod tests {
use ndarray_stats::{interpolate::Linear, QuantileExt};
use noisy_float::types::n64;
use ordered_float::NotNan;
use rand::{distributions::Distribution, thread_rng};
use rand_distr::Uniform;
use rand::distr::{Distribution, Uniform};

#[test]
fn test_basics() {
Expand Down Expand Up @@ -248,8 +247,8 @@ mod tests {
let max_bins = 32_768;
let min_value = 1.0e-9;

let mut rng = thread_rng();
let dist = Uniform::new(0.0, 100.0);
let mut rng = rand::rng();
let dist = Uniform::new(0.0, 100.0).unwrap();

let mut summary = Summary::new(alpha, max_bins, min_value);
let mut uniform = Vec::new();
Expand Down Expand Up @@ -283,8 +282,8 @@ mod tests {
let max_bins = 65_536;
let min_value = 1.0e-9;

let mut rng = thread_rng();
let dist = Uniform::new(-100.0, 100.0);
let mut rng = rand::rng();
let dist = Uniform::new(-100.0, 100.0).unwrap();

let mut summary = Summary::new(alpha, max_bins, min_value);
let mut uniform = Vec::new();
Expand Down
5 changes: 2 additions & 3 deletions metrics/benches/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use criterion::Criterion;
use metrics::{
counter, Counter, Gauge, Histogram, Key, KeyName, Metadata, Recorder, SharedString, Unit,
};
use rand::{thread_rng, Rng};

#[derive(Debug)]
struct TestRecorder;
Expand Down Expand Up @@ -53,7 +52,7 @@ fn macro_benchmark(c: &mut Criterion) {
group.bench_function("global_initialized/with_dynamic_labels", |b| {
let _ = metrics::set_global_recorder(TestRecorder);

let label_val = thread_rng().gen::<u64>().to_string();
let label_val = rand::random::<u64>().to_string();
b.iter(move || {
counter!("counter_bench", "request" => "http", "uid" => label_val.clone())
.increment(42);
Expand All @@ -75,7 +74,7 @@ fn macro_benchmark(c: &mut Criterion) {
});
group.bench_function("local_initialized/with_dynamic_labels", |b| {
metrics::with_local_recorder(&TestRecorder, || {
let label_val = thread_rng().gen::<u64>().to_string();
let label_val = rand::random::<u64>().to_string();
b.iter(move || {
counter!("counter_bench", "request" => "http", "uid" => label_val.clone())
.increment(42);
Expand Down
3 changes: 1 addition & 2 deletions tooling/metrics-histogram-fidelity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ rust-version = "1.56.1"

[dependencies]
metrics-util = { path = "../../metrics-util" }
rand = { version = "0.7", features = ["small_rng"] }
rand_distr = "0.3"
rand = "0.9"
ndarray = "0.13"
ndarray-stats = "0.3"
noisy_float = "0.1"
Expand Down
9 changes: 4 additions & 5 deletions tooling/metrics-histogram-fidelity/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use metrics_util::Summary;
use metrics_util::storage::Summary;
use ndarray::{Array1, Axis};
use ndarray_stats::{interpolate::Linear, QuantileExt};
use noisy_float::types::n64;
use ordered_float::NotNan;
use rand::{distributions::Distribution, thread_rng};
use rand_distr::Uniform;
use rand::distr::{Distribution, Uniform};
use std::fs::File;
use std::io;
use std::io::prelude::*;
Expand All @@ -15,8 +14,8 @@ fn main() -> io::Result<()> {
// Generates a consistent set of inputs, and uses them to feed to a reference DDSketch
// implementation so we can get the quantiles produced for our comparison.
println!("generating uniform distribution...");
let mut rng = thread_rng();
let dist = Uniform::new(-25.0, 75.0);
let mut rng = rand::rng();
let dist = Uniform::new(-25.0, 75.0).unwrap();

let mut summary = Summary::new(0.0001, 32768, 1.0e-9);
let mut uniform = Vec::new();
Expand Down