Skip to content

Commit 4c05a47

Browse files
authored
Merge pull request #101 from aqrln/duration-histogram-guard-consistency
fix: make the timings recorded in wait_duration and histogram consistent
2 parents 9e20219 + a404510 commit 4c05a47

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,7 @@ impl<M: Manager> Pool<M> {
442442

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

445-
internals.wait_duration += wait_guard.elapsed();
446-
drop(wait_guard);
445+
internals.wait_duration += wait_guard.into_elapsed();
447446

448447
let conn = internals.free_conns.pop();
449448
let internal_config = internals.config.clone();

src/metrics_utils.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::time::{Duration, Instant};
1+
use std::{
2+
mem::ManuallyDrop,
3+
time::{Duration, Instant},
4+
};
25

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

@@ -71,8 +74,11 @@ impl DurationHistogramGuard {
7174
}
7275
}
7376

74-
pub(crate) fn elapsed(&self) -> Duration {
75-
self.start.elapsed()
77+
pub(crate) fn into_elapsed(self) -> Duration {
78+
let this = ManuallyDrop::new(self);
79+
let elapsed = this.start.elapsed();
80+
histogram!(this.key).record(elapsed);
81+
elapsed
7682
}
7783
}
7884

0 commit comments

Comments
 (0)