Skip to content

Commit 2e2b4a0

Browse files
committed
Add derived metrics test
1 parent a07c6dc commit 2e2b4a0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/auto_metrics.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ cfg_rt! {
3535
let recorder = Arc::new(metrics_util::debugging::DebuggingRecorder::new());
3636
metrics::set_global_recorder(recorder.clone()).unwrap();
3737
tokio::task::spawn(RuntimeMetricsReporterBuilder::default().with_interval(Duration::from_millis(100)).describe_and_run());
38+
3839
let mut done = false;
3940
for _ in 0..1000 {
4041
tokio::time::sleep(Duration::from_millis(10)).await;
@@ -55,6 +56,7 @@ cfg_rt! {
5556
}
5657
}
5758
assert!(done, "metric not found");
59+
5860
tokio::task::spawn(async {
5961
// spawn a thread with a long poll time, let's see we can find it
6062
std::thread::sleep(std::time::Duration::from_millis(100));
@@ -98,6 +100,22 @@ cfg_rt! {
98100
// check that we found exactly 1 poll in the 100ms region
99101
assert_eq!(long_polls_found, 1);
100102

103+
{
104+
let snapshot = recorder.snapshotter().snapshot().into_vec();
105+
if let Some(metric) = snapshot.iter().find(|metrics| {
106+
metrics.0.key().name() == "mean_polls_per_park"
107+
}) {
108+
match metric {
109+
(_, Some(metrics::Unit::Percent), Some(s), DebugValue::Gauge(ratio))
110+
if &s[..] == "The ratio of the [`RuntimeMetrics::total_polls_count`] to the [`RuntimeMetrics::total_noop_count`]." =>
111+
{
112+
assert!(ratio.0 > 0.0);
113+
}
114+
_ => panic!("bad {metric:?}"),
115+
}
116+
}
117+
}
118+
101119
// test task metrics
102120
let task_monitor = TaskMonitor::new();
103121
tokio::task::spawn(
@@ -131,6 +149,22 @@ cfg_rt! {
131149
}
132150
}
133151
assert!(done, "metric not found");
152+
153+
{
154+
let snapshot = recorder.snapshotter().snapshot().into_vec();
155+
if let Some(metric) = snapshot.iter().find(|metrics| {
156+
metrics.0.key().name() == "mean_first_poll_delay"
157+
}) {
158+
match metric {
159+
(_, Some(metrics::Unit::Percent), Some(s), DebugValue::Gauge(ratio))
160+
if &s[..] == "/// The mean duration elapsed between the instant tasks are instrumented, and the instant they are first polled." =>
161+
{
162+
assert!(ratio.0 > 0.0);
163+
}
164+
_ => panic!("bad {metric:?}"),
165+
}
166+
}
167+
}
134168
});
135169
}
136170
}

0 commit comments

Comments
 (0)