diff --git a/Cargo.lock b/Cargo.lock index 8c1f7b638e..d774d0bcea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1342,6 +1342,31 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "aws-lc-rs" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f409eb70b561706bf8abba8ca9c112729c481595893fd06a2dd9af8ed8441148" +dependencies = [ + "aws-lc-sys", + "paste", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "923ded50f602b3007e5e63e3f094c479d9c8a9b42d7f4034e4afe456aa48bfd2" +dependencies = [ + "bindgen 0.69.5", + "cc", + "cmake", + "dunce", + "fs_extra", + "paste", +] + [[package]] name = "axum" version = "0.6.20" @@ -2745,6 +2770,15 @@ dependencies = [ "bitflags 1.2.1", ] +[[package]] +name = "cmake" +version = "0.1.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e" +dependencies = [ + "cc", +] + [[package]] name = "coins-bip32" version = "0.8.7" @@ -2984,6 +3018,16 @@ dependencies = [ "libc", ] +[[package]] +name = "core-foundation" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -4269,6 +4313,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -5111,9 +5161,27 @@ dependencies = [ "hyper 0.14.32", "log", "rustls 0.21.12", - "rustls-native-certs", + "rustls-native-certs 0.6.3", + "tokio", + "tokio-rustls 0.24.1", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" +dependencies = [ + "futures-util", + "http 1.2.0", + "hyper 1.5.2", + "hyper-util", + "rustls 0.23.20", + "rustls-native-certs 0.8.1", + "rustls-pki-types", "tokio", - "tokio-rustls", + "tokio-rustls 0.26.1", + "tower-service", ] [[package]] @@ -5376,7 +5444,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdf9d64cfcf380606e64f9a0bcf493616b65331199f984151a6fa11a7b3cde38" dependencies = [ "async-io 2.4.0", - "core-foundation", + "core-foundation 0.9.4", "fnv", "futures", "if-addrs", @@ -5720,11 +5788,11 @@ dependencies = [ "http 0.2.12", "jsonrpsee-core", "pin-project", - "rustls-native-certs", + "rustls-native-certs 0.6.3", "soketto", "thiserror 1.0.69", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tokio-util", "tracing", "url", @@ -5765,7 +5833,7 @@ checksum = "57c7b9f95208927653e7965a98525e7fc641781cab89f0e27c43fa2974405683" dependencies = [ "async-trait", "hyper 0.14.32", - "hyper-rustls", + "hyper-rustls 0.24.2", "jsonrpsee-core", "jsonrpsee-types", "serde", @@ -6741,20 +6809,19 @@ dependencies = [ [[package]] name = "metrics" -version = "0.21.1" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fde3af1a009ed76a778cb84fdef9e7dbbdf5775ae3e4cc1f434a6a307f6f76c5" +checksum = "2be3cbd384d4e955b231c895ce10685e3d8260c5ccffae898c96c723b0772835" dependencies = [ "ahash", - "metrics-macros", "portable-atomic", ] [[package]] name = "metrics" -version = "0.22.3" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2be3cbd384d4e955b231c895ce10685e3d8260c5ccffae898c96c723b0772835" +checksum = "7a7deb012b3b2767169ff203fadb4c6b0b82b947512e5eb9e0b78c2e186ad9e3" dependencies = [ "ahash", "portable-atomic", @@ -6762,15 +6829,18 @@ dependencies = [ [[package]] name = "metrics-exporter-prometheus" -version = "0.12.2" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d4fa7ce7c4862db464a37b0b31d89bca874562f034bd7993895572783d02950" +checksum = "12779523996a67c13c84906a876ac6fe4d07a6e1adb54978378e13f199251a62" dependencies = [ - "base64 0.21.7", - "hyper 0.14.32", - "indexmap 1.9.3", + "base64 0.22.1", + "http-body-util", + "hyper 1.5.2", + "hyper-rustls 0.27.5", + "hyper-util", + "indexmap 2.7.0", "ipnet", - "metrics 0.21.1", + "metrics 0.24.1", "metrics-util", "quanta", "thiserror 1.0.69", @@ -6778,17 +6848,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "metrics-macros" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b4faf00617defe497754acde3024865bc143d44a86799b24e191ecff91354f" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.95", -] - [[package]] name = "metrics-process" version = "1.2.1" @@ -6806,16 +6865,17 @@ dependencies = [ [[package]] name = "metrics-util" -version = "0.15.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "111cb375987443c3de8d503580b536f77dc8416d32db62d9456db5d93bd7ac47" +checksum = "dbd4884b1dd24f7d6628274a2f5ae22465c337c5ba065ec9b6edccddf8acc673" dependencies = [ "crossbeam-epoch", "crossbeam-utils", - "hashbrown 0.13.2", - "metrics 0.21.1", - "num_cpus", + "hashbrown 0.15.2", + "metrics 0.24.1", "quanta", + "rand 0.8.5", + "rand_xoshiro", "sketches-ddsketch", ] @@ -7031,7 +7091,7 @@ dependencies = [ "openssl-probe", "openssl-sys", "schannel", - "security-framework", + "security-framework 2.11.1", "security-framework-sys", "tempfile", ] @@ -7643,7 +7703,7 @@ dependencies = [ "futures", "lazy_static", "lru", - "metrics 0.21.1", + "metrics 0.24.1", "mockall", "nix 0.20.2", "papyrus_common", @@ -7752,7 +7812,7 @@ version = "0.0.0" dependencies = [ "axum", "hyper 0.14.32", - "metrics 0.21.1", + "metrics 0.24.1", "metrics-exporter-prometheus", "metrics-process", "papyrus_config", @@ -7784,7 +7844,7 @@ dependencies = [ "lazy_static", "libp2p", "libp2p-swarm-test", - "metrics 0.21.1", + "metrics 0.24.1", "mockall", "papyrus_common", "papyrus_config", @@ -7868,7 +7928,7 @@ dependencies = [ "futures", "indexmap 2.7.0", "lazy_static", - "metrics 0.21.1", + "metrics 0.24.1", "papyrus_common", "papyrus_config", "papyrus_network", @@ -7893,7 +7953,7 @@ dependencies = [ name = "papyrus_proc_macros" version = "0.0.0" dependencies = [ - "metrics 0.21.1", + "metrics 0.24.1", "metrics-exporter-prometheus", "papyrus_common", "papyrus_test_utils", @@ -7949,7 +8009,7 @@ dependencies = [ "jsonrpsee", "jsonschema", "lazy_static", - "metrics 0.21.1", + "metrics 0.24.1", "metrics-exporter-prometheus", "mockall", "papyrus_common", @@ -8008,7 +8068,7 @@ dependencies = [ "lazy_static", "libmdbx", "memmap2", - "metrics 0.21.1", + "metrics 0.24.1", "metrics-exporter-prometheus", "num-bigint 0.4.6", "num-traits", @@ -8056,7 +8116,7 @@ dependencies = [ "indexmap 2.7.0", "itertools 0.12.1", "lru", - "metrics 0.21.1", + "metrics 0.24.1", "mockall", "papyrus_base_layer", "papyrus_common", @@ -8882,13 +8942,12 @@ dependencies = [ [[package]] name = "quanta" -version = "0.11.1" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17e662a7a8291a865152364c20c7abc5e60486ab2001e8ec10b24862de0b9ab" +checksum = "3bd1fe6824cea6538803de3ff1bc0cf3949024db3d43c9643024bfb33a807c0e" dependencies = [ "crossbeam-utils", "libc", - "mach2", "once_cell", "raw-cpuid", "wasi", @@ -9161,13 +9220,22 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand_xoshiro" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" +dependencies = [ + "rand_core 0.6.4", +] + [[package]] name = "raw-cpuid" -version = "10.7.0" +version = "11.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332" +checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" dependencies = [ - "bitflags 1.2.1", + "bitflags 2.6.0", ] [[package]] @@ -9317,7 +9385,7 @@ dependencies = [ "http 0.2.12", "http-body 0.4.6", "hyper 0.14.32", - "hyper-rustls", + "hyper-rustls 0.24.2", "hyper-tls 0.5.0", "ipnet", "js-sys", @@ -9336,7 +9404,7 @@ dependencies = [ "system-configuration 0.5.1", "tokio", "tokio-native-tls", - "tokio-rustls", + "tokio-rustls 0.24.1", "tokio-util", "tower-service", "url", @@ -9734,6 +9802,7 @@ version = "0.23.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b" dependencies = [ + "aws-lc-rs", "log", "once_cell", "ring 0.17.8", @@ -9752,7 +9821,19 @@ dependencies = [ "openssl-probe", "rustls-pemfile 1.0.4", "schannel", - "security-framework", + "security-framework 2.11.1", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcff2dd52b58a8d98a70243663a0d234c4e2b79235637849d15913394a247d3" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework 3.2.0", ] [[package]] @@ -9798,6 +9879,7 @@ version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ + "aws-lc-rs", "ring 0.17.8", "rustls-pki-types", "untrusted 0.9.0", @@ -9963,7 +10045,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ "bitflags 2.6.0", - "core-foundation", + "core-foundation 0.9.4", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316" +dependencies = [ + "bitflags 2.6.0", + "core-foundation 0.10.0", "core-foundation-sys", "libc", "security-framework-sys", @@ -10285,9 +10380,9 @@ checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "sketches-ddsketch" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85636c14b73d81f541e525f585c0a2109e6744e1565b5c1668e31c70c10ed65c" +checksum = "c1e9a774a6c28142ac54bb25d25562e6bcf957493a184f15ad4eebccb23e410a" [[package]] name = "slab" @@ -10807,7 +10902,7 @@ dependencies = [ "hyper 0.14.32", "jsonrpsee", "mempool_test_utils", - "metrics 0.21.1", + "metrics 0.24.1", "metrics-exporter-prometheus", "papyrus_config", "reqwest 0.11.27", @@ -11002,7 +11097,7 @@ version = "0.0.0" dependencies = [ "axum", "hyper 0.14.32", - "metrics 0.21.1", + "metrics 0.24.1", "metrics-exporter-prometheus", "num-traits", "papyrus_config", @@ -11359,7 +11454,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ "bitflags 1.2.1", - "core-foundation", + "core-foundation 0.9.4", "system-configuration-sys 0.5.0", ] @@ -11370,7 +11465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ "bitflags 2.6.0", - "core-foundation", + "core-foundation 0.9.4", "system-configuration-sys 0.6.0", ] @@ -11760,6 +11855,16 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37" +dependencies = [ + "rustls 0.23.20", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.17" @@ -11795,7 +11900,7 @@ dependencies = [ "log", "rustls 0.21.12", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tungstenite", "webpki-roots 0.25.4", ] diff --git a/Cargo.toml b/Cargo.toml index c925d77af0..6dfbc2de49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -149,8 +149,8 @@ log = "0.4" lru = "0.12.0" memmap2 = "0.8.0" mempool_test_utils = { path = "crates/mempool_test_utils", version = "0.0.0" } -metrics = "0.21.0" -metrics-exporter-prometheus = "0.12.1" +metrics = "0.24.1" +metrics-exporter-prometheus = "0.16.1" metrics-process = "1.0.11" mockall = "0.12.1" mockito = "1.4.0" diff --git a/crates/papyrus_monitoring_gateway/src/gateway_test.rs b/crates/papyrus_monitoring_gateway/src/gateway_test.rs index a075bca640..4cd356c6ab 100644 --- a/crates/papyrus_monitoring_gateway/src/gateway_test.rs +++ b/crates/papyrus_monitoring_gateway/src/gateway_test.rs @@ -5,7 +5,7 @@ use axum::body::Body; use axum::http::{Request, StatusCode}; use axum::response::Response; use axum::Router; -use metrics::{absolute_counter, describe_counter, register_counter}; +use metrics::{counter, describe_counter}; use metrics_exporter_prometheus::PrometheusBuilder; use papyrus_storage::{table_names, test_utils}; use pretty_assertions::assert_eq; @@ -182,9 +182,8 @@ async fn with_metrics() { let metric_name = "metric_name"; let metric_help = "metric_help"; let metric_value = 8224; - register_counter!(metric_name); + counter!(metric_name).absolute(metric_value); describe_counter!(metric_name, metric_help); - absolute_counter!(metric_name, metric_value); let response = request_app(app, "metrics").await; diff --git a/crates/papyrus_network/src/network_manager/mod.rs b/crates/papyrus_network/src/network_manager/mod.rs index f9602ac55e..df129e4d90 100644 --- a/crates/papyrus_network/src/network_manager/mod.rs +++ b/crates/papyrus_network/src/network_manager/mod.rs @@ -99,7 +99,7 @@ impl GenericNetworkManager { // TODO(shahak): remove the advertised_multiaddr arg once we manage external addresses // in a behaviour. pub(crate) fn generic_new(mut swarm: SwarmT, advertised_multiaddr: Option) -> Self { - gauge!(papyrus_metrics::PAPYRUS_NUM_CONNECTED_PEERS, 0f64); + gauge!(papyrus_metrics::PAPYRUS_NUM_CONNECTED_PEERS).set(0f64); let reported_peer_receivers = FuturesUnordered::new(); reported_peer_receivers.push(futures::future::pending().boxed()); if let Some(address) = advertised_multiaddr.clone() { @@ -268,10 +268,8 @@ impl GenericNetworkManager { match event { SwarmEvent::ConnectionEstablished { peer_id, .. } => { debug!("Connected to peer id: {peer_id:?}"); - gauge!( - papyrus_metrics::PAPYRUS_NUM_CONNECTED_PEERS, - self.swarm.num_connected_peers() as f64 - ); + gauge!(papyrus_metrics::PAPYRUS_NUM_CONNECTED_PEERS) + .set(self.swarm.num_connected_peers() as f64); } SwarmEvent::ConnectionClosed { peer_id, cause, .. } => { match cause { @@ -280,10 +278,8 @@ impl GenericNetworkManager { } None => debug!("Connection to {peer_id:?} closed."), } - gauge!( - papyrus_metrics::PAPYRUS_NUM_CONNECTED_PEERS, - self.swarm.num_connected_peers() as f64 - ); + gauge!(papyrus_metrics::PAPYRUS_NUM_CONNECTED_PEERS) + .set(self.swarm.num_connected_peers() as f64); } SwarmEvent::Behaviour(event) => { self.handle_behaviour_event(event)?; @@ -405,10 +401,8 @@ impl GenericNetworkManager { query: Vec, ) { self.num_active_inbound_sessions += 1; - gauge!( - papyrus_metrics::PAPYRUS_NUM_ACTIVE_INBOUND_SESSIONS, - self.num_active_inbound_sessions as f64 - ); + gauge!(papyrus_metrics::PAPYRUS_NUM_ACTIVE_INBOUND_SESSIONS) + .set(self.num_active_inbound_sessions as f64); let (report_sender, report_receiver) = oneshot::channel::<()>(); self.handle_new_report_receiver(peer_id, report_receiver); // TODO: consider returning error instead of panic. @@ -572,10 +566,8 @@ impl GenericNetworkManager { outbound_session_id: {outbound_session_id:?}" ); self.num_active_outbound_sessions += 1; - gauge!( - papyrus_metrics::PAPYRUS_NUM_ACTIVE_OUTBOUND_SESSIONS, - self.num_active_outbound_sessions as f64 - ); + gauge!(papyrus_metrics::PAPYRUS_NUM_ACTIVE_OUTBOUND_SESSIONS) + .set(self.num_active_outbound_sessions as f64); self.sqmr_outbound_response_senders.insert(outbound_session_id, responses_sender); self.sqmr_outbound_report_receivers_awaiting_assignment .insert(outbound_session_id, report_receiver); @@ -598,17 +590,13 @@ impl GenericNetworkManager { match session_id { SessionId::InboundSessionId(_) => { self.num_active_inbound_sessions -= 1; - gauge!( - papyrus_metrics::PAPYRUS_NUM_ACTIVE_INBOUND_SESSIONS, - self.num_active_inbound_sessions as f64 - ); + gauge!(papyrus_metrics::PAPYRUS_NUM_ACTIVE_INBOUND_SESSIONS) + .set(self.num_active_inbound_sessions as f64); } SessionId::OutboundSessionId(_) => { self.num_active_outbound_sessions += 1; - gauge!( - papyrus_metrics::PAPYRUS_NUM_ACTIVE_OUTBOUND_SESSIONS, - self.num_active_outbound_sessions as f64 - ); + gauge!(papyrus_metrics::PAPYRUS_NUM_ACTIVE_OUTBOUND_SESSIONS) + .set(self.num_active_outbound_sessions as f64); } } } diff --git a/crates/papyrus_p2p_sync/src/client/header.rs b/crates/papyrus_p2p_sync/src/client/header.rs index c74948ea95..578b1c47de 100644 --- a/crates/papyrus_p2p_sync/src/client/header.rs +++ b/crates/papyrus_p2p_sync/src/client/header.rs @@ -44,9 +44,8 @@ impl BlockData for SignedBlockHeader { .expect("Vec::first should return a value on a vector of size 1"), )? .commit()?; - gauge!( - papyrus_metrics::PAPYRUS_HEADER_MARKER, - self.block_header.block_header_without_hash.block_number.unchecked_next().0 as f64 + gauge!(papyrus_metrics::PAPYRUS_HEADER_MARKER).set( + self.block_header.block_header_without_hash.block_number.unchecked_next().0 as f64, ); // TODO(shahak): Fix code dup with central sync let time_delta = Utc::now() @@ -57,7 +56,7 @@ impl BlockData for SignedBlockHeader { let header_latency = time_delta.num_seconds(); debug!("Header latency: {}.", header_latency); if header_latency >= 0 { - gauge!(papyrus_metrics::PAPYRUS_HEADER_LATENCY_SEC, header_latency as f64); + gauge!(papyrus_metrics::PAPYRUS_HEADER_LATENCY_SEC).set(header_latency as f64); } Ok(()) } diff --git a/crates/papyrus_p2p_sync/src/client/state_diff.rs b/crates/papyrus_p2p_sync/src/client/state_diff.rs index 362daca121..5b3de1037b 100644 --- a/crates/papyrus_p2p_sync/src/client/state_diff.rs +++ b/crates/papyrus_p2p_sync/src/client/state_diff.rs @@ -31,7 +31,7 @@ impl BlockData for (ThinStateDiff, BlockNumber) { storage_writer: &mut StorageWriter, ) -> Result<(), StorageError> { storage_writer.begin_rw_txn()?.append_state_diff(self.1, self.0)?.commit()?; - gauge!(papyrus_metrics::PAPYRUS_STATE_MARKER, self.1.unchecked_next().0 as f64); + gauge!(papyrus_metrics::PAPYRUS_STATE_MARKER).set(self.1.unchecked_next().0 as f64); Ok(()) } } diff --git a/crates/papyrus_proc_macros/src/lib.rs b/crates/papyrus_proc_macros/src/lib.rs index 5f7a02d4d7..d03a4acf3f 100644 --- a/crates/papyrus_proc_macros/src/lib.rs +++ b/crates/papyrus_proc_macros/src/lib.rs @@ -166,7 +166,7 @@ pub fn latency_histogram(attr: TokenStream, input: TokenStream) -> TokenStream { let return_value=#origin_block; if let Some(start_time) = start_function_time { let exec_time = start_time.elapsed().as_secs_f64(); - metrics::histogram!(#metric_name, exec_time); + metrics::histogram!(#metric_name).record(exec_time); tracing::debug!("{}: {}", #metric_name, exec_time); } return_value diff --git a/crates/papyrus_rpc/src/rpc_metrics/mod.rs b/crates/papyrus_rpc/src/rpc_metrics/mod.rs index a5098f80e9..6e565670d1 100644 --- a/crates/papyrus_rpc/src/rpc_metrics/mod.rs +++ b/crates/papyrus_rpc/src/rpc_metrics/mod.rs @@ -8,7 +8,7 @@ use std::time::Instant; use jsonrpsee::server::logger::{HttpRequest, Logger, MethodKind, TransportProtocol}; use jsonrpsee::types::Params; use jsonrpsee::Methods; -use metrics::{histogram, increment_counter, register_counter, register_histogram}; +use metrics::{counter, histogram}; // Name of the metrics. const INCOMING_REQUEST: &str = "rpc_incoming_requests"; @@ -23,14 +23,15 @@ const ILLEGAL_METHOD: &str = "illegal_method"; // Register the metrics and returns a set of the method names. fn init_metrics(methods: &Methods) -> HashSet { let mut methods_set: HashSet = HashSet::new(); - register_counter!(INCOMING_REQUEST, METHOD_LABEL => ILLEGAL_METHOD); - register_counter!(FAILED_REQUESTS, METHOD_LABEL => ILLEGAL_METHOD); + counter!(INCOMING_REQUEST, METHOD_LABEL => ILLEGAL_METHOD).absolute(0); + counter!(FAILED_REQUESTS, METHOD_LABEL => ILLEGAL_METHOD).absolute(0); for method in methods.method_names() { methods_set.insert(method.to_string()); let (method_name, version) = get_method_and_version(method); - register_counter!(FAILED_REQUESTS, METHOD_LABEL => method_name.clone(), VERSION_LABEL => version.clone()); - register_counter!(INCOMING_REQUEST, METHOD_LABEL => method_name.clone(), VERSION_LABEL => version.clone()); - register_histogram!(REQUEST_LATENCY, METHOD_LABEL => method_name, VERSION_LABEL => version); + counter!(FAILED_REQUESTS, METHOD_LABEL => method_name.clone(), VERSION_LABEL => version.clone()).absolute(0); + counter!(INCOMING_REQUEST, METHOD_LABEL => method_name.clone(), VERSION_LABEL => version.clone()).absolute(0); + histogram!(REQUEST_LATENCY, METHOD_LABEL => method_name, VERSION_LABEL => version) + .record(0); } methods_set } @@ -61,14 +62,15 @@ impl Logger for MetricLogger { if self.methods_set.contains(method_name) { let (method, version) = get_method_and_version(method_name); if let jsonrpsee::helpers::MethodResponseResult::Failed(_) = success_or_error { - increment_counter!(FAILED_REQUESTS, METHOD_LABEL=> method.clone(), VERSION_LABEL=> version.clone()); + counter!(FAILED_REQUESTS, METHOD_LABEL=> method.clone(), VERSION_LABEL=> version.clone()).increment(1); } - increment_counter!(INCOMING_REQUEST, METHOD_LABEL=> method.clone(), VERSION_LABEL=> version.clone()); + counter!(INCOMING_REQUEST, METHOD_LABEL=> method.clone(), VERSION_LABEL=> version.clone()).increment(1); let latency = started_at.elapsed().as_secs_f64(); - histogram!(REQUEST_LATENCY, latency,METHOD_LABEL=> method, VERSION_LABEL=> version); + histogram!(REQUEST_LATENCY, METHOD_LABEL=> method, VERSION_LABEL=> version) + .record(latency); } else { - increment_counter!(INCOMING_REQUEST, METHOD_LABEL => ILLEGAL_METHOD); - increment_counter!(FAILED_REQUESTS, METHOD_LABEL => ILLEGAL_METHOD); + counter!(INCOMING_REQUEST, METHOD_LABEL => ILLEGAL_METHOD).increment(1); + counter!(FAILED_REQUESTS, METHOD_LABEL => ILLEGAL_METHOD).increment(1); } } diff --git a/crates/papyrus_storage/src/storage_metrics.rs b/crates/papyrus_storage/src/storage_metrics.rs index 8e6fd114b6..82b0ab0210 100644 --- a/crates/papyrus_storage/src/storage_metrics.rs +++ b/crates/papyrus_storage/src/storage_metrics.rs @@ -3,7 +3,7 @@ #[path = "storage_metrics_test.rs"] mod storage_metrics_test; -use metrics::{absolute_counter, gauge}; +use metrics::{counter, gauge}; use tracing::debug; use crate::{StorageReader, StorageResult}; @@ -17,15 +17,11 @@ use crate::{StorageReader, StorageResult}; #[allow(clippy::as_conversions)] pub fn update_storage_metrics(reader: &StorageReader) -> StorageResult<()> { debug!("updating storage metrics"); - gauge!("storage_free_pages_number", reader.db_reader.get_free_pages()? as f64); + gauge!("storage_free_pages_number").set(reader.db_reader.get_free_pages()? as f64); let info = reader.db_reader.get_db_info()?; - absolute_counter!( - "storage_last_page_number", - u64::try_from(info.last_pgno()).expect("usize should fit in u64") - ); - absolute_counter!( - "storage_last_transaction_index", - u64::try_from(info.last_txnid()).expect("usize should fit in u64") - ); + counter!("storage_last_page_number") + .absolute(u64::try_from(info.last_pgno()).expect("usize should fit in u64")); + counter!("storage_last_transaction_index") + .absolute(u64::try_from(info.last_txnid()).expect("usize should fit in u64")); Ok(()) } diff --git a/crates/papyrus_sync/src/lib.rs b/crates/papyrus_sync/src/lib.rs index b1e1f4165c..c29ef416e7 100644 --- a/crates/papyrus_sync/src/lib.rs +++ b/crates/papyrus_sync/src/lib.rs @@ -424,14 +424,10 @@ impl< .append_block_signature(block_number, signature)? .append_body(block_number, block.body)? .commit()?; - metrics::gauge!( - papyrus_metrics::PAPYRUS_HEADER_MARKER, - block_number.unchecked_next().0 as f64 - ); - metrics::gauge!( - papyrus_metrics::PAPYRUS_BODY_MARKER, - block_number.unchecked_next().0 as f64 - ); + metrics::gauge!(papyrus_metrics::PAPYRUS_HEADER_MARKER) + .set(block_number.unchecked_next().0 as f64); + metrics::gauge!(papyrus_metrics::PAPYRUS_BODY_MARKER) + .set(block_number.unchecked_next().0 as f64); let time_delta = Utc::now() - Utc .timestamp_opt(block.header.block_header_without_hash.timestamp.0 as i64, 0) @@ -440,7 +436,7 @@ impl< let header_latency = time_delta.num_seconds(); debug!("Header latency: {}.", header_latency); if header_latency >= 0 { - metrics::gauge!(papyrus_metrics::PAPYRUS_HEADER_LATENCY_SEC, header_latency as f64); + metrics::gauge!(papyrus_metrics::PAPYRUS_HEADER_LATENCY_SEC).set(header_latency as f64); } Ok(()) } @@ -477,15 +473,11 @@ impl< )? .commit()?; - metrics::gauge!( - papyrus_metrics::PAPYRUS_STATE_MARKER, - block_number.unchecked_next().0 as f64 - ); + metrics::gauge!(papyrus_metrics::PAPYRUS_STATE_MARKER) + .set(block_number.unchecked_next().0 as f64); let compiled_class_marker = self.reader.begin_ro_txn()?.get_compiled_class_marker()?; - metrics::gauge!( - papyrus_metrics::PAPYRUS_COMPILED_CLASS_MARKER, - compiled_class_marker.0 as f64 - ); + metrics::gauge!(papyrus_metrics::PAPYRUS_COMPILED_CLASS_MARKER) + .set(compiled_class_marker.0 as f64); // Info the user on syncing the block once all the data is stored. info!("Added block {} with hash {:#064x}.", block_number, block_hash.0); @@ -509,10 +501,8 @@ impl< txn.commit()?; let compiled_class_marker = self.reader.begin_ro_txn()?.get_compiled_class_marker()?; - metrics::gauge!( - papyrus_metrics::PAPYRUS_COMPILED_CLASS_MARKER, - compiled_class_marker.0 as f64 - ); + metrics::gauge!(papyrus_metrics::PAPYRUS_COMPILED_CLASS_MARKER) + .set(compiled_class_marker.0 as f64); debug!("Added compiled class."); Ok(()) } @@ -554,10 +544,8 @@ impl< if txn.get_base_layer_block_marker()? != block_number.unchecked_next() { info!("Verified block {block_number} hash against base layer."); txn.update_base_layer_block_marker(&block_number.unchecked_next())?.commit()?; - metrics::gauge!( - papyrus_metrics::PAPYRUS_BASE_LAYER_MARKER, - block_number.unchecked_next().0 as f64 - ); + metrics::gauge!(papyrus_metrics::PAPYRUS_BASE_LAYER_MARKER) + .set(block_number.unchecked_next().0 as f64); } Ok(()) } @@ -691,9 +679,7 @@ fn stream_new_blocks< let central_block_marker = latest_central_block.map_or( BlockNumber::default(), |block_hash_and_number| block_hash_and_number.number.unchecked_next() ); - metrics::gauge!( - papyrus_metrics::PAPYRUS_CENTRAL_BLOCK_MARKER, central_block_marker.0 as f64 - ); + metrics::gauge!(papyrus_metrics::PAPYRUS_CENTRAL_BLOCK_MARKER).set(central_block_marker.0 as f64); if header_marker == central_block_marker { // Only if the node have the last block and state (without casms), sync pending data. if collect_pending_data && reader.begin_ro_txn()?.get_state_marker()? == header_marker{ diff --git a/crates/sequencing/papyrus_consensus/src/manager.rs b/crates/sequencing/papyrus_consensus/src/manager.rs index b76e37be0f..b611443caa 100644 --- a/crates/sequencing/papyrus_consensus/src/manager.rs +++ b/crates/sequencing/papyrus_consensus/src/manager.rs @@ -15,6 +15,7 @@ use std::time::Duration; use futures::channel::mpsc; use futures::stream::FuturesUnordered; use futures::StreamExt; +use metrics::counter; use papyrus_common::metrics::{PAPYRUS_CONSENSUS_HEIGHT, PAPYRUS_CONSENSUS_SYNC_COUNT}; use papyrus_network::network_manager::BroadcastTopicClientTrait; use papyrus_network_types::network_types::BroadcastedMessageMetadata; @@ -78,7 +79,7 @@ where let mut manager = MultiHeightManager::new(validator_id, timeouts); #[allow(clippy::as_conversions)] // FIXME: use int metrics so `as f64` may be removed. loop { - metrics::gauge!(PAPYRUS_CONSENSUS_HEIGHT, current_height.0 as f64); + metrics::gauge!(PAPYRUS_CONSENSUS_HEIGHT).set(current_height.0 as f64); let must_observer = current_height < start_active_height; match manager @@ -101,7 +102,7 @@ where } RunHeightRes::Sync(sync_height) => { info!("Sync to height: {}. current_height={}", sync_height, current_height); - metrics::increment_counter!(PAPYRUS_CONSENSUS_SYNC_COUNT); + counter!(PAPYRUS_CONSENSUS_SYNC_COUNT).increment(1); current_height = sync_height.unchecked_next(); } } diff --git a/crates/starknet_http_server/src/metrics.rs b/crates/starknet_http_server/src/metrics.rs index 7c53a4a4ec..8ede5476d1 100644 --- a/crates/starknet_http_server/src/metrics.rs +++ b/crates/starknet_http_server/src/metrics.rs @@ -1,4 +1,4 @@ -use metrics::{absolute_counter, describe_counter, register_counter}; +use metrics::{counter, describe_counter}; use tracing::info; #[cfg(test)] @@ -14,27 +14,24 @@ pub(crate) const ADDED_TRANSACTIONS_FAILURE: (&str, &str, u64) = pub(crate) fn init_metrics() { info!("Initializing HTTP Server metrics"); - register_counter!(ADDED_TRANSACTIONS_TOTAL.0); + counter!(ADDED_TRANSACTIONS_TOTAL.0).absolute(ADDED_TRANSACTIONS_TOTAL.2); describe_counter!(ADDED_TRANSACTIONS_TOTAL.0, ADDED_TRANSACTIONS_TOTAL.1); - absolute_counter!(ADDED_TRANSACTIONS_TOTAL.0, ADDED_TRANSACTIONS_TOTAL.2); - register_counter!(ADDED_TRANSACTIONS_SUCCESS.0); + counter!(ADDED_TRANSACTIONS_SUCCESS.0).absolute(ADDED_TRANSACTIONS_SUCCESS.2); describe_counter!(ADDED_TRANSACTIONS_SUCCESS.0, ADDED_TRANSACTIONS_SUCCESS.1); - absolute_counter!(ADDED_TRANSACTIONS_SUCCESS.0, ADDED_TRANSACTIONS_SUCCESS.2); - register_counter!(ADDED_TRANSACTIONS_FAILURE.0); + counter!(ADDED_TRANSACTIONS_FAILURE.0).absolute(ADDED_TRANSACTIONS_FAILURE.2); describe_counter!(ADDED_TRANSACTIONS_FAILURE.0, ADDED_TRANSACTIONS_FAILURE.1); - absolute_counter!(ADDED_TRANSACTIONS_FAILURE.0, ADDED_TRANSACTIONS_FAILURE.2); } pub(crate) fn record_added_transaction() { - metrics::increment_counter!(ADDED_TRANSACTIONS_TOTAL.0); + counter!(ADDED_TRANSACTIONS_TOTAL.0).increment(1); } pub(crate) fn record_added_transaction_status(add_tx_success: bool) { if add_tx_success { - metrics::increment_counter!(ADDED_TRANSACTIONS_SUCCESS.0); + counter!(ADDED_TRANSACTIONS_SUCCESS.0).increment(1); } else { - metrics::increment_counter!(ADDED_TRANSACTIONS_FAILURE.0); + counter!(ADDED_TRANSACTIONS_FAILURE.0).increment(1); } } diff --git a/crates/starknet_monitoring_endpoint/src/monitoring_endpoint_test.rs b/crates/starknet_monitoring_endpoint/src/monitoring_endpoint_test.rs index e0c222a1d9..9c4e660c87 100644 --- a/crates/starknet_monitoring_endpoint/src/monitoring_endpoint_test.rs +++ b/crates/starknet_monitoring_endpoint/src/monitoring_endpoint_test.rs @@ -5,7 +5,7 @@ use axum::response::Response; use axum::Router; use hyper::body::to_bytes; use hyper::Client; -use metrics::{absolute_counter, describe_counter, register_counter}; +use metrics::{counter, describe_counter}; use pretty_assertions::assert_eq; use tokio::spawn; use tokio::task::yield_now; @@ -63,10 +63,8 @@ async fn with_metrics() { let metric_name = "metric_name"; let metric_help = "metric_help"; let metric_value = 8224; - register_counter!(metric_name); + counter!(metric_name).absolute(metric_value); describe_counter!(metric_name, metric_help); - absolute_counter!(metric_name, metric_value); - let response = request_app(app, METRICS).await; assert_eq!(response.status(), StatusCode::OK); let body_bytes = hyper::body::to_bytes(response.into_body()).await.unwrap();