Skip to content

Commit

Permalink
add label to transaction inclusion metric; refine buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanBrodetski committed Feb 16, 2024
1 parent 6f715c8 commit 79716f4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/lib/zksync_core/src/api_server/web3/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub(super) struct ApiMetrics {
/// Number of transaction submission errors for a specific submission error reason.
#[metrics(labels = ["reason"])]
pub submit_tx_error: LabeledFamily<&'static str, Counter>,
#[metrics(buckets = Buckets::linear(0.0..=10.0, 1.0))]
#[metrics(buckets = Buckets::exponential(1.0..=128.0, 2.0))]
pub web3_in_flight_requests: Family<ApiTransportLabel, Histogram<usize>>,
/// Number of currently open WebSocket sessions.
pub ws_open_sessions: Gauge,
Expand Down
3 changes: 3 additions & 0 deletions core/lib/zksync_core/src/state_keeper/io/seal_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use zksync_types::{
// TODO (SMA-1206): use seconds instead of milliseconds.
use zksync_utils::{h256_to_u256, time::millis_since_epoch, u256_to_h256};

use crate::state_keeper::metrics::TxExecutionType;
use crate::{
metrics::{BlockStage, MiniblockStage, APP_METRICS},
state_keeper::{
Expand Down Expand Up @@ -484,6 +485,8 @@ impl MiniblockSealCommand {
KEEPER_METRICS
.transaction_inclusion_delay
.observe(inclusion_delay)
.transaction_inclusion_delay[&TxExecutionType::from_is_l1(tx.transaction.is_l1())]
.observe(Duration::from_millis(inclusion_delay))
});
progress.observe(Some(self.miniblock.executed_transactions.len()));

Expand Down
25 changes: 23 additions & 2 deletions core/lib/zksync_core/src/state_keeper/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ pub(crate) enum TxExecutionStage {
DryRunRollback,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)]
#[metrics(label = "tx_execution_type", rename_all = "snake_case")]
pub(crate) enum TxExecutionType {
L1,
L2,
}

impl TxExecutionType {
pub fn from_is_l1(is_l1: bool) -> TxExecutionType {
match is_l1 {
true => TxExecutionType::L1,
false => TxExecutionType::L2,
}
}
}

const INCLUSION_DELAY_BUCKETS: Buckets = Buckets::values(&[
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9,
2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 20.0, 30.0, 60.0, 120.0, 240.0,
]);

/// General-purpose state keeper metrics.
#[derive(Debug, Metrics)]
#[metrics(prefix = "server_state_keeper")]
Expand All @@ -53,8 +74,8 @@ pub(crate) struct StateKeeperMetrics {
#[metrics(buckets = Buckets::LATENCIES)]
pub load_previous_miniblock_header: Histogram<Duration>,
/// The time it takes for transactions to be included in a block. Representative of the time user must wait before their transaction is confirmed.
#[metrics(buckets = Buckets::LATENCIES)]
pub transaction_inclusion_delay: Histogram<Duration>,
#[metrics(buckets = INCLUSION_DELAY_BUCKETS)]
pub transaction_inclusion_delay: Family<TxExecutionType, Histogram<Duration>>,
/// Time spent by the state keeper on transaction execution.
#[metrics(buckets = Buckets::LATENCIES)]
pub tx_execution_time: Family<TxExecutionStage, Histogram<Duration>>,
Expand Down

0 comments on commit 79716f4

Please sign in to comment.