diff --git a/crates/metrics/Cargo.toml b/crates/metrics/Cargo.toml index 09bad3e..118c9c4 100644 --- a/crates/metrics/Cargo.toml +++ b/crates/metrics/Cargo.toml @@ -8,7 +8,7 @@ default = ["future"] future = ["dep:pin-project"] [dependencies] -metrics = "0.23" +backend = { package = "metrics", version = "0.23" } smallvec = "1" parking_lot = "0.12" enum-ordinalize = "4.3" diff --git a/crates/metrics/src/future.rs b/crates/metrics/src/future.rs index 2eb14ac..6abae7e 100644 --- a/crates/metrics/src/future.rs +++ b/crates/metrics/src/future.rs @@ -25,7 +25,7 @@ use { sealed::{Attrs, Metric}, Lazy, }, - metrics::{Counter, Gauge, Histogram}, + backend::{counter, gauge, histogram, Counter, Gauge, Histogram, Label}, std::{ future::Future, pin::Pin, @@ -67,19 +67,19 @@ pub struct Metrics { impl Metric for Metrics { fn register(attrs: &Attrs) -> Self { let mut labels = attrs.labels(); - let name = metrics::Label::from_static_parts("future_name", attrs.name()); + let name = Label::from_static_parts("future_name", attrs.name()); labels.push(name); Self { - duration: metrics::histogram!(name::FUTURE_DURATION, labels.iter()), - cancelled_duration: metrics::histogram!(name::FUTURE_CANCELLED_DURATION, labels.iter()), - created: metrics::counter!(name::FUTURES_CREATED, labels.iter()), - started: metrics::counter!(name::FUTURES_STARTED, labels.iter()), - finished: metrics::counter!(name::FUTURES_FINISHED, labels.iter()), - cancelled: metrics::counter!(name::FUTURES_CANCELLED, labels.iter()), - poll_duration: metrics::histogram!(name::FUTURE_POLL_DURATION, labels.iter()), - poll_duration_max: metrics::gauge!(name::FUTURE_POLL_DURATION_MAX, labels.iter()), - polls: metrics::counter!(name::FUTURE_POLLS, labels.iter()), + duration: histogram!(name::FUTURE_DURATION, labels.iter()), + cancelled_duration: histogram!(name::FUTURE_CANCELLED_DURATION, labels.iter()), + created: counter!(name::FUTURES_CREATED, labels.iter()), + started: counter!(name::FUTURES_STARTED, labels.iter()), + finished: counter!(name::FUTURES_FINISHED, labels.iter()), + cancelled: counter!(name::FUTURES_CANCELLED, labels.iter()), + poll_duration: histogram!(name::FUTURE_POLL_DURATION, labels.iter()), + poll_duration_max: gauge!(name::FUTURE_POLL_DURATION_MAX, labels.iter()), + polls: counter!(name::FUTURE_POLLS, labels.iter()), } } } diff --git a/crates/metrics/src/label.rs b/crates/metrics/src/label.rs index 6888c4c..bdff0eb 100644 --- a/crates/metrics/src/label.rs +++ b/crates/metrics/src/label.rs @@ -4,13 +4,14 @@ use { Metric, }, arc_swap::ArcSwap, + backend::Label, enum_ordinalize::Ordinalize, parking_lot::Mutex, smallvec::SmallVec, std::{borrow::Borrow, collections::HashMap, sync::Arc}, }; -pub type DynamicLabels = SmallVec<[metrics::Label; 4]>; +pub type DynamicLabels = SmallVec<[Label; 4]>; pub type StaticLabels = &'static [(&'static str, &'static str)]; pub type Labeled = WithLabel; @@ -92,7 +93,7 @@ where { fn register(attrs: &Attrs) -> Self { let metrics = L::VARIANTS.iter().map(|l| { - let label = metrics::Label::from_static_parts(L::NAME, l.as_str()); + let label = Label::from_static_parts(L::NAME, l.as_str()); (*l, M::register(&attrs.with_label(label))) }); @@ -170,8 +171,8 @@ where fn register(attrs: &Attrs) -> Self { let name = const { resolve_label_name::() }; - let f = metrics::Label::from_static_parts(name, "false"); - let t = metrics::Label::from_static_parts(name, "true"); + let f = Label::from_static_parts(name, "false"); + let t = Label::from_static_parts(name, "true"); Self { collection: ( @@ -302,7 +303,7 @@ where let mut inner_clone: HashMap<_, _> = (**inner).clone(); let name = const { resolve_label_name::() }; - let label_ = metrics::Label::new(name, label.to_owned().to_string()); + let label_ = Label::new(name, label.to_owned().to_string()); // Insert the new `Metric`. // diff --git a/crates/metrics/src/lazy.rs b/crates/metrics/src/lazy.rs index 04b264a..7831fcf 100644 --- a/crates/metrics/src/lazy.rs +++ b/crates/metrics/src/lazy.rs @@ -6,7 +6,7 @@ use { Metric, StaticAttrs, }, - metrics::{Counter, Gauge, Histogram, IntoF64}, + backend::{Counter, Gauge, Histogram, IntoF64}, std::sync::OnceLock, }; diff --git a/crates/metrics/src/lib.rs b/crates/metrics/src/lib.rs index cab2ebd..d75d5b9 100644 --- a/crates/metrics/src/lib.rs +++ b/crates/metrics/src/lib.rs @@ -79,14 +79,14 @@ //! ``` pub use { + backend, enum_ordinalize, label::{label_name, BoolLabel, EnumLabel, LabelName, StringLabel, WithLabel}, lazy::Lazy, - metrics as backend, }; use { + backend::{Counter, Gauge, Histogram, IntoF64, Label}, label::{DynamicLabels, Labeled, Labeled2, Labeled3, Labeled4, StaticLabels}, - metrics::{Counter, Gauge, Histogram, IntoF64}, sealed::{Attrs, Decrement, Execute, Increment, Metric, Record, Set}, }; @@ -165,11 +165,11 @@ impl Attrs { fn labels(&self) -> DynamicLabels { let mut labels = self.dynamic.labels.clone(); let static_ = self.static_.labels.iter(); - labels.extend(static_.map(|(k, v)| metrics::Label::from_static_parts(k, v))); + labels.extend(static_.map(|(k, v)| Label::from_static_parts(k, v))); labels } - fn with_label(&self, label: metrics::Label) -> Self { + fn with_label(&self, label: Label) -> Self { let mut this = self.clone(); this.dynamic.labels.push(label); this @@ -218,9 +218,9 @@ pub type LabeledCounter4 = Labeled4; impl Metric for Counter { fn register(attrs: &Attrs) -> Self { - let counter = metrics::counter!(attrs.name(), attrs.labels().iter()); + let counter = backend::counter!(attrs.name(), attrs.labels().iter()); if let Some(desc) = attrs.description() { - metrics::describe_counter!(attrs.name(), desc); + backend::describe_counter!(attrs.name(), desc); } counter } @@ -242,9 +242,9 @@ pub type LabeledGauge4 = Labeled4; impl Metric for Gauge { fn register(attrs: &Attrs) -> Self { - let gauge = metrics::gauge!(attrs.name(), attrs.labels().iter()); + let gauge = backend::gauge!(attrs.name(), attrs.labels().iter()); if let Some(desc) = attrs.description() { - metrics::describe_gauge!(attrs.name(), desc); + backend::describe_gauge!(attrs.name(), desc); } gauge } @@ -284,9 +284,9 @@ pub type LabeledHistogram4 = Labeled4; impl Metric for Histogram { fn register(attrs: &Attrs) -> Self { - let histogram = metrics::histogram!(attrs.name(), attrs.labels().iter()); + let histogram = backend::histogram!(attrs.name(), attrs.labels().iter()); if let Some(desc) = attrs.description() { - metrics::describe_histogram!(attrs.name(), desc); + backend::describe_histogram!(attrs.name(), desc); } histogram }