Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit errors in prover API metrics #2890

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions core/node/external_proof_integration_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
})
};
Expand Down
11 changes: 2 additions & 9 deletions core/node/external_proof_integration_api/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Duration>, 2>,
#[metrics(labels = ["method", "status"], buckets = vise::Buckets::LATENCIES)]
pub call_latency: LabeledFamily<(Method, u16), Histogram<Duration>, 2>,
}

#[vise::register]
Expand Down
8 changes: 5 additions & 3 deletions core/node/external_proof_integration_api/src/middleware.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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());
}
}
Loading