Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
leecchh committed Oct 15, 2024
1 parent 5aa5eb3 commit 5b6779c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 27 deletions.
44 changes: 24 additions & 20 deletions crates/sui-faucet/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
}
}
}
Expand Down Expand Up @@ -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());
Expand All @@ -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();
}
}
33 changes: 26 additions & 7 deletions crates/sui-faucet/src/metrics_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ impl<Inner> Layer<Inner> for RequestMetricsLayer {
}
}


impl<Inner, Body> Service<Request<Body>> for RequestMetricsService<Inner>
where
Inner: Service<Request<Body>, Response = http::Response<Body>, Error = BoxError> + Clone + Send + 'static,
Inner: Service<Request<Body>, Response = http::Response<Body>, Error = BoxError>
+ Clone
+ Send
+ 'static,
Inner::Future: Send,
Body: Send + 'static,
{
Expand Down Expand Up @@ -109,10 +111,21 @@ impl<Res> Future for RequestMetricsFuture<Res> {

impl MetricsGuard {
fn new(metrics: Arc<RequestMetrics>, 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(),
}
Expand All @@ -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
);
}
}

Expand Down Expand Up @@ -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
);
}
}
}

0 comments on commit 5b6779c

Please sign in to comment.