From 5b6779c790ed7bf53e01cdc8c954a830472c5769 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 15 Oct 2024 14:03:19 -0400 Subject: [PATCH] formatting --- crates/sui-faucet/src/metrics.rs | 44 ++++++++++++++------------ crates/sui-faucet/src/metrics_layer.rs | 33 +++++++++++++++---- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/crates/sui-faucet/src/metrics.rs b/crates/sui-faucet/src/metrics.rs index 9e97c25871532..6a94a28370322 100644 --- a/crates/sui-faucet/src/metrics.rs +++ b/crates/sui-faucet/src/metrics.rs @@ -4,10 +4,9 @@ use mysten_network::metrics::MetricsCallbackProvider; use prometheus::{ - register_histogram_vec_with_registry, - register_int_gauge_vec_with_registry, register_int_gauge_with_registry, - register_int_counter_vec_with_registry, - IntGaugeVec, Registry, IntCounterVec, HistogramVec, IntGauge + register_histogram_vec_with_registry, register_int_counter_vec_with_registry, + register_int_gauge_vec_with_registry, register_int_gauge_with_registry, HistogramVec, + IntCounterVec, IntGauge, IntGaugeVec, Registry, }; use std::time::Duration; use tonic::Code; @@ -47,45 +46,52 @@ impl RequestMetrics { "Total number of requests received in Faucet", &["path"], registry, - ).unwrap(), + ) + .unwrap(), total_requests_succeeded: register_int_counter_vec_with_registry!( "total_requests_succeeded", "Total number of requests processed successfully in Faucet", &["path"], registry, - ).unwrap(), + ) + .unwrap(), total_requests_shed: register_int_counter_vec_with_registry!( "total_requests_shed", "Total number of requests that were dropped because the service was saturated", &["path"], registry, - ).unwrap(), + ) + .unwrap(), total_requests_failed: register_int_counter_vec_with_registry!( "total_requests_failed", "Total number of requests that started but failed with an uncaught error", &["path"], registry, - ).unwrap(), + ) + .unwrap(), total_requests_disconnected: register_int_counter_vec_with_registry!( "total_requests_disconnected", "Total number of requests where the client disconnected before the service \ returned a response", &["path"], registry, - ).unwrap(), + ) + .unwrap(), current_requests_in_flight: register_int_gauge_vec_with_registry!( "current_requests_in_flight", "Current number of requests being processed in Faucet", &["path"], registry, - ).unwrap(), + ) + .unwrap(), process_latency: register_histogram_vec_with_registry!( "process_latency", "Latency of processing a Faucet request", &["path"], LATENCY_SEC_BUCKETS.to_vec(), registry, - ).unwrap(), + ) + .unwrap(), } } } @@ -128,13 +134,7 @@ impl MetricsCallbackProvider for RequestMetrics { .inc(); } - fn on_response( - &self, - path: String, - latency: Duration, - _status: u16, - grpc_status_code: Code, - ) { + fn on_response(&self, path: String, latency: Duration, _status: u16, grpc_status_code: Code) { self.process_latency .with_label_values(&[path.as_str()]) .observe(latency.as_secs_f64()); @@ -159,13 +159,17 @@ impl MetricsCallbackProvider for RequestMetrics { } fn on_start(&self, path: &str) { - self.current_requests_in_flight.with_label_values(&[path]).inc(); + self.current_requests_in_flight + .with_label_values(&[path]) + .inc(); } fn on_drop(&self, path: &str) { self.total_requests_disconnected .with_label_values(&[path]) .inc(); - self.current_requests_in_flight.with_label_values(&[path]).dec(); + self.current_requests_in_flight + .with_label_values(&[path]) + .dec(); } } diff --git a/crates/sui-faucet/src/metrics_layer.rs b/crates/sui-faucet/src/metrics_layer.rs index 88dbbf18347d6..7e7dfe3569af9 100644 --- a/crates/sui-faucet/src/metrics_layer.rs +++ b/crates/sui-faucet/src/metrics_layer.rs @@ -57,10 +57,12 @@ impl Layer for RequestMetricsLayer { } } - impl Service> for RequestMetricsService where - Inner: Service, Response = http::Response, Error = BoxError> + Clone + Send + 'static, + Inner: Service, Response = http::Response, Error = BoxError> + + Clone + + Send + + 'static, Inner::Future: Send, Body: Send + 'static, { @@ -109,10 +111,21 @@ impl Future for RequestMetricsFuture { impl MetricsGuard { fn new(metrics: Arc, path: &str) -> Self { - metrics.total_requests_received.with_label_values(&[path]).inc(); - metrics.current_requests_in_flight.with_label_values(&[path]).inc(); + metrics + .total_requests_received + .with_label_values(&[path]) + .inc(); + metrics + .current_requests_in_flight + .with_label_values(&[path]) + .inc(); MetricsGuard { - timer: Some(metrics.process_latency.with_label_values(&[path]).start_timer()), + timer: Some( + metrics + .process_latency + .with_label_values(&[path]) + .start_timer(), + ), metrics, path: path.to_string(), } @@ -125,7 +138,10 @@ impl MetricsGuard { .total_requests_succeeded .with_label_values(&[&self.path]) .inc(); - info!("Request succeeded for path {} in {:.2}s", self.path, elapsed); + info!( + "Request succeeded for path {} in {:.2}s", + self.path, elapsed + ); } } @@ -179,7 +195,10 @@ impl Drop for MetricsGuard { .total_requests_disconnected .with_label_values(&[&self.path]) .inc(); - info!("Request disconnected for path {} in {:.2}s", self.path, elapsed); + info!( + "Request disconnected for path {} in {:.2}s", + self.path, elapsed + ); } } }