aboutsummaryrefslogtreecommitdiff
path: root/src/util/metrics.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-02-22 14:52:41 +0100
committerAlex Auvolat <alex@adnab.me>2022-03-14 10:53:36 +0100
commit2a5609b292de019085f93a79b7b73f7a8341bf51 (patch)
tree7175cbeb1fc4eabcec936ccb8aee2945a92b1c60 /src/util/metrics.rs
parent818daa5c786813fdf50fecb6022e29b18e509b62 (diff)
downloadgarage-2a5609b292de019085f93a79b7b73f7a8341bf51.tar.gz
garage-2a5609b292de019085f93a79b7b73f7a8341bf51.zip
Add metrics to API endpoint
Diffstat (limited to 'src/util/metrics.rs')
-rw-r--r--src/util/metrics.rs29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/util/metrics.rs b/src/util/metrics.rs
index b3b1fc3c..cd5aa182 100644
--- a/src/util/metrics.rs
+++ b/src/util/metrics.rs
@@ -2,26 +2,40 @@ use std::time::SystemTime;
use futures::{future::BoxFuture, Future, FutureExt};
-use opentelemetry::{KeyValue, metrics::*};
+use opentelemetry::{metrics::*, KeyValue};
pub trait RecordDuration<'a>: 'a {
type Output;
- fn record_duration(self, r: &'a ValueRecorder<f64>, attributes: &'a [KeyValue]) -> BoxFuture<'a, Self::Output>;
+ fn record_duration(
+ self,
+ r: &'a ValueRecorder<f64>,
+ attributes: &'a [KeyValue],
+ ) -> BoxFuture<'a, Self::Output>;
fn bound_record_duration(self, r: &'a BoundValueRecorder<f64>) -> BoxFuture<'a, Self::Output>;
}
impl<'a, T, O> RecordDuration<'a> for T
-where T: Future<Output=O> + Send + 'a {
+where
+ T: Future<Output = O> + Send + 'a,
+{
type Output = O;
- fn record_duration(self, r: &'a ValueRecorder<f64>, attributes: &'a [KeyValue]) -> BoxFuture<'a, Self::Output> {
+ fn record_duration(
+ self,
+ r: &'a ValueRecorder<f64>,
+ attributes: &'a [KeyValue],
+ ) -> BoxFuture<'a, Self::Output> {
async move {
let request_start = SystemTime::now();
let res = self.await;
- r.record(request_start.elapsed().map_or(0.0, |d| d.as_secs_f64()), attributes);
+ r.record(
+ request_start.elapsed().map_or(0.0, |d| d.as_secs_f64()),
+ attributes,
+ );
res
- }.boxed()
+ }
+ .boxed()
}
fn bound_record_duration(self, r: &'a BoundValueRecorder<f64>) -> BoxFuture<'a, Self::Output> {
@@ -30,6 +44,7 @@ where T: Future<Output=O> + Send + 'a {
let res = self.await;
r.record(request_start.elapsed().map_or(0.0, |d| d.as_secs_f64()));
res
- }.boxed()
+ }
+ .boxed()
}
}