Remove thread ID from metrics
All checks were successful
/ clippy (push) Successful in 17s
/ tests (push) Successful in 23s
/ check (aarch64-unknown-linux-musl) (push) Successful in 12s
/ check (armv7-unknown-linux-musleabihf) (push) Successful in 12s
/ check (x86_64-unknown-linux-musl) (push) Successful in 11s

This commit is contained in:
asonix 2024-02-12 13:30:48 -06:00
parent efa357a92b
commit 7bc70d83c0

View file

@ -598,8 +598,7 @@ struct MetricsGuard {
impl MetricsGuard {
fn guard(name: &'static str, id: u64) -> Self {
tracing::trace!("Starting {name}-{id}");
metrics::counter!(format!("async-cpupool.{name}.launched"), "id" => id.to_string())
.increment(1);
metrics::counter!(format!("async-cpupool.{name}.launched")).increment(1);
MetricsGuard {
name,
@ -616,8 +615,8 @@ impl MetricsGuard {
impl Drop for MetricsGuard {
fn drop(&mut self) {
metrics::counter!(format!("async-cpupool.{}.closed", self.name), "clean" => (!self.armed).to_string(), "id" => self.id.to_string()).increment(1);
metrics::histogram!(format!("async-cpupool.{}.duration", self.name), "clean" => (!self.armed).to_string(), "id" => self.id.to_string()).record(self.start.elapsed().as_secs_f64());
metrics::counter!(format!("async-cpupool.{}.closed", self.name), "clean" => (!self.armed).to_string()).increment(1);
metrics::histogram!(format!("async-cpupool.{}.duration", self.name), "clean" => (!self.armed).to_string()).record(self.start.elapsed().as_secs_f64());
tracing::trace!("Stopping {}-{}", self.name, self.id);
}
}
@ -634,7 +633,7 @@ fn run(
loop {
match selector::blocking_select(signal.recv_async(), receiver.recv_async()) {
selector::Either::Left(_) | selector::Either::Right(Err(_)) => break,
selector::Either::Right(Ok(send_fn)) => invoke_send_fn(name, id, send_fn),
selector::Either::Right(Ok(send_fn)) => invoke_send_fn(name, send_fn),
}
}
@ -643,17 +642,16 @@ fn run(
drop(closed_tx);
}
fn invoke_send_fn(name: &'static str, id: u64, send_fn: SendFn) {
fn invoke_send_fn(name: &'static str, send_fn: SendFn) {
let start = Instant::now();
metrics::counter!(format!("async-cpupool.{name}.operation.start"), "id" => id.to_string())
.increment(1);
metrics::counter!(format!("async-cpupool.{name}.operation.start")).increment(1);
let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(move || {
(send_fn)();
}));
metrics::counter!(format!("async-cpupool.{name}.operation.end"), "complete" => res.is_ok().to_string(), "id" => id.to_string()).increment(1);
metrics::histogram!(format!("async-cpupool.{name}.operation.duration"), "complete" => res.is_ok().to_string(), "id" => id.to_string()).record(start.elapsed().as_secs_f64());
metrics::counter!(format!("async-cpupool.{name}.operation.end"), "complete" => res.is_ok().to_string()).increment(1);
metrics::histogram!(format!("async-cpupool.{name}.operation.duration"), "complete" => res.is_ok().to_string()).record(start.elapsed().as_secs_f64());
if let Err(e) = res {
tracing::trace!("panic in spawned task: {e:?}");