From 9f6153f4855186dfff74ba47949e22e1e552503c Mon Sep 17 00:00:00 2001 From: Tobin Feldman-Fitzthum Date: Mon, 12 Feb 2024 09:02:24 -0600 Subject: [PATCH] chore: Update metrics to 0.22.1 (#90) Pick up fixes for ahash. Metrics has changed the usage of their macros, so update to follow the new format. Signed-off-by: Tobin Feldman-Fitzthum --- Cargo.toml | 2 +- src/lib.rs | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5afc79..c753024 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ async-trait = "0.1" futures-timer = "3.0.2" log = "0.4" thiserror = "1.0" -metrics = "0.21" +metrics = "0.22.1" tracing = { version = "0.1", features = ["attributes"] } tracing-subscriber = "0.3.11" diff --git a/src/lib.rs b/src/lib.rs index b78235e..c22128e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,7 +100,7 @@ use futures_util::select; use futures_util::FutureExt; use futures_util::SinkExt; use futures_util::StreamExt; -use metrics::{decrement_gauge, gauge, histogram, increment_counter, increment_gauge}; +use metrics::{counter, gauge, histogram}; pub use spawn::spawn; use std::fmt; use std::future::Future; @@ -175,8 +175,8 @@ impl Conn { fn close(&self, state: &PoolState) { state.num_open.fetch_sub(1, Ordering::Relaxed); state.max_idle_closed.fetch_add(1, Ordering::Relaxed); - decrement_gauge!(OPEN_CONNECTIONS, 1.0); - increment_counter!(CLOSED_TOTAL); + gauge!(OPEN_CONNECTIONS).decrement(1.0); + counter!(CLOSED_TOTAL).increment(1); } fn expired(&self, timeout: Option) -> bool { @@ -374,7 +374,7 @@ impl Pool { config.max_open as usize }; - gauge!(IDLE_CONNECTIONS, 0.0); + gauge!(IDLE_CONNECTIONS).set(0.0); let (share_config, internal_config) = config.split(); let internals = Mutex::new(PoolInternals { @@ -447,8 +447,8 @@ impl Pool { conn: Some(c), }; - increment_gauge!(ACTIVE_CONNECTIONS, 1.0); - decrement_gauge!(WAIT_COUNT, 1.0); + gauge!(ACTIVE_CONNECTIONS).increment(1.0); + gauge!(WAIT_COUNT).decrement(1.0); Ok(conn) } @@ -488,7 +488,7 @@ impl Pool { async fn get_or_create_conn(&self) -> Result, Error> { self.0.state.wait_count.fetch_add(1, Ordering::Relaxed); - increment_gauge!(WAIT_COUNT, 1.0); + gauge!(WAIT_COUNT).increment(1.0); let wait_start = Instant::now(); let permit = self @@ -503,7 +503,7 @@ impl Pool { let mut internals = self.0.internals.lock().await; internals.wait_duration += wait_start.elapsed(); - histogram!(WAIT_DURATION, wait_start.elapsed()); + histogram!(WAIT_DURATION).record(wait_start.elapsed()); let conn = internals.free_conns.pop(); let internal_config = internals.config.clone(); @@ -512,7 +512,7 @@ impl Pool { if conn.is_some() { let mut conn = conn.unwrap(); if self.validate_conn(internal_config, &mut conn).await { - decrement_gauge!(IDLE_CONNECTIONS, 1.0); + gauge!(IDLE_CONNECTIONS,).decrement(1.0); permit.forget(); return Ok(conn); } else { @@ -534,8 +534,8 @@ impl Pool { match self.0.manager.connect().await { Ok(c) => { self.0.state.num_open.fetch_add(1, Ordering::Relaxed); - increment_gauge!(OPEN_CONNECTIONS, 1.0); - increment_counter!(OPENED_TOTAL); + gauge!(OPEN_CONNECTIONS).increment(1.0); + counter!(OPENED_TOTAL).increment(1); let conn = Conn { raw: Some(c), @@ -616,7 +616,7 @@ fn put_idle_conn( if internals.config.max_idle == 0 || internals.config.max_idle > internals.free_conns.len() as u64 { - increment_gauge!(IDLE_CONNECTIONS, 1.0); + gauge!(IDLE_CONNECTIONS).increment(1.0); internals.free_conns.push(conn); drop(internals); } else { @@ -720,7 +720,7 @@ impl Drop for Connection { let pool = self.pool.take().unwrap(); let conn = self.conn.take().unwrap(); - decrement_gauge!(ACTIVE_CONNECTIONS, 1.0); + gauge!(ACTIVE_CONNECTIONS).decrement(1.0); // FIXME: No clone! pool.clone().0.manager.spawn_task(async move { recycle_conn(&pool.0, conn).await;