diff options
author | Alex <alex@adnab.me> | 2022-10-02 16:41:06 +0200 |
---|---|---|
committer | Alex <alex@adnab.me> | 2022-10-02 16:41:06 +0200 |
commit | a096ced35562bd0a8877a1ee2f755be1edafe343 (patch) | |
tree | b2a427054a30f23d512d63d895a4ddd8a98f46e2 /src/util/metrics.rs | |
parent | e21b672c96da3c6d01a5ef964aa0ad7a38f8e74c (diff) | |
parent | ad917ffd3f76316e48b89ff17e2f8a600a269481 (diff) | |
download | garage-a096ced35562bd0a8877a1ee2f755be1edafe343.tar.gz garage-a096ced35562bd0a8877a1ee2f755be1edafe343.zip |
Merge pull request 'Fix instant substractions that might have panicked' (#398) from fix-time into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/398
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() |