diff options
author | Alex Auvolat <alex@adnab.me> | 2022-09-29 15:53:54 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-09-29 15:53:54 +0200 |
commit | ad917ffd3f76316e48b89ff17e2f8a600a269481 (patch) | |
tree | 4411b84a2021eda2e98e38c4549ba00dc71dcef6 /src/util/metrics.rs | |
parent | 497164d78253fa1dd3cdbfc8a5267edaab4040f3 (diff) | |
download | garage-ad917ffd3f76316e48b89ff17e2f8a600a269481.tar.gz garage-ad917ffd3f76316e48b89ff17e2f8a600a269481.zip |
Fix instant substractions that might have panickedfix-time
Diffstat (limited to 'src/util/metrics.rs')
-rw-r--r-- | src/util/metrics.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/util/metrics.rs b/src/util/metrics.rs index 1b05eabe..b882a886 100644 --- a/src/util/metrics.rs +++ b/src/util/metrics.rs @@ -1,4 +1,4 @@ -use std::time::SystemTime; +use std::time::Instant; use futures::{future::BoxFuture, Future, FutureExt}; use rand::Rng; @@ -28,10 +28,12 @@ where attributes: &'a [KeyValue], ) -> BoxFuture<'a, Self::Output> { async move { - let request_start = SystemTime::now(); + let request_start = Instant::now(); let res = self.await; r.record( - request_start.elapsed().map_or(0.0, |d| d.as_secs_f64()), + Instant::now() + .saturating_duration_since(request_start) + .as_secs_f64(), attributes, ); res @@ -41,9 +43,13 @@ where fn bound_record_duration(self, r: &'a BoundValueRecorder<f64>) -> BoxFuture<'a, Self::Output> { async move { - let request_start = SystemTime::now(); + let request_start = Instant::now(); let res = self.await; - r.record(request_start.elapsed().map_or(0.0, |d| d.as_secs_f64())); + r.record( + Instant::now() + .saturating_duration_since(request_start) + .as_secs_f64(), + ); res } .boxed() |