From 79716f439872ab4fe178048b8118e63f0289e877 Mon Sep 17 00:00:00 2001 From: romanbrodetskiy Date: Fri, 16 Feb 2024 08:10:17 +0000 Subject: [PATCH] add label to transaction inclusion metric; refine buckets --- .../src/api_server/web3/metrics.rs | 2 +- .../src/state_keeper/io/seal_logic.rs | 3 +++ .../zksync_core/src/state_keeper/metrics.rs | 25 +++++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/lib/zksync_core/src/api_server/web3/metrics.rs b/core/lib/zksync_core/src/api_server/web3/metrics.rs index 44edd032f69c..28071c9a37d5 100644 --- a/core/lib/zksync_core/src/api_server/web3/metrics.rs +++ b/core/lib/zksync_core/src/api_server/web3/metrics.rs @@ -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>, /// Number of currently open WebSocket sessions. pub ws_open_sessions: Gauge, diff --git a/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs b/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs index f835d776ba61..4d5451642fd8 100644 --- a/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs +++ b/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs @@ -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::{ @@ -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())); diff --git a/core/lib/zksync_core/src/state_keeper/metrics.rs b/core/lib/zksync_core/src/state_keeper/metrics.rs index 181447e9761b..3e840d855382 100644 --- a/core/lib/zksync_core/src/state_keeper/metrics.rs +++ b/core/lib/zksync_core/src/state_keeper/metrics.rs @@ -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")] @@ -53,8 +74,8 @@ pub(crate) struct StateKeeperMetrics { #[metrics(buckets = Buckets::LATENCIES)] pub load_previous_miniblock_header: Histogram, /// 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, + #[metrics(buckets = INCLUSION_DELAY_BUCKETS)] + pub transaction_inclusion_delay: Family>, /// Time spent by the state keeper on transaction execution. #[metrics(buckets = Buckets::LATENCIES)] pub tx_execution_time: Family>,