diff --git a/Cargo.lock b/Cargo.lock index 9d1b17780..2ae9308e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2278,12 +2278,10 @@ dependencies = [ "async-trait", "derive_more", "kona-derive", - "lazy_static", "lru", "op-alloy-consensus", "op-alloy-genesis", "op-alloy-protocol", - "prometheus", "reqwest", "serde", "serde_json", @@ -3147,46 +3145,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "procfs" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "731e0d9356b0c25f16f33b5be79b1c57b562f141ebfcdb0ad8ac2c13a24293b4" -dependencies = [ - "bitflags 2.6.0", - "hex", - "lazy_static", - "procfs-core", - "rustix", -] - -[[package]] -name = "procfs-core" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3554923a69f4ce04c4a754260c338f505ce22642d3830e049a399fc2059a29" -dependencies = [ - "bitflags 2.6.0", - "hex", -] - -[[package]] -name = "prometheus" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d33c28a30771f7f96db69893f78b857f7450d7e0237e9c8fc6427a81bae7ed1" -dependencies = [ - "cfg-if", - "fnv", - "lazy_static", - "libc", - "memchr", - "parking_lot", - "procfs", - "protobuf", - "thiserror", -] - [[package]] name = "proptest" version = "1.5.0" @@ -3218,12 +3176,6 @@ dependencies = [ "syn 2.0.85", ] -[[package]] -name = "protobuf" -version = "2.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" - [[package]] name = "ptr_meta" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index 4e659faf0..0f393397e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,8 +96,6 @@ cfg-if = "1.0.0" os_pipe = "1.2.1" reqwest = "0.12.8" command-fds = "0.3.0" -prometheus = "0.13.4" -lazy_static = "1.5.0" async-trait = "0.1.83" alloc-no-stdlib = "2.0.4" linked_list_allocator = "0.10.5" diff --git a/crates/derive-alloy/Cargo.toml b/crates/derive-alloy/Cargo.toml index 623632a82..56ddb614a 100644 --- a/crates/derive-alloy/Cargo.toml +++ b/crates/derive-alloy/Cargo.toml @@ -37,10 +37,6 @@ async-trait.workspace = true # Workspace kona-derive = { workspace = true, features = ["serde"] } -# `metrics` feature dependencies -lazy_static = { workspace = true, optional = true } -prometheus = { workspace = true, optional = true, features = ["process"] } - # `test-utils` feature dependencies derive_more = { workspace = true, features = ["full"], optional = true } alloy-rpc-client = { workspace = true, optional = true } @@ -58,7 +54,6 @@ kona-derive = { workspace = true, features = ["serde", "test-utils"] } [features] default = [] -metrics = ["dep:prometheus", "dep:lazy_static"] test-utils = [ "dep:derive_more", "dep:alloy-rpc-client", diff --git a/crates/derive-alloy/src/alloy_providers.rs b/crates/derive-alloy/src/alloy_providers.rs index 1a80cf671..848d97635 100644 --- a/crates/derive-alloy/src/alloy_providers.rs +++ b/crates/derive-alloy/src/alloy_providers.rs @@ -4,7 +4,7 @@ use alloy_consensus::{Block, Header, Receipt, ReceiptWithBloom, TxEnvelope, TxTy use alloy_primitives::{Bytes, B256, U64}; use alloy_provider::{Provider, ReqwestProvider}; use alloy_rlp::{Buf, Decodable}; -use alloy_transport::{RpcError, TransportErrorKind, TransportResult}; +use alloy_transport::{RpcError, TransportErrorKind}; use async_trait::async_trait; use kona_derive::traits::{ChainProvider, L2ChainProvider}; use lru::LruCache; @@ -71,71 +71,29 @@ impl ChainProvider for AlloyChainProvider { type Error = RpcError; async fn header_by_hash(&mut self, hash: B256) -> Result { - crate::inc!(PROVIDER_CALLS, &["chain_provider", "header_by_hash"]); - crate::timer!(START, PROVIDER_RESPONSE_TIME, &["chain_provider", "header_by_hash"], timer); if let Some(header) = self.header_by_hash_cache.get(&hash) { return Ok(header.clone()); } - let raw_header: TransportResult = - self.inner.raw_request("debug_getRawHeader".into(), [hash]).await; - let raw_header: Bytes = match raw_header { - Ok(b) => b, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["chain_provider", "header_by_hash", "debug_getRawHeader"] - ); - return Err(e); - } - }; + let raw_header: Bytes = self.inner.raw_request("debug_getRawHeader".into(), [hash]).await?; match Header::decode(&mut raw_header.as_ref()) { Ok(header) => { self.header_by_hash_cache.put(hash, header.clone()); Ok(header) } - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!(PROVIDER_ERRORS, &["chain_provider", "header_by_hash", "decode"]); - Err(RpcError::LocalUsageError(Box::new(e))) - } + Err(e) => Err(RpcError::LocalUsageError(Box::new(e))), } } async fn block_info_by_number(&mut self, number: u64) -> Result { - crate::inc!(PROVIDER_CALLS, &["chain_provider", "block_info_by_number"]); - crate::timer!( - START, - PROVIDER_RESPONSE_TIME, - &["chain_provider", "block_info_by_number"], - timer - ); if let Some(block_info) = self.block_info_by_number_cache.get(&number) { return Ok(*block_info); } - let raw_header: TransportResult = - self.inner.raw_request("debug_getRawHeader".into(), [U64::from(number)]).await; - let raw_header: Bytes = match raw_header { - Ok(b) => b, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["chain_provider", "block_info_by_number", "debug_getRawHeader"] - ); - return Err(e); - } - }; - let header = match Header::decode(&mut raw_header.as_ref()) { - Ok(h) => h, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!(PROVIDER_ERRORS, &["chain_provider", "block_info_by_number", "decode"]); - return Err(RpcError::LocalUsageError(Box::new(e))); - } - }; + let raw_header: Bytes = + self.inner.raw_request("debug_getRawHeader".into(), [U64::from(number)]).await?; + let header = Header::decode(&mut raw_header.as_ref()) + .map_err(|e| RpcError::LocalUsageError(Box::new(e)))?; let block_info = BlockInfo { hash: header.hash_slow(), @@ -148,32 +106,13 @@ impl ChainProvider for AlloyChainProvider { } async fn receipts_by_hash(&mut self, hash: B256) -> Result, Self::Error> { - crate::inc!(PROVIDER_CALLS, &["chain_provider", "receipts_by_hash"]); - crate::timer!( - START, - PROVIDER_RESPONSE_TIME, - &["chain_provider", "receipts_by_hash"], - timer - ); if let Some(receipts) = self.receipts_by_hash_cache.get(&hash) { return Ok(receipts.clone()); } - let raw_receipts: TransportResult> = - self.inner.raw_request("debug_getRawReceipts".into(), [hash]).await; - let raw_receipts: Vec = match raw_receipts { - Ok(r) => r, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["chain_provider", "receipts_by_hash", "debug_getRawReceipts"] - ); - return Err(e); - } - }; - - let receipts = match raw_receipts + let raw_receipts: Vec = + self.inner.raw_request("debug_getRawReceipts".into(), [hash]).await?; + let receipts = raw_receipts .iter() .map(|r| { let r = &mut r.as_ref(); @@ -187,15 +126,7 @@ impl ChainProvider for AlloyChainProvider { .map_err(|e| RpcError::LocalUsageError(Box::new(e)))? .receipt) }) - .collect::, Self::Error>>() - { - Ok(r) => r, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!(PROVIDER_ERRORS, &["chain_provider", "receipts_by_hash", "decode"]); - return Err(e); - } - }; + .collect::, Self::Error>>()?; self.receipts_by_hash_cache.put(hash, receipts.clone()); Ok(receipts) } @@ -204,42 +135,14 @@ impl ChainProvider for AlloyChainProvider { &mut self, hash: B256, ) -> Result<(BlockInfo, Vec), Self::Error> { - crate::inc!(PROVIDER_CALLS, &["chain_provider", "block_info_and_transactions_by_hash"]); - crate::timer!( - START, - PROVIDER_RESPONSE_TIME, - &["chain_provider", "block_info_and_transactions_by_hash"], - timer - ); if let Some(block_info_and_txs) = self.block_info_and_transactions_by_hash_cache.get(&hash) { return Ok(block_info_and_txs.clone()); } - let raw_block: TransportResult = - self.inner.raw_request("debug_getRawBlock".into(), [hash]).await; - let raw_block: Bytes = match raw_block { - Ok(b) => b, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["chain_provider", "block_info_and_transactions_by_hash", "debug_getRawBlock"] - ); - return Err(e); - } - }; - let block = match Block::decode(&mut raw_block.as_ref()) { - Ok(b) => b, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["chain_provider", "block_info_and_transactions_by_hash", "decode"] - ); - return Err(RpcError::LocalUsageError(Box::new(e))); - } - }; + let raw_block: Bytes = self.inner.raw_request("debug_getRawBlock".into(), [hash]).await?; + let block = Block::decode(&mut raw_block.as_ref()) + .map_err(|e| RpcError::LocalUsageError(Box::new(e)))?; let block_info = BlockInfo { hash: block.header.hash_slow(), @@ -307,77 +210,27 @@ impl L2ChainProvider for AlloyL2ChainProvider { type Error = RpcError; async fn l2_block_info_by_number(&mut self, number: u64) -> Result { - crate::inc!(PROVIDER_CALLS, &["l2_chain_provider", "l2_block_info_by_number"]); - crate::timer!( - START, - PROVIDER_RESPONSE_TIME, - &["l2_chain_provider", "l2_block_info_by_number"], - timer - ); if let Some(l2_block_info) = self.l2_block_info_by_number_cache.get(&number) { return Ok(*l2_block_info); } - let block = match self.block_by_number(number).await { - Ok(p) => p, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["l2_chain_provider", "l2_block_info_by_number", "block_by_number"] - ); - return Err(e); - } - }; + let block = self.block_by_number(number).await?; let l2_block_info = - match L2BlockInfo::from_block_and_genesis(&block, &self.rollup_config.genesis) { - Ok(b) => b, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["l2_chain_provider", "l2_block_info_by_number", "from_block_and_genesis"] - ); - return Err(RpcError::LocalUsageError(Box::new(e))); - } - }; + L2BlockInfo::from_block_and_genesis(&block, &self.rollup_config.genesis) + .map_err(|e| RpcError::LocalUsageError(Box::new(e)))?; self.l2_block_info_by_number_cache.put(number, l2_block_info); Ok(l2_block_info) } async fn block_by_number(&mut self, number: u64) -> Result { - crate::inc!(PROVIDER_CALLS, &["l2_chain_provider", "block_by_number"]); - crate::timer!( - START, - PROVIDER_RESPONSE_TIME, - &["l2_chain_provider", "block_by_number"], - timer - ); if let Some(block) = self.block_by_number_cache.get(&number) { return Ok(block.clone()); } - let raw_block: TransportResult = - self.inner.raw_request("debug_getRawBlock".into(), [U64::from(number)]).await; - let raw_block: Bytes = match raw_block { - Ok(b) => b, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["l2_chain_provider", "block_by_number", "debug_getRawBlock"] - ); - return Err(e); - } - }; - let block = match OpBlock::decode(&mut raw_block.as_ref()) { - Ok(b) => b, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!(PROVIDER_ERRORS, &["l2_chain_provider", "block_by_number", "decode"]); - return Err(RpcError::LocalUsageError(Box::new(e))); - } - }; + let raw_block: Bytes = + self.inner.raw_request("debug_getRawBlock".into(), [U64::from(number)]).await?; + let block = OpBlock::decode(&mut raw_block.as_ref()) + .map_err(|e| RpcError::LocalUsageError(Box::new(e)))?; self.block_by_number_cache.put(number, block.clone()); Ok(block) } @@ -387,39 +240,13 @@ impl L2ChainProvider for AlloyL2ChainProvider { number: u64, rollup_config: Arc, ) -> Result { - crate::inc!(PROVIDER_CALLS, &["l2_chain_provider", "system_config_by_number"]); - crate::timer!( - START, - PROVIDER_RESPONSE_TIME, - &["l2_chain_provider", "system_config_by_number"], - timer - ); if let Some(system_config) = self.system_config_by_number_cache.get(&number) { return Ok(*system_config); } - let block = match self.block_by_number(number).await { - Ok(e) => e, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["l2_chain_provider", "system_config_by_number", "block_by_number"] - ); - return Err(e); - } - }; - let sys_config = match to_system_config(&block, &rollup_config) { - Ok(s) => s, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["l2_chain_provider", "system_config_by_number", "to_system_config"] - ); - return Err(RpcError::LocalUsageError(Box::new(e))); - } - }; + let block = self.block_by_number(number).await?; + let sys_config = to_system_config(&block, &rollup_config) + .map_err(|e| RpcError::LocalUsageError(Box::new(e)))?; self.system_config_by_number_cache.put(number, sys_config); Ok(sys_config) } diff --git a/crates/derive-alloy/src/beacon_client.rs b/crates/derive-alloy/src/beacon_client.rs index e4336c999..0447b9290 100644 --- a/crates/derive-alloy/src/beacon_client.rs +++ b/crates/derive-alloy/src/beacon_client.rs @@ -103,45 +103,13 @@ impl BeaconClient for OnlineBeaconClient { type Error = reqwest::Error; async fn config_spec(&self) -> Result { - crate::inc!(PROVIDER_CALLS, &["beacon_client", "config_spec"]); - crate::timer!(START, PROVIDER_RESPONSE_TIME, &["beacon_client", "config_spec"], timer); - let first = match self.inner.get(format!("{}/{}", self.base, SPEC_METHOD)).send().await { - Ok(response) => response, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!(PROVIDER_ERRORS, &["beacon_client", "config_spec", "request"]); - return Err(e); - } - }; - match first.json::().await { - Ok(response) => Ok(response), - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!(PROVIDER_ERRORS, &["beacon_client", "config_spec", "decode"]); - Err(e) - } - } + let first = self.inner.get(format!("{}/{}", self.base, SPEC_METHOD)).send().await?; + first.json::().await } async fn beacon_genesis(&self) -> Result { - crate::inc!(PROVIDER_CALLS, &["beacon_client", "beacon_genesis"]); - crate::timer!(START, PROVIDER_RESPONSE_TIME, &["beacon_client", "beacon_genesis"], timer); - let first = match self.inner.get(format!("{}/{}", self.base, GENESIS_METHOD)).send().await { - Ok(response) => response, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!(PROVIDER_ERRORS, &["beacon_client", "beacon_genesis", "request"]); - return Err(e); - } - }; - match first.json::().await { - Ok(response) => Ok(response), - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!(PROVIDER_ERRORS, &["beacon_client", "beacon_genesis", "decode"]); - Err(e) - } - } + let first = self.inner.get(format!("{}/{}", self.base, GENESIS_METHOD)).send().await?; + first.json::().await } async fn beacon_blob_side_cars( @@ -149,41 +117,15 @@ impl BeaconClient for OnlineBeaconClient { slot: u64, hashes: &[IndexedBlobHash], ) -> Result, Self::Error> { - crate::inc!(PROVIDER_CALLS, &["beacon_client", "beacon_blob_side_cars"]); - crate::timer!( - START, - PROVIDER_RESPONSE_TIME, - &["beacon_client", "beacon_blob_side_cars"], - timer - ); - let raw_response = match self + let raw_response = self .inner .get(format!("{}/{}/{}", self.base, SIDECARS_METHOD_PREFIX, slot)) .send() - .await - { - Ok(response) => response, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["beacon_client", "beacon_blob_side_cars", "request"] - ); - return Err(e); - } - }; - let raw_response = match raw_response.json::().await { - Ok(response) => response, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!(PROVIDER_ERRORS, &["beacon_client", "beacon_blob_side_cars", "decode"]); - return Err(e); - } - }; - - let mut sidecars = Vec::with_capacity(hashes.len()); + .await?; + let raw_response = raw_response.json::().await?; // Filter the sidecars by the hashes, in-order. + let mut sidecars = Vec::with_capacity(hashes.len()); hashes.iter().for_each(|hash| { if let Some(sidecar) = raw_response.data.iter().find(|sidecar| sidecar.index == hash.index as u64) diff --git a/crates/derive-alloy/src/blob_provider.rs b/crates/derive-alloy/src/blob_provider.rs index 37fab8bcb..d87e19567 100644 --- a/crates/derive-alloy/src/blob_provider.rs +++ b/crates/derive-alloy/src/blob_provider.rs @@ -72,8 +72,14 @@ impl OnlineBlobProvider { } /// Computes the slot for the given timestamp. - pub fn slot(genesis: u64, slot_time: u64, timestamp: u64) -> Result { - crate::ensure!(timestamp >= genesis, BlobProviderError::SlotDerivation); + pub const fn slot( + genesis: u64, + slot_time: u64, + timestamp: u64, + ) -> Result { + if timestamp < genesis { + return Err(BlobProviderError::SlotDerivation); + } Ok((timestamp - genesis) / slot_time) } @@ -136,31 +142,15 @@ where block_ref: &BlockInfo, blob_hashes: &[IndexedBlobHash], ) -> Result>, Self::Error> { - crate::inc!(PROVIDER_CALLS, &["blob_provider", "get_blobs"]); - crate::timer!(START, PROVIDER_RESPONSE_TIME, &["blob_provider", "get_blobs"], timer); // Fetches the genesis timestamp and slot interval from the // [BeaconGenesis] and [ConfigSpec] if not previously loaded. - if let Err(e) = self.load_configs().await { - crate::timer!(DISCARD, timer); - crate::inc!(PROVIDER_ERRORS, &["blob_provider", "get_blobs", "load_configs"]); - return Err(e); - } + self.load_configs().await?; // Fetch the blob sidecars for the given block reference and blob hashes. - let sidecars = match self.fetch_filtered_sidecars(block_ref, blob_hashes).await { - Ok(sidecars) => sidecars, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!( - PROVIDER_ERRORS, - &["blob_provider", "get_blobs", "fetch_filtered_sidecars"] - ); - return Err(e); - } - }; + let sidecars = self.fetch_filtered_sidecars(block_ref, blob_hashes).await?; // Validate the blob sidecars straight away with the num hashes. - let blobs = match sidecars + let blobs = sidecars .into_iter() .enumerate() .map(|(i, sidecar)| { @@ -176,15 +166,7 @@ where } }) .collect::>, BlobProviderError>>() - { - Ok(blobs) => blobs, - Err(e) => { - crate::timer!(DISCARD, timer); - crate::inc!(PROVIDER_ERRORS, &["blob_provider", "get_blobs", "verify_blob"]); - return Err(BlobProviderError::Backend(e.to_string())); - } - }; - + .map_err(|e| BlobProviderError::Backend(e.to_string()))?; Ok(blobs) } } @@ -311,7 +293,6 @@ where match self.primary.get_blobs(block_ref, blob_hashes).await { Ok(blobs) => Ok(blobs), Err(primary_err) => { - crate::inc!(PROVIDER_ERRORS, &["blob_provider", "get_blobs", "primary"]); warn!(target: "blob_provider", "Primary provider failed: {:?}", primary_err); // Fetch the blob sidecars for the given block reference and blob hashes. @@ -320,16 +301,12 @@ where Ok(sidecars) => sidecars, Err(e) => { warn!(target: "blob_provider", "Fallback provider failed: {:?}", e); - crate::inc!( - PROVIDER_ERRORS, - &["blob_provider", "get_blobs", "fallback_fetch_filtered_sidecars"] - ); return Err(e); } }; // Validate the blob sidecars straight away with the num hashes. - let blobs = match sidecars + let blobs = sidecars .into_iter() .enumerate() .map(|(i, sidecar)| { @@ -344,18 +321,7 @@ where Err(e) => Err(BlobProviderError::Backend(e.to_string())), } }) - .collect::>, BlobProviderError>>() - { - Ok(blobs) => blobs, - Err(e) => { - crate::inc!( - PROVIDER_ERRORS, - &["blob_provider", "get_blobs", "fallback_verify_blob"] - ); - return Err(e); - } - }; - + .collect::>, BlobProviderError>>()?; Ok(blobs) } } diff --git a/crates/derive-alloy/src/lib.rs b/crates/derive-alloy/src/lib.rs index 1076f62ff..fa3bdbed0 100644 --- a/crates/derive-alloy/src/lib.rs +++ b/crates/derive-alloy/src/lib.rs @@ -6,13 +6,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] -mod macros; - -#[cfg(feature = "metrics")] -pub mod metrics; -#[cfg(feature = "metrics")] -pub use metrics::*; - #[cfg(any(test, feature = "test-utils"))] pub mod test_utils; #[cfg(any(test, feature = "test-utils"))] diff --git a/crates/derive-alloy/src/macros.rs b/crates/derive-alloy/src/macros.rs deleted file mode 100644 index 05b606a13..000000000 --- a/crates/derive-alloy/src/macros.rs +++ /dev/null @@ -1,71 +0,0 @@ -//! Macros for use across derive. - -/// Ensure inlines a branch check. -#[macro_export] -macro_rules! ensure { - ($cond:expr, $msg:expr) => { - if !$cond { - return Err($msg.into()); - } - }; -} - -/// Starts the timer with a label value. -#[macro_export] -macro_rules! timer { - (START, $metric:ident, $labels:expr, $timer:ident) => { - #[cfg(feature = "metrics")] - let $timer = $crate::metrics::$metric.with_label_values($labels).start_timer(); - }; - (DISCARD, $timer:ident) => { - #[cfg(feature = "metrics")] - $timer.stop_and_discard(); - }; - (STOP, $timer:ident) => { - #[cfg(feature = "metrics")] - $timer.stop_and_record(); - }; -} - -/// Increments a metric with a label value. -#[macro_export] -macro_rules! inc { - ($metric:ident) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.inc(); - }; - ($metric:ident, $labels:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.with_label_values($labels).inc(); - }; - ($metric:ident, $value:expr, $labels:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.with_label_values($labels).add($value); - }; -} - -/// Observes a metric with a label value. -#[macro_export] -macro_rules! observe { - ($metric:ident, $value:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.observe($value); - }; - ($metric:ident, $value:expr, $labels:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.with_label_values($label).observe($value); - }; -} - -/// Sets a metric value. -#[macro_export] -macro_rules! set { - ($metric:ident, $value:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.set($value); - }; - ($metric:ident, $value:expr, $labels:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.with_label_values($labels).set($value as f64); - }; -} diff --git a/crates/derive-alloy/src/metrics.rs b/crates/derive-alloy/src/metrics.rs deleted file mode 100644 index 1b9b641b5..000000000 --- a/crates/derive-alloy/src/metrics.rs +++ /dev/null @@ -1,35 +0,0 @@ -//! Metrics for providers. - -use lazy_static::lazy_static; -use prometheus::{self, register_counter_vec, register_histogram_vec, CounterVec, HistogramVec}; -use std::{boxed::Box, string::String}; - -const RESPONSE_TIME_CUSTOM_BUCKETS: &[f64; 18] = &[ - 0.00001, 0.00005, 0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.008, 0.01, 0.02, 0.05, 0.08, - 0.1, 0.2, 0.5, 0.8, 1.0, -]; - -lazy_static! { - /// Tracks the number of provider method calls. - pub static ref PROVIDER_CALLS: CounterVec = register_counter_vec!( - "kona_derive_provider_calls", - "Number of provider method calls", - &["provider", "method"] - ).expect("Provider Calls failed to register"); - - /// Tracks the number of errors in provider methods. - pub static ref PROVIDER_ERRORS: CounterVec = register_counter_vec!( - "kona_derive_provider_errors", - "Number of provider errors", - &["provider", "method", "error"] - ).expect("Provider Errors failed to register"); - - /// Tracks the time taken for provider methods. - pub static ref PROVIDER_RESPONSE_TIME: HistogramVec = register_histogram_vec!( - "kona_derive_provider_response_time_seconds", - "Provider response times", - &["provider", "method"], - RESPONSE_TIME_CUSTOM_BUCKETS.to_vec() - ) - .expect("Failed to register histogram vec"); -}