diff --git a/Cargo.toml b/Cargo.toml index d5b0d1805..8b7836f69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,8 +65,8 @@ reqwest = { version = "=0.11.24", features = ["json"] } tower = "=0.4.13" # observability -metrics = "=0.21.1" -metrics-exporter-prometheus = "=0.12.2" +metrics = { version = "=0.21.1", optional = true } +metrics-exporter-prometheus = { version = "=0.12.2", optional = true } tracing = "=0.1.40" tracing-subscriber = { version = "=0.3.18", features = ["env-filter", "json"] } @@ -132,6 +132,15 @@ semicolon_if_nothing_returned = "warn" [features] default = ["rocks"] -dev = [] # Application is running in develoment mode. -perf = [] # Application is running in performance test mode. + +# Application is running in develoment mode. +dev = [] + +# Application is running in performance test mode. +perf = [] + +# Enable metrics dependencies and code for metrics collection. +metrics = ["dep:metrics", "dep:metrics-exporter-prometheus"] + +# Enable RocksDB dependencies. rocks = ["rocksdb", "bincode"] diff --git a/justfile b/justfile index c37895635..bbad68015 100644 --- a/justfile +++ b/justfile @@ -153,7 +153,7 @@ test-unit name="": # Test: Execute Rust integration tests test-int name="": - cargo test --test '*' {{name}} -- --nocapture + cargo test --test '*' {{name}} --features metrics -- --nocapture # ------------------------------------------------------------------------------ # E2E tasks diff --git a/src/bin/importer_offline.rs b/src/bin/importer_offline.rs index acad561e1..5f91c9220 100644 --- a/src/bin/importer_offline.rs +++ b/src/bin/importer_offline.rs @@ -1,6 +1,5 @@ use std::cmp::min; use std::sync::Arc; -use std::time::Instant; use anyhow::anyhow; use futures::try_join; @@ -16,6 +15,7 @@ use stratus::eth::storage::ExternalRpcStorage; use stratus::eth::storage::StratusStorage; use stratus::eth::EthExecutor; use stratus::ext::not; +#[cfg(feature = "metrics")] use stratus::infra::metrics; use stratus::init_global_services; use stratus::log_and_err; @@ -123,7 +123,8 @@ async fn execute_block_importer( tracing::info!(%block_start, %block_end, receipts = %receipts.len(), "importing blocks"); let block_last_index = blocks.len() - 1; for (block_index, block) in blocks.into_iter().enumerate() { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); match csv { // when exporting to csv, only persist temporary changes because permanent will be bulk loaded at the end of the process @@ -156,6 +157,7 @@ async fn execute_block_importer( } } + #[cfg(feature = "metrics")] metrics::inc_import_offline(start.elapsed()); } }; diff --git a/src/bin/importer_online.rs b/src/bin/importer_online.rs index 16d4ebe36..ee0cb35ca 100644 --- a/src/bin/importer_online.rs +++ b/src/bin/importer_online.rs @@ -8,6 +8,7 @@ use stratus::eth::primitives::ExternalBlock; use stratus::eth::primitives::ExternalReceipt; use stratus::eth::primitives::ExternalReceipts; use stratus::eth::primitives::Hash; +#[cfg(feature = "metrics")] use stratus::infra::metrics; use stratus::infra::BlockchainClient; use stratus::init_global_services; @@ -33,7 +34,9 @@ async fn run(config: ImporterOnlineConfig) -> anyhow::Result<()> { // keep importing forever loop { - let start = std::time::Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + number = number.next(); // fetch block and receipts @@ -49,6 +52,8 @@ async fn run(config: ImporterOnlineConfig) -> anyhow::Result<()> { // import block let mut receipts: ExternalReceipts = receipts.into(); executor.import_external_to_perm(block, &mut receipts).await?; + + #[cfg(feature = "metrics")] metrics::inc_import_online(start.elapsed()); } } diff --git a/src/eth/evm/revm.rs b/src/eth/evm/revm.rs index c2eaa44b4..040fd0211 100644 --- a/src/eth/evm/revm.rs +++ b/src/eth/evm/revm.rs @@ -6,7 +6,6 @@ //! of the `Evm` trait, serving as a bridge between Ethereum's abstract operations and Stratus's storage mechanisms. use std::sync::Arc; -use std::time::Instant; use anyhow::anyhow; use anyhow::Context; @@ -47,6 +46,7 @@ use crate::eth::primitives::SlotIndex; use crate::eth::storage::StratusStorage; use crate::ext::not; use crate::ext::OptionExt; +#[cfg(feature = "metrics")] use crate::infra::metrics; /// Implementation of EVM using [`revm`](https://crates.io/crates/revm). @@ -82,7 +82,8 @@ impl Revm { impl Evm for Revm { fn execute(&mut self, input: EvmInput) -> anyhow::Result { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); // configure session let evm = &mut self.evm; @@ -114,9 +115,11 @@ impl Evm for Revm { // parse result and track metrics let session = evm.db_mut(); let session_input = std::mem::take(&mut session.input); - let session_point_in_time = std::mem::take(&mut session.input.point_in_time); + let session_storage_changes = std::mem::take(&mut session.storage_changes); let session_metrics = std::mem::take(&mut session.metrics); + #[cfg(feature = "metrics")] + let session_point_in_time = std::mem::take(&mut session.input.point_in_time); let execution = match evm_result { Ok(result) => Ok(parse_revm_execution(result, session_input, session_storage_changes)), @@ -126,9 +129,12 @@ impl Evm for Revm { } }; - metrics::inc_evm_execution(start.elapsed(), &session_point_in_time, execution.is_ok()); - metrics::inc_evm_execution_account_reads(session_metrics.account_reads); - metrics::inc_evm_execution_slot_reads(session_metrics.slot_reads); + #[cfg(feature = "metrics")] + { + metrics::inc_evm_execution(start.elapsed(), &session_point_in_time, execution.is_ok()); + metrics::inc_evm_execution_account_reads(session_metrics.account_reads); + metrics::inc_evm_execution_slot_reads(session_metrics.slot_reads); + } execution.map(|x| (x, session_metrics)) } diff --git a/src/eth/executor.rs b/src/eth/executor.rs index 7529df1eb..a3b71598b 100644 --- a/src/eth/executor.rs +++ b/src/eth/executor.rs @@ -7,7 +7,6 @@ use std::io::Write; use std::sync::Arc; -use std::time::Instant; use anyhow::anyhow; use tokio::sync::broadcast; @@ -31,6 +30,7 @@ use crate::eth::storage::InMemoryPermanentStorage; use crate::eth::storage::StorageError; use crate::eth::storage::StratusStorage; use crate::eth::BlockMiner; +#[cfg(feature = "metrics")] use crate::infra::metrics; /// Number of events in the backlog. @@ -90,7 +90,9 @@ impl EthExecutor { /// Re-executes an external block locally and imports it to the temporary storage. pub async fn import_external_to_temp(&self, block: ExternalBlock, receipts: &mut ExternalReceipts) -> anyhow::Result { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let mut block_metrics = ExecutionMetrics::default(); tracing::info!(number = %block.number(), "importing external block"); @@ -100,7 +102,8 @@ impl EthExecutor { // re-execute transactions let mut executions: Vec = Vec::with_capacity(block.transactions.len()); for tx in block.transactions.clone() { - let tx_start = Instant::now(); + #[cfg(feature = "metrics")] + let tx_start = metrics::now(); // re-execute transaction or create a fake execution the external transaction failed let receipt = receipts.try_take(&tx.hash())?; @@ -134,6 +137,7 @@ impl EthExecutor { executions.push((tx, receipt, execution.clone())); // track metrics + #[cfg(feature = "metrics")] metrics::inc_executor_external_transaction(tx_start.elapsed()); block_metrics.account_reads += execution_metrics.account_reads; block_metrics.slot_reads += execution_metrics.slot_reads; @@ -161,16 +165,21 @@ impl EthExecutor { }; // track metrics - metrics::inc_executor_external_block(start.elapsed()); - metrics::inc_executor_external_block_account_reads(block_metrics.account_reads); - metrics::inc_executor_external_block_slot_reads(block_metrics.slot_reads); + #[cfg(feature = "metrics")] + { + metrics::inc_executor_external_block(start.elapsed()); + metrics::inc_executor_external_block_account_reads(block_metrics.account_reads); + metrics::inc_executor_external_block_slot_reads(block_metrics.slot_reads); + } Ok(block) } /// Executes a transaction persisting state changes. pub async fn transact(&self, transaction: TransactionInput) -> anyhow::Result { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + tracing::info!( hash = %transaction.hash, nonce = %transaction.nonce, @@ -205,6 +214,7 @@ impl EthExecutor { continue; } Err(e) => { + #[cfg(feature = "metrics")] metrics::inc_executor_transact(start.elapsed(), false); return Err(e.into()); } @@ -226,13 +236,17 @@ impl EthExecutor { } } + #[cfg(feature = "metrics")] metrics::inc_executor_transact(start.elapsed(), true); + Ok(execution) } /// Executes a transaction without persisting state changes. pub async fn call(&self, input: CallInput, point_in_time: StoragePointInTime) -> anyhow::Result { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + tracing::info!( from = ?input.from, to = ?input.to, @@ -243,7 +257,10 @@ impl EthExecutor { let evm_input = EvmInput::from_eth_call(input, point_in_time); let result = self.execute_in_evm(evm_input).await; + + #[cfg(feature = "metrics")] metrics::inc_executor_call(start.elapsed(), result.is_ok()); + result.map(|x| x.0) } diff --git a/src/eth/primitives/storage_point_in_time.rs b/src/eth/primitives/storage_point_in_time.rs index 674ff5d2d..6df881ccc 100644 --- a/src/eth/primitives/storage_point_in_time.rs +++ b/src/eth/primitives/storage_point_in_time.rs @@ -7,6 +7,7 @@ //! block number, facilitating temporal queries in Ethereum. use crate::eth::primitives::BlockNumber; +#[cfg(feature = "metrics")] use crate::infra::metrics::LabelValue; /// EVM storage point-in-time indicator. @@ -23,6 +24,7 @@ pub enum StoragePointInTime { // ----------------------------------------------------------------------------- // Conversions: Other -> Self // ----------------------------------------------------------------------------- +#[cfg(feature = "metrics")] impl From<&StoragePointInTime> for LabelValue { fn from(value: &StoragePointInTime) -> Self { match value { diff --git a/src/eth/rpc/rpc_middleware.rs b/src/eth/rpc/rpc_middleware.rs index f9116bfe8..a2d856cd0 100644 --- a/src/eth/rpc/rpc_middleware.rs +++ b/src/eth/rpc/rpc_middleware.rs @@ -19,6 +19,7 @@ use crate::eth::primitives::SoliditySignature; use crate::eth::primitives::TransactionInput; use crate::eth::rpc::next_rpc_param; use crate::eth::rpc::parse_rpc_rlp; +#[cfg(feature = "metrics")] use crate::infra::metrics; // ----------------------------------------------------------------------------- @@ -55,6 +56,7 @@ where ); // metrify request + #[cfg(feature = "metrics")] metrics::inc_rpc_requests_started(method, function); RpcResponse { @@ -129,6 +131,7 @@ impl> Future for RpcResponse { ); // metrify response + #[cfg(feature = "metrics")] metrics::inc_rpc_requests_finished(elapsed, proj.method.clone(), *proj.function, response.success_or_error.is_success()); } diff --git a/src/eth/storage/hybrid/mod.rs b/src/eth/storage/hybrid/mod.rs index 6bc43ee31..7d5c5ea40 100644 --- a/src/eth/storage/hybrid/mod.rs +++ b/src/eth/storage/hybrid/mod.rs @@ -2,6 +2,7 @@ mod hybrid_state; mod query_executor; mod rocks_db; +use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::Duration; @@ -9,7 +10,6 @@ use std::time::Duration; use anyhow::Context; use async_trait::async_trait; use futures::future::join_all; -use metrics::atomics::AtomicU64; use num_traits::cast::ToPrimitive; use sqlx::postgres::PgPoolOptions; use sqlx::types::Json; diff --git a/src/eth/storage/inmemory/inmemory_permanent.rs b/src/eth/storage/inmemory/inmemory_permanent.rs index 90866fb61..d37ef5061 100644 --- a/src/eth/storage/inmemory/inmemory_permanent.rs +++ b/src/eth/storage/inmemory/inmemory_permanent.rs @@ -1,12 +1,12 @@ //! In-memory storage implementations. use std::collections::HashMap; +use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; use std::sync::Arc; use async_trait::async_trait; use indexmap::IndexMap; -use metrics::atomics::AtomicU64; use rand::rngs::StdRng; use rand::seq::IteratorRandom; use rand::SeedableRng; diff --git a/src/eth/storage/stratus_storage.rs b/src/eth/storage/stratus_storage.rs index 94bf1dd29..695e7c88b 100644 --- a/src/eth/storage/stratus_storage.rs +++ b/src/eth/storage/stratus_storage.rs @@ -1,5 +1,4 @@ use std::sync::Arc; -use std::time::Instant; use anyhow::anyhow; @@ -20,10 +19,14 @@ use crate::eth::primitives::TransactionMined; use crate::eth::storage::PermanentStorage; use crate::eth::storage::StorageError; use crate::eth::storage::TemporaryStorage; +#[cfg(feature = "metrics")] use crate::infra::metrics; +#[cfg(feature = "metrics")] const STORAGE_TEMP: &str = "temporary"; +#[cfg(feature = "metrics")] const STORAGE_PERM: &str = "permanent"; +#[cfg(feature = "metrics")] const DEFAULT_VALUE: &str = "default"; pub struct StratusStorage { @@ -41,42 +44,72 @@ impl StratusStorage { // ------------------------------------------------------------------------- // Retrieves the active block number. + #[allow(clippy::let_and_return)] pub async fn read_active_block_number(&self) -> anyhow::Result> { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.temp.read_active_block_number().await; + + #[cfg(feature = "metrics")] metrics::inc_storage_read_active_block_number(start.elapsed(), result.is_ok()); + result } // Retrieves the last mined block number. + #[allow(clippy::let_and_return)] pub async fn read_mined_block_number(&self) -> anyhow::Result { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.perm.read_mined_block_number().await; + + #[cfg(feature = "metrics")] metrics::inc_storage_read_mined_block_number(start.elapsed(), result.is_ok()); + result } /// Atomically increments the block number, returning the new value. + #[allow(clippy::let_and_return)] pub async fn increment_block_number(&self) -> anyhow::Result { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.perm.increment_block_number().await; + + #[cfg(feature = "metrics")] metrics::inc_storage_increment_block_number(start.elapsed(), result.is_ok()); + result } /// Sets the active block number to a specific value. + #[allow(clippy::let_and_return)] pub async fn set_active_block_number(&self, number: BlockNumber) -> anyhow::Result<()> { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.temp.set_active_block_number(number).await; + + #[cfg(feature = "metrics")] metrics::inc_storage_set_active_block_number(start.elapsed(), result.is_ok()); + result } /// Sets the mined block number to a specific value. + #[allow(clippy::let_and_return)] pub async fn set_mined_block_number(&self, number: BlockNumber) -> anyhow::Result<()> { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.perm.set_mined_block_number(number).await; + + #[cfg(feature = "metrics")] metrics::inc_storage_set_mined_block_number(start.elapsed(), result.is_ok()); + result } @@ -86,22 +119,26 @@ impl StratusStorage { /// Retrieves an account from the storage. Returns default value when not found. pub async fn read_account(&self, address: &Address, point_in_time: &StoragePointInTime) -> anyhow::Result { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); match self.temp.maybe_read_account(address).await? { Some(account) => { tracing::debug!("account found in the temporary storage"); + #[cfg(feature = "metrics")] metrics::inc_storage_read_account(start.elapsed(), STORAGE_TEMP, point_in_time, true); Ok(account) } None => match self.perm.maybe_read_account(address, point_in_time).await? { Some(account) => { tracing::debug!("account found in the permanent storage"); + #[cfg(feature = "metrics")] metrics::inc_storage_read_account(start.elapsed(), STORAGE_PERM, point_in_time, true); Ok(account) } None => { tracing::debug!("account not found, assuming default value"); + #[cfg(feature = "metrics")] metrics::inc_storage_read_account(start.elapsed(), DEFAULT_VALUE, point_in_time, true); Ok(Account { address: address.clone(), @@ -114,22 +151,26 @@ impl StratusStorage { /// Retrieves an slot from the storage. Returns default value when not found. pub async fn read_slot(&self, address: &Address, slot_index: &SlotIndex, point_in_time: &StoragePointInTime) -> anyhow::Result { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); match self.temp.maybe_read_slot(address, slot_index).await? { Some(slot) => { tracing::debug!("slot found in the temporary storage"); + #[cfg(feature = "metrics")] metrics::inc_storage_read_slot(start.elapsed(), STORAGE_TEMP, point_in_time, true); Ok(slot) } None => match self.perm.maybe_read_slot(address, slot_index, point_in_time).await? { Some(slot) => { tracing::debug!("slot found in the permanent storage"); + #[cfg(feature = "metrics")] metrics::inc_storage_read_slot(start.elapsed(), STORAGE_PERM, point_in_time, true); Ok(slot) } None => { tracing::debug!("slot not found, assuming default value"); + #[cfg(feature = "metrics")] metrics::inc_storage_read_slot(start.elapsed(), DEFAULT_VALUE, point_in_time, true); Ok(Slot { index: slot_index.clone(), @@ -141,26 +182,44 @@ impl StratusStorage { } /// Retrieves a block from the storage. + #[allow(clippy::let_and_return)] pub async fn read_block(&self, block_selection: &BlockSelection) -> anyhow::Result> { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.perm.read_block(block_selection).await; + + #[cfg(feature = "metrics")] metrics::inc_storage_read_block(start.elapsed(), result.is_ok()); + result } /// Retrieves a transaction from the storage. + #[allow(clippy::let_and_return)] pub async fn read_mined_transaction(&self, hash: &Hash) -> anyhow::Result> { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.perm.read_mined_transaction(hash).await; + + #[cfg(feature = "metrics")] metrics::inc_storage_read_mined_transaction(start.elapsed(), result.is_ok()); + result } /// Retrieves logs from the storage. + #[allow(clippy::let_and_return)] pub async fn read_logs(&self, filter: &LogFilter) -> anyhow::Result> { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.perm.read_logs(filter).await; + + #[cfg(feature = "metrics")] metrics::inc_storage_read_logs(start.elapsed(), result.is_ok()); + result } @@ -169,35 +228,54 @@ impl StratusStorage { // ------------------------------------------------------------------------- /// Persists accounts like pre-genesis accounts or test accounts. + #[allow(clippy::let_and_return)] pub async fn save_accounts_to_perm(&self, accounts: Vec) -> anyhow::Result<()> { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.perm.save_accounts(accounts).await; + + #[cfg(feature = "metrics")] metrics::inc_storage_save_accounts(start.elapsed(), result.is_ok()); + result } /// Temporarily saves account's changes generated during block production. + #[allow(clippy::let_and_return)] pub async fn save_account_changes_to_temp(&self, changes: Vec) -> anyhow::Result<()> { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.temp.save_account_changes(changes).await; + + #[cfg(feature = "metrics")] metrics::inc_storage_save_account_changes(start.elapsed(), result.is_ok()); + result } /// If necessary, flushes temporary state to durable storage. + #[allow(clippy::let_and_return)] pub async fn flush_temp(&self) -> anyhow::Result<()> { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.temp.flush().await; + + #[cfg(feature = "metrics")] metrics::inc_storage_flush_temp(start.elapsed(), result.is_ok()); + result } /// Commits changes to permanent storage and prepares temporary storage for a new block to be produced. pub async fn commit_to_perm(&self, block: Block) -> anyhow::Result<(), StorageError> { - let start = Instant::now(); - - // compute labels + #[cfg(feature = "metrics")] + let start = metrics::now(); + #[cfg(feature = "metrics")] let label_size_by_tx = block.label_size_by_transactions(); + #[cfg(feature = "metrics")] let label_size_by_gas = block.label_size_by_gas(); // save block to permanent storage and clears temporary storage @@ -207,23 +285,37 @@ impl StratusStorage { self.reset_temp().await?; self.set_active_block_number(next_number).await?; + #[cfg(feature = "metrics")] metrics::inc_storage_commit(start.elapsed(), label_size_by_tx, label_size_by_gas, result.is_ok()); + result } /// Resets temporary storage. + #[allow(clippy::let_and_return)] pub async fn reset_temp(&self) -> anyhow::Result<()> { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.temp.reset().await; + + #[cfg(feature = "metrics")] metrics::inc_storage_reset(start.elapsed(), STORAGE_TEMP, result.is_ok()); + result } /// Resets permanent storage down to specific block_number. + #[allow(clippy::let_and_return)] pub async fn reset_perm(&self, block_number: BlockNumber) -> anyhow::Result<()> { - let start = Instant::now(); + #[cfg(feature = "metrics")] + let start = metrics::now(); + let result = self.perm.reset_at(block_number).await; + + #[cfg(feature = "metrics")] metrics::inc_storage_reset(start.elapsed(), STORAGE_PERM, result.is_ok()); + result } diff --git a/src/infra/metrics.rs b/src/infra/metrics.rs index 3f6f243a6..c2d2ee8c4 100644 --- a/src/infra/metrics.rs +++ b/src/infra/metrics.rs @@ -1,6 +1,8 @@ //! Metrics services. +#![cfg(feature = "metrics")] use std::stringify; +use std::time::Instant; use metrics::counter; use metrics::describe_counter; @@ -62,6 +64,11 @@ pub fn init_metrics(histogram_kind: MetricsHistogramKind) { } } +/// Track metrics execution starting instant. +pub fn now() -> Instant { + Instant::now() +} + // JSON-RPC metrics. metrics! { group: json_rpc, diff --git a/src/infra/mod.rs b/src/infra/mod.rs index cf5e3d2ab..b4706b687 100644 --- a/src/infra/mod.rs +++ b/src/infra/mod.rs @@ -2,9 +2,11 @@ pub mod blockchain_client; pub mod docker; +#[cfg(feature = "metrics")] pub mod metrics; pub mod tracing; pub use blockchain_client::BlockchainClient; +#[cfg(feature = "metrics")] pub use metrics::init_metrics; pub use tracing::init_tracing; diff --git a/src/lib.rs b/src/lib.rs index 06af7ed54..2b2125c4b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,7 @@ where // init services infra::init_tracing(); + #[cfg(feature = "metrics")] infra::init_metrics(config.common().metrics_histogram_kind); config diff --git a/tests/test_import_offline_snapshot.rs b/tests/test_import_offline_snapshot.rs index cff096f94..a93ac2dd0 100644 --- a/tests/test_import_offline_snapshot.rs +++ b/tests/test_import_offline_snapshot.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use std::time::Duration; -use const_format::formatcp; use fancy_duration::AsFancyDuration; use itertools::Itertools; use stratus::config::IntegrationTestConfig; @@ -15,49 +14,57 @@ use stratus::eth::storage::PostgresPermanentStorage; use stratus::eth::storage::PostgresPermanentStorageConfig; use stratus::eth::storage::StratusStorage; use stratus::infra::docker::Docker; -use stratus::infra::metrics::METRIC_EVM_EXECUTION; -use stratus::infra::metrics::METRIC_STORAGE_COMMIT; -use stratus::infra::metrics::METRIC_STORAGE_READ_ACCOUNT; -use stratus::infra::metrics::METRIC_STORAGE_READ_SLOT; use stratus::init_global_services; +#[cfg(feature = "metrics")] +mod m { + pub use const_format::formatcp; + pub use stratus::infra::metrics::METRIC_EVM_EXECUTION; + pub use stratus::infra::metrics::METRIC_STORAGE_COMMIT; + pub use stratus::infra::metrics::METRIC_STORAGE_READ_ACCOUNT; + pub use stratus::infra::metrics::METRIC_STORAGE_READ_SLOT; +} +#[cfg(feature = "metrics")] const METRIC_QUERIES: [&str; 30] = [ // EVM "", - formatcp!("{}_count", METRIC_EVM_EXECUTION), - formatcp!("{}_sum", METRIC_EVM_EXECUTION), - formatcp!("{}{{quantile='1'}}", METRIC_EVM_EXECUTION), + m::formatcp!("{}_count", m::METRIC_EVM_EXECUTION), + m::formatcp!("{}_sum", m::METRIC_EVM_EXECUTION), + m::formatcp!("{}{{quantile='1'}}", m::METRIC_EVM_EXECUTION), // STORAGE ACCOUNTS "", - formatcp!("sum({}_count)", METRIC_STORAGE_READ_ACCOUNT), - formatcp!("{}_count{{found_at='temporary'}}", METRIC_STORAGE_READ_ACCOUNT), - formatcp!("{}_count{{found_at='permanent'}}", METRIC_STORAGE_READ_ACCOUNT), - formatcp!("{}_count{{found_at='default'}}", METRIC_STORAGE_READ_ACCOUNT), - formatcp!("sum({}_sum)", METRIC_STORAGE_READ_ACCOUNT), - formatcp!("{}_sum{{found_at='temporary'}}", METRIC_STORAGE_READ_ACCOUNT), - formatcp!("{}_sum{{found_at='permanent'}}", METRIC_STORAGE_READ_ACCOUNT), - formatcp!("{}_sum{{found_at='default'}}", METRIC_STORAGE_READ_ACCOUNT), - formatcp!("{}{{found_at='temporary', quantile='1'}}", METRIC_STORAGE_READ_ACCOUNT), - formatcp!("{}{{found_at='permanent', quantile='1'}}", METRIC_STORAGE_READ_ACCOUNT), - formatcp!("{}{{found_at='default', quantile='1'}}", METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("sum({}_count)", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("{}_count{{found_at='temporary'}}", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("{}_count{{found_at='permanent'}}", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("{}_count{{found_at='default'}}", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("sum({}_sum)", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("{}_sum{{found_at='temporary'}}", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("{}_sum{{found_at='permanent'}}", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("{}_sum{{found_at='default'}}", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("{}{{found_at='temporary', quantile='1'}}", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("{}{{found_at='permanent', quantile='1'}}", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("{}{{found_at='default', quantile='1'}}", m::METRIC_STORAGE_READ_ACCOUNT), // STORAGE SLOTS "", - formatcp!("sum({}_count)", METRIC_STORAGE_READ_SLOT), - formatcp!("{}_count{{found_at='temporary'}}", METRIC_STORAGE_READ_SLOT), - formatcp!("{}_count{{found_at='permanent'}}", METRIC_STORAGE_READ_SLOT), - formatcp!("{}_count{{found_at='default'}}", METRIC_STORAGE_READ_SLOT), - formatcp!("sum({}_sum)", METRIC_STORAGE_READ_SLOT), - formatcp!("{}_sum{{found_at='temporary'}}", METRIC_STORAGE_READ_SLOT), - formatcp!("{}_sum{{found_at='permanent'}}", METRIC_STORAGE_READ_SLOT), - formatcp!("{}_sum{{found_at='default'}}", METRIC_STORAGE_READ_SLOT), - formatcp!("{}{{found_at='temporary', quantile='1'}}", METRIC_STORAGE_READ_SLOT), - formatcp!("{}{{found_at='permanent', quantile='1'}}", METRIC_STORAGE_READ_SLOT), - formatcp!("{}{{found_at='default', quantile='1'}}", METRIC_STORAGE_READ_SLOT), + m::formatcp!("sum({}_count)", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("{}_count{{found_at='temporary'}}", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("{}_count{{found_at='permanent'}}", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("{}_count{{found_at='default'}}", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("sum({}_sum)", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("{}_sum{{found_at='temporary'}}", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("{}_sum{{found_at='permanent'}}", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("{}_sum{{found_at='default'}}", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("{}{{found_at='temporary', quantile='1'}}", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("{}{{found_at='permanent', quantile='1'}}", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("{}{{found_at='default', quantile='1'}}", m::METRIC_STORAGE_READ_SLOT), // STORAGE COMMIT "", - formatcp!("{}{{quantile='1'}}", METRIC_STORAGE_COMMIT), + m::formatcp!("{}{{quantile='1'}}", m::METRIC_STORAGE_COMMIT), ]; +#[cfg(not(feature = "metrics"))] +const METRIC_QUERIES: [&str; 0] = []; + #[tokio::test] async fn test_import_offline_snapshot() { let mut config = init_global_services::();