From 835dca65372df1fc02412eac23d7bd996ef0f7a9 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Wed, 25 Oct 2023 17:01:27 +0100 Subject: [PATCH] fix warnings --- .cargo/config.toml | 1 - libs/metrics/src/tokio_metrics.rs | 28 ++++++++++++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index bd99b53e9b..cc767a7f68 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -16,7 +16,6 @@ opt-level = 1 # This is only present for local builds, as it will be overridden # by the RUSTDOCFLAGS env var in CI. rustdocflags = ["-Arustdoc::private_intra_doc_links"] -rustflags = ["--cfg=tokio_unstable"] [alias] build_testing = ["build", "--features", "testing"] diff --git a/libs/metrics/src/tokio_metrics.rs b/libs/metrics/src/tokio_metrics.rs index bdee8eba7d..236e6b68b8 100644 --- a/libs/metrics/src/tokio_metrics.rs +++ b/libs/metrics/src/tokio_metrics.rs @@ -1,13 +1,6 @@ -use std::{ - collections::HashMap, - sync::{Arc, Mutex}, -}; +use std::sync::{Arc, Mutex}; -use once_cell::sync::Lazy; -use prometheus::{ - core::Desc, - proto::{self, LabelPair}, -}; +use prometheus::{core::Desc, proto}; use crate::register_internal; @@ -82,7 +75,7 @@ impl TokioCollector { for i in 0..workers { let mut m = f(rt, i); - let mut label_worker = LabelPair::default(); + let mut label_worker = proto::LabelPair::default(); label_worker.set_name("worker".to_owned()); label_worker.set_value(i.to_string()); let mut labels = labels.clone(); @@ -99,7 +92,7 @@ impl TokioCollector { &self, desc: &Desc, typ: proto::MetricType, - f: impl Fn(&tokio::runtime::RuntimeMetrics, Vec, &mut Vec), + f: impl Fn(&tokio::runtime::RuntimeMetrics, Vec, &mut Vec), ) -> proto::MetricFamily { let mut m = proto::MetricFamily::default(); m.set_name(desc.fq_name.clone()); @@ -109,7 +102,7 @@ impl TokioCollector { for (rt, name) in &*self.handles.lock().unwrap() { let rt_metrics = rt.metrics(); - let mut label_name = LabelPair::default(); + let mut label_name = proto::LabelPair::default(); label_name.set_name("runtime".to_owned()); label_name.set_value(name.to_owned()); @@ -123,25 +116,28 @@ impl TokioCollector { } } -static ACTIVE_TASK_COUNT: Lazy = Lazy::new(|| { +#[cfg(tokio_unstable)] +static ACTIVE_TASK_COUNT: once_cell::sync::Lazy = once_cell::sync::Lazy::new(|| { Desc::new( "tokio_active_task_count_total".to_owned(), "the number of active tasks in the runtime".to_owned(), vec!["runtime".to_owned()], - HashMap::default(), + Default::default(), ) .expect("should be a valid description") }); -static WORKER_STEAL_COUNT: Lazy = Lazy::new(|| { +#[cfg(tokio_unstable)] +static WORKER_STEAL_COUNT: once_cell::sync::Lazy = once_cell::sync::Lazy::new(|| { Desc::new( "tokio_worker_steal_count_total".to_owned(), "the number of tasks the given worker thread stole from another worker thread".to_owned(), vec!["runtime".to_owned(), "worker".to_owned()], - HashMap::default(), + Default::default(), ) .expect("should be a valid description") }); +#[allow(unused_mut, clippy::let_and_return)] impl prometheus::core::Collector for TokioCollector { fn desc(&self) -> Vec<&Desc> { let mut metrics = Vec::new();