Skip to content

Commit

Permalink
chore: Update metrics to 0.22.1 (#90)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
fitzthum committed Feb 12, 2024
1 parent 38bf403 commit 9f6153f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,8 +175,8 @@ impl<C, E> Conn<C, E> {
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<Duration>) -> bool {
Expand Down Expand Up @@ -374,7 +374,7 @@ impl<M: Manager> Pool<M> {
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 {
Expand Down Expand Up @@ -447,8 +447,8 @@ impl<M: Manager> Pool<M> {
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)
}
Expand Down Expand Up @@ -488,7 +488,7 @@ impl<M: Manager> Pool<M> {

async fn get_or_create_conn(&self) -> Result<Conn<M::Connection, M::Error>, Error<M::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
Expand All @@ -503,7 +503,7 @@ impl<M: Manager> Pool<M> {
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();
Expand All @@ -512,7 +512,7 @@ impl<M: Manager> Pool<M> {
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 {
Expand All @@ -534,8 +534,8 @@ impl<M: Manager> Pool<M> {
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),
Expand Down Expand Up @@ -616,7 +616,7 @@ fn put_idle_conn<M: Manager>(
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 {
Expand Down Expand Up @@ -720,7 +720,7 @@ impl<M: Manager> Drop for Connection<M> {
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;
Expand Down

0 comments on commit 9f6153f

Please sign in to comment.