Skip to content

Commit

Permalink
Merge pull request #101 from aqrln/duration-histogram-guard-consistency
Browse files Browse the repository at this point in the history
fix: make the timings recorded in wait_duration and histogram consistent
  • Loading branch information
SevInf authored Oct 15, 2024
2 parents 9e20219 + a404510 commit 4c05a47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,7 @@ impl<M: Manager> Pool<M> {

let mut internals = self.0.internals.lock().await;

internals.wait_duration += wait_guard.elapsed();
drop(wait_guard);
internals.wait_duration += wait_guard.into_elapsed();

let conn = internals.free_conns.pop();
let internal_config = internals.config.clone();
Expand Down
12 changes: 9 additions & 3 deletions src/metrics_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::time::{Duration, Instant};
use std::{
mem::ManuallyDrop,
time::{Duration, Instant},
};

use metrics::{describe_counter, describe_gauge, describe_histogram, gauge, histogram};

Expand Down Expand Up @@ -71,8 +74,11 @@ impl DurationHistogramGuard {
}
}

pub(crate) fn elapsed(&self) -> Duration {
self.start.elapsed()
pub(crate) fn into_elapsed(self) -> Duration {
let this = ManuallyDrop::new(self);
let elapsed = this.start.elapsed();
histogram!(this.key).record(elapsed);
elapsed
}
}

Expand Down

0 comments on commit 4c05a47

Please sign in to comment.