Skip to content

Commit 2ac7cc5

Browse files
authored
feat: emit errors in prover API metrics (#2890)
## What ❔ Report reasons of failed calls in prover API metrics. ## Why ❔ To have more observability ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`.
1 parent f848d93 commit 2ac7cc5

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

core/node/external_proof_integration_api/src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ use types::{ExternalProof, ProofGenerationDataResponse};
1919
use zksync_basic_types::L1BatchNumber;
2020

2121
pub use crate::processor::Processor;
22-
use crate::{
23-
metrics::{CallOutcome, Method},
24-
middleware::MetricsMiddleware,
25-
};
22+
use crate::{metrics::Method, middleware::MetricsMiddleware};
2623

2724
/// External API implementation.
2825
#[derive(Debug)]
@@ -37,11 +34,7 @@ impl Api {
3734
axum::middleware::from_fn(move |req: Request, next: Next| async move {
3835
let middleware = MetricsMiddleware::new(method);
3936
let response = next.run(req).await;
40-
let outcome = match response.status().is_success() {
41-
true => CallOutcome::Success,
42-
false => CallOutcome::Failure,
43-
};
44-
middleware.observe(outcome);
37+
middleware.observe(response.status());
4538
response
4639
})
4740
};

core/node/external_proof_integration_api/src/metrics.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ use std::time::Duration;
22

33
use vise::{EncodeLabelSet, EncodeLabelValue, Histogram, LabeledFamily, Metrics};
44

5-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)]
6-
#[metrics(label = "outcome", rename_all = "snake_case")]
7-
pub(crate) enum CallOutcome {
8-
Success,
9-
Failure,
10-
}
11-
125
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)]
136
#[metrics(label = "type", rename_all = "snake_case")]
147
pub(crate) enum Method {
@@ -20,8 +13,8 @@ pub(crate) enum Method {
2013
#[derive(Debug, Metrics)]
2114
#[metrics(prefix = "external_proof_integration_api")]
2215
pub(crate) struct ProofIntegrationApiMetrics {
23-
#[metrics(labels = ["method", "outcome"], buckets = vise::Buckets::LATENCIES)]
24-
pub call_latency: LabeledFamily<(Method, CallOutcome), Histogram<Duration>, 2>,
16+
#[metrics(labels = ["method", "status"], buckets = vise::Buckets::LATENCIES)]
17+
pub call_latency: LabeledFamily<(Method, u16), Histogram<Duration>, 2>,
2518
}
2619

2720
#[vise::register]

core/node/external_proof_integration_api/src/middleware.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use axum::http::StatusCode;
12
use tokio::time::Instant;
23

3-
use crate::metrics::{CallOutcome, Method, METRICS};
4+
use crate::metrics::{Method, METRICS};
45

56
#[derive(Debug)]
67
pub(crate) struct MetricsMiddleware {
@@ -16,7 +17,8 @@ impl MetricsMiddleware {
1617
}
1718
}
1819

19-
pub fn observe(&self, outcome: CallOutcome) {
20-
METRICS.call_latency[&(self.method, outcome)].observe(self.started_at.elapsed());
20+
pub fn observe(&self, status_code: StatusCode) {
21+
METRICS.call_latency[&(self.method, status_code.as_u16())]
22+
.observe(self.started_at.elapsed());
2123
}
2224
}

0 commit comments

Comments
 (0)