diff --git a/core/node/external_proof_integration_api/src/lib.rs b/core/node/external_proof_integration_api/src/lib.rs index 4355896e2a2e..d152ea265cb8 100644 --- a/core/node/external_proof_integration_api/src/lib.rs +++ b/core/node/external_proof_integration_api/src/lib.rs @@ -19,10 +19,7 @@ use types::{ExternalProof, ProofGenerationDataResponse}; use zksync_basic_types::L1BatchNumber; pub use crate::processor::Processor; -use crate::{ - metrics::{CallOutcome, Method}, - middleware::MetricsMiddleware, -}; +use crate::{metrics::Method, middleware::MetricsMiddleware}; /// External API implementation. #[derive(Debug)] @@ -37,11 +34,7 @@ impl Api { axum::middleware::from_fn(move |req: Request, next: Next| async move { let middleware = MetricsMiddleware::new(method); let response = next.run(req).await; - let outcome = match response.status().is_success() { - true => CallOutcome::Success, - false => CallOutcome::Failure, - }; - middleware.observe(outcome); + middleware.observe(response.status()); response }) }; diff --git a/core/node/external_proof_integration_api/src/metrics.rs b/core/node/external_proof_integration_api/src/metrics.rs index f43b49b7b1c0..6b909a278d62 100644 --- a/core/node/external_proof_integration_api/src/metrics.rs +++ b/core/node/external_proof_integration_api/src/metrics.rs @@ -2,13 +2,6 @@ use std::time::Duration; use vise::{EncodeLabelSet, EncodeLabelValue, Histogram, LabeledFamily, Metrics}; -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)] -#[metrics(label = "outcome", rename_all = "snake_case")] -pub(crate) enum CallOutcome { - Success, - Failure, -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)] #[metrics(label = "type", rename_all = "snake_case")] pub(crate) enum Method { @@ -20,8 +13,8 @@ pub(crate) enum Method { #[derive(Debug, Metrics)] #[metrics(prefix = "external_proof_integration_api")] pub(crate) struct ProofIntegrationApiMetrics { - #[metrics(labels = ["method", "outcome"], buckets = vise::Buckets::LATENCIES)] - pub call_latency: LabeledFamily<(Method, CallOutcome), Histogram, 2>, + #[metrics(labels = ["method", "status"], buckets = vise::Buckets::LATENCIES)] + pub call_latency: LabeledFamily<(Method, u16), Histogram, 2>, } #[vise::register] diff --git a/core/node/external_proof_integration_api/src/middleware.rs b/core/node/external_proof_integration_api/src/middleware.rs index 1dc6aefe9171..ebd4ef5bfb09 100644 --- a/core/node/external_proof_integration_api/src/middleware.rs +++ b/core/node/external_proof_integration_api/src/middleware.rs @@ -1,6 +1,7 @@ +use axum::http::StatusCode; use tokio::time::Instant; -use crate::metrics::{CallOutcome, Method, METRICS}; +use crate::metrics::{Method, METRICS}; #[derive(Debug)] pub(crate) struct MetricsMiddleware { @@ -16,7 +17,8 @@ impl MetricsMiddleware { } } - pub fn observe(&self, outcome: CallOutcome) { - METRICS.call_latency[&(self.method, outcome)].observe(self.started_at.elapsed()); + pub fn observe(&self, status_code: StatusCode) { + METRICS.call_latency[&(self.method, status_code.as_u16())] + .observe(self.started_at.elapsed()); } }