Skip to content

Commit

Permalink
added metric
Browse files Browse the repository at this point in the history
  • Loading branch information
pompon0 committed Nov 13, 2024
1 parent 68441fc commit d992ba1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/node/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ thiserror.workspace = true
tracing.workspace = true
tokio.workspace = true
semver.workspace = true
vise.workspace = true

[dev-dependencies]
zksync_node_genesis.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions core/node/consensus/src/en.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use zksync_web3_decl::{

use super::{config, storage::Store, ConsensusConfig, ConsensusSecrets};
use crate::{
metrics::METRICS,
registry,
storage::{self, ConnectionPool},
};
Expand Down Expand Up @@ -367,6 +368,7 @@ impl EN {
) -> ctx::Result<FetchedBlock> {
const RETRY_INTERVAL: time::Duration = time::Duration::seconds(5);
let n = L2BlockNumber(n.0.try_into().context("overflow")?);
METRICS.fetch_block.inc();
loop {
match ctx.wait(self.client.sync_l2_block(n, true)).await? {
Ok(Some(block)) => return Ok(block.try_into()?),
Expand Down
1 change: 1 addition & 0 deletions core/node/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod abi;
mod config;
mod en;
pub mod era;
mod metrics;
mod mn;
mod registry;
mod storage;
Expand Down
13 changes: 13 additions & 0 deletions core/node/consensus/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Consensus related metrics.
#[derive(Debug, vise::Metrics)]
#[metrics(prefix = "zksync_node_consensus")]
pub(crate) struct Metrics {
/// Number of blocks that has been fetched via JSON-RPC.
/// It is used only as a fallback when the p2p syncing is disabled or falling behind.
/// so it shouldn't be increasing under normal circumstances if p2p syncing is enabled.
pub fetch_block: vise::Counter,
}

#[vise::register]
pub(super) static METRICS: vise::Global<Metrics> = vise::Global::new();

0 comments on commit d992ba1

Please sign in to comment.