-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: External prover API metrics, refactoring (#2630)
## What ❔ Added metrics for external proof integration API, refactored code a little bit ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## 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`.
- Loading branch information
1 parent
30edda4
commit c83cca8
Showing
7 changed files
with
115 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod error; | ||
mod metrics; | ||
mod processor; | ||
|
||
use std::{net::SocketAddr, sync::Arc}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::time::Duration; | ||
|
||
use tokio::time::Instant; | ||
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 { | ||
GetLatestProofGenerationData, | ||
GetSpecificProofGenerationData, | ||
VerifyProof, | ||
} | ||
|
||
#[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>, | ||
} | ||
|
||
pub(crate) struct MethodCallGuard { | ||
method_type: Method, | ||
outcome: CallOutcome, | ||
started_at: Instant, | ||
} | ||
|
||
impl MethodCallGuard { | ||
pub(crate) fn new(method_type: Method) -> Self { | ||
MethodCallGuard { | ||
method_type, | ||
outcome: CallOutcome::Failure, | ||
started_at: Instant::now(), | ||
} | ||
} | ||
|
||
pub(crate) fn mark_successful(&mut self) { | ||
self.outcome = CallOutcome::Success; | ||
} | ||
} | ||
|
||
impl Drop for MethodCallGuard { | ||
fn drop(&mut self) { | ||
METRICS.call_latency[&(self.method_type, self.outcome)].observe(self.started_at.elapsed()); | ||
} | ||
} | ||
|
||
#[vise::register] | ||
pub(crate) static METRICS: vise::Global<ProofIntegrationApiMetrics> = vise::Global::new(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters