From 3facd0897f4beca2181f9532a24b7636e1573f6c Mon Sep 17 00:00:00 2001 From: Erwan Date: Fri, 2 Feb 2024 15:31:45 -0500 Subject: [PATCH 1/3] penumbra: update metrics crate --- crates/bin/pclientd/Cargo.toml | 2 +- crates/bin/pd/Cargo.toml | 2 +- crates/cnidarium/Cargo.toml | 2 +- crates/core/app/Cargo.toml | 2 +- crates/core/component/community-pool/Cargo.toml | 2 +- crates/core/component/compact-block/Cargo.toml | 2 +- crates/core/component/dex/Cargo.toml | 2 +- crates/core/component/fee/Cargo.toml | 2 +- crates/core/component/governance/Cargo.toml | 2 +- crates/core/component/ibc/Cargo.toml | 2 +- crates/core/component/sct/Cargo.toml | 2 +- crates/core/component/shielded-pool/Cargo.toml | 2 +- crates/core/component/stake/Cargo.toml | 2 +- crates/util/tendermint-proxy/Cargo.toml | 2 +- crates/view/Cargo.toml | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/bin/pclientd/Cargo.toml b/crates/bin/pclientd/Cargo.toml index 1b7bdc0b99..deb1d98516 100644 --- a/crates/bin/pclientd/Cargo.toml +++ b/crates/bin/pclientd/Cargo.toml @@ -45,7 +45,7 @@ bytes = { version = "1", features = ["serde"] } prost = "0.12.3" futures = "0.3" hex = "0.4" -metrics = "0.19.0" +metrics = "0.22" async-stream = "0.2" parking_lot = "0.12" clap = { version = "3", features = ["derive", "env"] } diff --git a/crates/bin/pd/Cargo.toml b/crates/bin/pd/Cargo.toml index 6b113ec17e..a8aa21315e 100644 --- a/crates/bin/pd/Cargo.toml +++ b/crates/bin/pd/Cargo.toml @@ -106,7 +106,7 @@ hex = "0.4" rand = "0.8" rand_chacha = "0.3.1" rand_core = { version = "0.6.3", features = ["getrandom"] } -metrics = "0.19.0" +metrics = "0.22" metrics-exporter-prometheus = { version = "0.10.0", features = [ "http-listener", ] } diff --git a/crates/cnidarium/Cargo.toml b/crates/cnidarium/Cargo.toml index f7cacb37e4..784372c896 100644 --- a/crates/cnidarium/Cargo.toml +++ b/crates/cnidarium/Cargo.toml @@ -21,7 +21,7 @@ tracing = "0.1" rocksdb = "0.21.0" futures = "0.3" hex = "0.4" -metrics = { version = "0.19.0", optional = true } +metrics = { version = "0.22", optional = true } parking_lot = "0.12" pin-project = "1.0.12" smallvec = { version = "1.10", features = ["union", "const_generics"] } diff --git a/crates/core/app/Cargo.toml b/crates/core/app/Cargo.toml index 9c7a2451f2..83f1c4247e 100644 --- a/crates/core/app/Cargo.toml +++ b/crates/core/app/Cargo.toml @@ -51,7 +51,7 @@ blake2b_simd = "0.5" bincode = "1.3.3" serde = { version = "1", features = ["derive"] } serde_with = "2.2" -metrics = "0.19.0" +metrics = "0.22" sha2 = "0.9" serde_json = "1" serde_unit_struct = "0.1" diff --git a/crates/core/component/community-pool/Cargo.toml b/crates/core/component/community-pool/Cargo.toml index d151c5f1a7..f173aee129 100644 --- a/crates/core/component/community-pool/Cargo.toml +++ b/crates/core/component/community-pool/Cargo.toml @@ -35,7 +35,7 @@ anyhow = "1" tracing = "0.1" prost = "0.12.3" serde = { version = "1", features = ["derive"] } -metrics = "0.19.0" +metrics = "0.22" pbjson-types = "0.6.0" tendermint = "0.34.0" tendermint-light-client-verifier = "0.34.0" diff --git a/crates/core/component/compact-block/Cargo.toml b/crates/core/component/compact-block/Cargo.toml index 5cb13743b4..d6e82653c2 100644 --- a/crates/core/component/compact-block/Cargo.toml +++ b/crates/core/component/compact-block/Cargo.toml @@ -38,7 +38,7 @@ penumbra-sct = { path = "../sct", default-features = false } # Crates.io dependencies ark-ff = { version = "0.4", default_features = false } decaf377-rdsa = { version = "0.7" } -metrics = "0.19.0" +metrics = "0.22" serde = { version = "1", features = ["derive"] } tracing = "0.1" anyhow = "1" diff --git a/crates/core/component/dex/Cargo.toml b/crates/core/component/dex/Cargo.toml index 34eec7beaf..b79058d190 100644 --- a/crates/core/component/dex/Cargo.toml +++ b/crates/core/component/dex/Cargo.toml @@ -67,7 +67,7 @@ tracing = "0.1" prost = "0.12.3" serde = { version = "1", features = ["derive"] } serde_json = "1.0.96" -metrics = "0.19.0" +metrics = "0.22" pbjson-types = "0.6.0" tendermint = "0.34.0" tendermint-light-client-verifier = "0.34.0" diff --git a/crates/core/component/fee/Cargo.toml b/crates/core/component/fee/Cargo.toml index 5225194b6c..24dc4e392c 100644 --- a/crates/core/component/fee/Cargo.toml +++ b/crates/core/component/fee/Cargo.toml @@ -30,7 +30,7 @@ decaf377 = { version = "0.5" } # Crates.io dependencies ark-ff = { version = "0.4", default_features = false } -metrics = "0.19.0" +metrics = "0.22" serde = { version = "1", features = ["derive"] } tracing = "0.1" anyhow = "1" diff --git a/crates/core/component/governance/Cargo.toml b/crates/core/component/governance/Cargo.toml index 8402f18418..ce5ffce044 100644 --- a/crates/core/component/governance/Cargo.toml +++ b/crates/core/component/governance/Cargo.toml @@ -61,7 +61,7 @@ ark-serialize = "0.4" ark-groth16 = { version = "0.4", default-features = false } ark-snark = "0.4" async-stream = "0.2" -metrics = "0.19.0" +metrics = "0.22" serde = { version = "1", features = ["derive"] } tracing = "0.1" anyhow = "1" diff --git a/crates/core/component/ibc/Cargo.toml b/crates/core/component/ibc/Cargo.toml index 7834c75192..19b27f780a 100644 --- a/crates/core/component/ibc/Cargo.toml +++ b/crates/core/component/ibc/Cargo.toml @@ -40,7 +40,7 @@ tracing = "0.1" prost = "0.12.3" serde = { version = "1", features = ["derive"] } serde_json = "1" -metrics = "0.19.0" +metrics = "0.22" pbjson-types = "0.6.0" tendermint = "0.34.0" tendermint-light-client-verifier = "0.34.0" diff --git a/crates/core/component/sct/Cargo.toml b/crates/core/component/sct/Cargo.toml index 2e5dc9f511..7fba9c2bb5 100644 --- a/crates/core/component/sct/Cargo.toml +++ b/crates/core/component/sct/Cargo.toml @@ -35,7 +35,7 @@ ark-r1cs-std = { version = "0.4", default-features = false } ark-relations = "0.4" ark-ff = { version = "0.4", default_features = false } ark-serialize = "0.4" -metrics = "0.19.0" +metrics = "0.22" serde = { version = "1", features = ["derive"] } tracing = "0.1" anyhow = "1" diff --git a/crates/core/component/shielded-pool/Cargo.toml b/crates/core/component/shielded-pool/Cargo.toml index ea7accec4a..2388d7b5e4 100644 --- a/crates/core/component/shielded-pool/Cargo.toml +++ b/crates/core/component/shielded-pool/Cargo.toml @@ -61,7 +61,7 @@ ark-ff = { version = "0.4", default_features = false } ark-serialize = "0.4" ark-groth16 = { version = "0.4", default-features = false } ark-snark = "0.4" -metrics = "0.19.0" +metrics = "0.22" prost = "0.12.3" serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/crates/core/component/stake/Cargo.toml b/crates/core/component/stake/Cargo.toml index 1dcdd598d2..af025bdab4 100644 --- a/crates/core/component/stake/Cargo.toml +++ b/crates/core/component/stake/Cargo.toml @@ -82,7 +82,7 @@ tokio = { version = "1.21.1", features = ["full", "tracing"], optional = true } tonic = { version = "0.10", optional = true } im = { version = "15.1.0", optional = true } futures = { version = "0.3", optional = true } -metrics = { version = "0.19.0", optional = true } +metrics = { version = "0.22", optional = true } async-stream = { version = "0.3.5", optional = true } [dev-dependencies] diff --git a/crates/util/tendermint-proxy/Cargo.toml b/crates/util/tendermint-proxy/Cargo.toml index b04b7df199..826c51a8a6 100644 --- a/crates/util/tendermint-proxy/Cargo.toml +++ b/crates/util/tendermint-proxy/Cargo.toml @@ -16,7 +16,7 @@ chrono = { version = "0.4", default-features = false, features = ["serde"] } futures = "0.3" hex = "0.4" http = "0.2" -metrics = "0.19.0" +metrics = "0.22" pbjson-types = "0.6" pin-project = "1" pin-project-lite = "0.2.9" diff --git a/crates/view/Cargo.toml b/crates/view/Cargo.toml index 5190fd76c2..3a6192ef35 100644 --- a/crates/view/Cargo.toml +++ b/crates/view/Cargo.toml @@ -58,7 +58,7 @@ bytes = { version = "1", features = ["serde"] } prost = "0.12.3" futures = "0.3" hex = "0.4" -metrics = "0.19.0" +metrics = "0.22" async-stream = "0.2" parking_lot = "0.12" camino = "1" From e8ed83be229572fb51e60591082e892bb4679861 Mon Sep 17 00:00:00 2001 From: Erwan Date: Fri, 2 Feb 2024 15:47:12 -0500 Subject: [PATCH 2/3] penumbra: propagate `metrics@0.22` api changes --- Cargo.lock | 52 ++++++++++++------- crates/bin/pd/src/mempool.rs | 12 +---- crates/bin/pd/src/metrics.rs | 1 - crates/cnidarium/src/metrics.rs | 2 - crates/cnidarium/src/snapshot.rs | 9 ++-- .../compact-block/src/component/metrics.rs | 5 -- .../compact-block/src/component/rpc.rs | 10 ++-- .../dex/src/component/action_handler/swap.rs | 2 +- .../core/component/dex/src/component/arb.rs | 2 +- .../core/component/dex/src/component/dex.rs | 2 +- .../component/dex/src/component/metrics.rs | 5 -- .../dex/src/component/router/fill_route.rs | 2 +- .../dex/src/component/router/path_search.rs | 2 +- crates/core/component/stake/src/component.rs | 37 ++++++------- .../component/stake/src/component/metrics.rs | 6 --- 15 files changed, 69 insertions(+), 80 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06cbc4700f..15bd2fbcc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1496,7 +1496,7 @@ dependencies = [ "ibc-types", "ics23", "jmt", - "metrics", + "metrics 0.22.0", "once_cell", "parking_lot 0.12.1", "pbjson 0.5.1", @@ -4062,6 +4062,16 @@ dependencies = [ "metrics-macros", ] +[[package]] +name = "metrics" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77b9e10a211c839210fd7f99954bda26e5f8e26ec686ad68da6a32df7c80e782" +dependencies = [ + "ahash 0.8.7", + "portable-atomic", +] + [[package]] name = "metrics-exporter-prometheus" version = "0.10.0" @@ -4071,7 +4081,7 @@ dependencies = [ "hyper", "indexmap 1.9.3", "ipnet", - "metrics", + "metrics 0.19.0", "metrics-util", "parking_lot 0.11.2", "quanta", @@ -4099,7 +4109,7 @@ checksum = "91c0b6603313b4625101251a1c0749df7deef27ab410d430d79f2fcb9d8480aa" dependencies = [ "itoa", "lockfree-object-pool", - "metrics", + "metrics 0.19.0", "metrics-util", "once_cell", "tracing", @@ -4119,7 +4129,7 @@ dependencies = [ "crossbeam-utils", "hashbrown 0.11.2", "indexmap 1.9.3", - "metrics", + "metrics 0.19.0", "num_cpus", "ordered-float", "parking_lot 0.11.2", @@ -4695,7 +4705,7 @@ dependencies = [ "http-body", "ibc-proto", "ibc-types", - "metrics", + "metrics 0.22.0", "parking_lot 0.12.1", "penumbra-app", "penumbra-asset", @@ -4758,7 +4768,7 @@ dependencies = [ "ibc-types", "ics23", "jmt", - "metrics", + "metrics 0.22.0", "metrics-exporter-prometheus", "metrics-tracing-context", "metrics-util", @@ -4884,7 +4894,7 @@ dependencies = [ "ibc-types", "im", "jmt", - "metrics", + "metrics 0.22.0", "once_cell", "parking_lot 0.12.1", "penumbra-asset", @@ -5032,7 +5042,7 @@ dependencies = [ "cnidarium-component", "futures", "hex", - "metrics", + "metrics 0.22.0", "once_cell", "pbjson-types", "penumbra-asset", @@ -5065,7 +5075,7 @@ dependencies = [ "decaf377-rdsa", "futures", "im", - "metrics", + "metrics 0.22.0", "penumbra-community-pool", "penumbra-dex", "penumbra-fee", @@ -5146,7 +5156,7 @@ dependencies = [ "hex", "im", "itertools 0.11.0", - "metrics", + "metrics 0.22.0", "once_cell", "parking_lot 0.12.1", "pbjson-types", @@ -5227,7 +5237,7 @@ dependencies = [ "cnidarium-component", "decaf377 0.5.0", "decaf377-rdsa", - "metrics", + "metrics 0.22.0", "penumbra-asset", "penumbra-num", "penumbra-proto", @@ -5283,7 +5293,7 @@ dependencies = [ "futures", "ibc-types", "im", - "metrics", + "metrics 0.22.0", "once_cell", "pbjson-types", "penumbra-asset", @@ -5328,7 +5338,7 @@ dependencies = [ "ibc-proto", "ibc-types", "ics23", - "metrics", + "metrics 0.22.0", "num-traits", "once_cell", "pbjson-types", @@ -5557,7 +5567,7 @@ dependencies = [ "decaf377-rdsa", "hex", "im", - "metrics", + "metrics 0.22.0", "once_cell", "penumbra-keys", "penumbra-proto", @@ -5596,7 +5606,7 @@ dependencies = [ "hex", "ibc-types", "im", - "metrics", + "metrics 0.22.0", "once_cell", "penumbra-asset", "penumbra-ibc", @@ -5644,7 +5654,7 @@ dependencies = [ "futures", "hex", "im", - "metrics", + "metrics 0.22.0", "once_cell", "penumbra-asset", "penumbra-community-pool", @@ -5754,7 +5764,7 @@ dependencies = [ "futures", "hex", "http", - "metrics", + "metrics 0.22.0", "pbjson-types", "penumbra-proto", "penumbra-transaction", @@ -5878,7 +5888,7 @@ dependencies = [ "genawaiter", "hex", "ibc-types", - "metrics", + "metrics 0.22.0", "once_cell", "parking_lot 0.12.1", "penumbra-app", @@ -6145,6 +6155,12 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "portable-atomic" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" + [[package]] name = "poseidon-parameters" version = "0.4.0" diff --git a/crates/bin/pd/src/mempool.rs b/crates/bin/pd/src/mempool.rs index cf82bd8708..2754740115 100644 --- a/crates/bin/pd/src/mempool.rs +++ b/crates/bin/pd/src/mempool.rs @@ -60,11 +60,7 @@ impl Mempool { Ok(events) => { let elapsed = start.elapsed(); tracing::info!(?elapsed, "tx accepted"); - metrics::increment_counter!( - metrics::MEMPOOL_CHECKTX_TOTAL, - "kind" => kind_str, - "code" => "0" - ); + metrics::counter!(metrics::MEMPOOL_CHECKTX_TOTAL, "kind" => kind_str, "code" => "0").increment(1); Ok(Response::CheckTx(CheckTxRsp { events, ..Default::default() @@ -73,11 +69,7 @@ impl Mempool { Err(e) => { let elapsed = start.elapsed(); tracing::info!(?e, ?elapsed, "tx rejected"); - metrics::increment_counter!( - metrics::MEMPOOL_CHECKTX_TOTAL, - "kind" => kind_str, - "code" => "1" - ); + metrics::counter!(metrics::MEMPOOL_CHECKTX_TOTAL, "kind" => kind_str, "code" => "1").increment(1); Ok(Response::CheckTx(CheckTxRsp { code: 1.into(), // Use the alternate format specifier to include the chain of error causes. diff --git a/crates/bin/pd/src/metrics.rs b/crates/bin/pd/src/metrics.rs index 7e8d337213..989f3e2cef 100644 --- a/crates/bin/pd/src/metrics.rs +++ b/crates/bin/pd/src/metrics.rs @@ -21,7 +21,6 @@ pub fn register_metrics() { // This will register metrics for all components. penumbra_app::register_metrics(); - register_counter!(MEMPOOL_CHECKTX_TOTAL); describe_counter!( MEMPOOL_CHECKTX_TOTAL, Unit::Count, diff --git a/crates/cnidarium/src/metrics.rs b/crates/cnidarium/src/metrics.rs index 5242bffa52..4eef4590dc 100644 --- a/crates/cnidarium/src/metrics.rs +++ b/crates/cnidarium/src/metrics.rs @@ -16,13 +16,11 @@ pub use metrics::*; /// Registers all metrics used by this crate. pub fn register_metrics() { - register_histogram!(STORAGE_GET_RAW_DURATION); describe_histogram!( STORAGE_GET_RAW_DURATION, Unit::Seconds, "The duration of a get_raw request" ); - register_histogram!(STORAGE_NONCONSENSUS_GET_RAW_DURATION); describe_histogram!( STORAGE_NONCONSENSUS_GET_RAW_DURATION, Unit::Seconds, diff --git a/crates/cnidarium/src/snapshot.rs b/crates/cnidarium/src/snapshot.rs index 277785ed38..706215e41c 100644 --- a/crates/cnidarium/src/snapshot.rs +++ b/crates/cnidarium/src/snapshot.rs @@ -232,7 +232,8 @@ impl StateRead for Snapshot { let _start = std::time::Instant::now(); let rsp = substore.get_jmt(key_hash); #[cfg(feature = "metrics")] - metrics::histogram!(metrics::STORAGE_GET_RAW_DURATION, _start.elapsed()); + metrics::histogram!(metrics::STORAGE_GET_RAW_DURATION) + .record(_start.elapsed()); rsp }) }) @@ -273,10 +274,8 @@ impl StateRead for Snapshot { .get_cf(cf_nonverifiable, key) .map_err(Into::into); #[cfg(feature = "metrics")] - metrics::histogram!( - metrics::STORAGE_NONCONSENSUS_GET_RAW_DURATION, - _start.elapsed() - ); + metrics::histogram!(metrics::STORAGE_NONCONSENSUS_GET_RAW_DURATION) + .record(_start.elapsed()); rsp }) }) diff --git a/crates/core/component/compact-block/src/component/metrics.rs b/crates/core/component/compact-block/src/component/metrics.rs index a2cab35bdf..a07c0702bd 100644 --- a/crates/core/component/compact-block/src/component/metrics.rs +++ b/crates/core/component/compact-block/src/component/metrics.rs @@ -17,14 +17,12 @@ pub use metrics::*; /// /// The source code contains the metrics descriptions. pub fn register_metrics() { - register_gauge!(COMPACT_BLOCK_RANGE_ACTIVE_CONNECTIONS); describe_gauge!( COMPACT_BLOCK_RANGE_ACTIVE_CONNECTIONS, Unit::Count, "The number of active connections streaming compact blocks" ); - register_counter!(COMPACT_BLOCK_RANGE_SERVED_TOTAL); describe_counter!( COMPACT_BLOCK_RANGE_SERVED_TOTAL, Unit::Count, @@ -32,9 +30,6 @@ pub fn register_metrics() { ); } -// Sample code for reference -- delete when adding the first metric -// pub const MEMPOOL_CHECKTX_TOTAL: &str = "penumbra_pd_mempool_checktx_total"; - pub const COMPACT_BLOCK_RANGE_ACTIVE_CONNECTIONS: &str = "cnidarium_component_compact_block_compact_block_range_active_connections"; diff --git a/crates/core/component/compact-block/src/component/rpc.rs b/crates/core/component/compact-block/src/component/rpc.rs index 9a15ddc6fa..79f25e5e84 100644 --- a/crates/core/component/compact-block/src/component/rpc.rs +++ b/crates/core/component/compact-block/src/component/rpc.rs @@ -143,7 +143,7 @@ impl QueryService for Server { // outside of the `send_op` future, and investigate if long blocking sends can // happen for benign reasons (i.e not caused by the client). tx_blocks.send(Ok(compact_block.into())).await?; - metrics::increment_counter!(metrics::COMPACT_BLOCK_RANGE_SERVED_TOTAL,); + metrics::counter!(metrics::COMPACT_BLOCK_RANGE_SERVED_TOTAL).increment(1); } // If the client didn't request a keep-alive, we're done. @@ -175,7 +175,7 @@ impl QueryService for Server { .send(Ok(block.into())) .await .map_err(|_| tonic::Status::cancelled("client closed connection"))?; - metrics::increment_counter!(metrics::COMPACT_BLOCK_RANGE_SERVED_TOTAL,); + metrics::counter!(metrics::COMPACT_BLOCK_RANGE_SERVED_TOTAL).increment(1); } // Ensure that we don't hold a reference to the snapshot indefinitely @@ -204,7 +204,7 @@ impl QueryService for Server { .send(Ok(block.into())) .await .map_err(|_| tonic::Status::cancelled("channel closed"))?; - metrics::increment_counter!(metrics::COMPACT_BLOCK_RANGE_SERVED_TOTAL,); + metrics::counter!(metrics::COMPACT_BLOCK_RANGE_SERVED_TOTAL).increment(1); } } .map_err(|e| async move { @@ -240,13 +240,13 @@ struct CompactBlockConnectionCounter {} impl CompactBlockConnectionCounter { pub fn new() -> Self { - metrics::increment_gauge!(metrics::COMPACT_BLOCK_RANGE_ACTIVE_CONNECTIONS, 1.0); + metrics::gauge!(metrics::COMPACT_BLOCK_RANGE_ACTIVE_CONNECTIONS).increment(1.0); CompactBlockConnectionCounter {} } } impl Drop for CompactBlockConnectionCounter { fn drop(&mut self) { - metrics::decrement_gauge!(metrics::COMPACT_BLOCK_RANGE_ACTIVE_CONNECTIONS, 1.0); + metrics::gauge!(metrics::COMPACT_BLOCK_RANGE_ACTIVE_CONNECTIONS).decrement(1.0); } } diff --git a/crates/core/component/dex/src/component/action_handler/swap.rs b/crates/core/component/dex/src/component/action_handler/swap.rs index fd5c87b7a1..30791079ef 100644 --- a/crates/core/component/dex/src/component/action_handler/swap.rs +++ b/crates/core/component/dex/src/component/action_handler/swap.rs @@ -62,7 +62,7 @@ impl ActionHandler for Swap { .await; metrics::histogram!( - crate::component::metrics::DEX_SWAP_DURATION, + crate::component::metrics::DEX_SWAP_DURATION).record( swap_start.elapsed() ); state.record_proto(event::swap(self)); diff --git a/crates/core/component/dex/src/component/arb.rs b/crates/core/component/dex/src/component/arb.rs index 8f3b3006e3..7dc8a2e375 100644 --- a/crates/core/component/dex/src/component/arb.rs +++ b/crates/core/component/dex/src/component/arb.rs @@ -130,7 +130,7 @@ pub trait Arbitrage: StateWrite + Sized { }, ); metrics::histogram!( - crate::component::metrics::DEX_ARB_DURATION, + crate::component::metrics::DEX_ARB_DURATION).record( arb_start.elapsed() ); return Ok(Value { diff --git a/crates/core/component/dex/src/component/dex.rs b/crates/core/component/dex/src/component/dex.rs index 19025973a4..17b9e1fca2 100644 --- a/crates/core/component/dex/src/component/dex.rs +++ b/crates/core/component/dex/src/component/dex.rs @@ -64,7 +64,7 @@ impl Component for Dex { .await .expect("handling batch swaps is infaillible"); metrics::histogram!( - crate::component::metrics::DEX_BATCH_DURATION, + crate::component::metrics::DEX_BATCH_DURATION).record( batch_start.elapsed() ); } diff --git a/crates/core/component/dex/src/component/metrics.rs b/crates/core/component/dex/src/component/metrics.rs index b3b8f813f4..547707ba17 100644 --- a/crates/core/component/dex/src/component/metrics.rs +++ b/crates/core/component/dex/src/component/metrics.rs @@ -15,31 +15,26 @@ pub use metrics::*; /// Registers all metrics used by this crate. pub fn register_metrics() { - register_histogram!(DEX_ARB_DURATION); describe_histogram!( DEX_ARB_DURATION, Unit::Seconds, "The time spent computing arbitrage during endblock phase" ); - register_histogram!(DEX_BATCH_DURATION); describe_histogram!( DEX_BATCH_DURATION, Unit::Seconds, "The time spent executing batches within the DEX" ); - register_histogram!(DEX_PATH_SEARCH_DURATION); describe_histogram!( DEX_PATH_SEARCH_DURATION, Unit::Seconds, "The time spent searching for paths while executing trades within the DEX" ); - register_histogram!(DEX_ROUTE_FILL_DURATION); describe_histogram!( DEX_ROUTE_FILL_DURATION, Unit::Seconds, "The time spent filling routes while executing trades within the DEX" ); - register_histogram!(DEX_SWAP_DURATION); describe_histogram!( DEX_SWAP_DURATION, Unit::Seconds, diff --git a/crates/core/component/dex/src/component/router/fill_route.rs b/crates/core/component/dex/src/component/router/fill_route.rs index 7cee801309..c0e08fde2f 100644 --- a/crates/core/component/dex/src/component/router/fill_route.rs +++ b/crates/core/component/dex/src/component/router/fill_route.rs @@ -256,7 +256,7 @@ async fn fill_route_inner( this.apply(); let fill_elapsed = fill_start.elapsed(); - metrics::histogram!(metrics::DEX_ROUTE_FILL_DURATION, fill_elapsed); + metrics::histogram!(metrics::DEX_ROUTE_FILL_DURATION).record(fill_elapsed); // cleanup / finalization Ok(swap_execution) } diff --git a/crates/core/component/dex/src/component/router/path_search.rs b/crates/core/component/dex/src/component/router/path_search.rs index 59280fc854..223567bfb3 100644 --- a/crates/core/component/dex/src/component/router/path_search.rs +++ b/crates/core/component/dex/src/component/router/path_search.rs @@ -55,7 +55,7 @@ pub trait PathSearch: StateRead + Clone + 'static { let spill_price = spill.map(|p| p.price); tracing::debug!(price = %path.price, spill_price = %spill_price.unwrap_or_else(|| 0u64.into()), ?src, ?nodes, "found path"); metrics::histogram!( - crate::component::metrics::DEX_PATH_SEARCH_DURATION, + crate::component::metrics::DEX_PATH_SEARCH_DURATION).record( path_start.elapsed() ); diff --git a/crates/core/component/stake/src/component.rs b/crates/core/component/stake/src/component.rs index 1d5a8aa5f0..f6177b4624 100644 --- a/crates/core/component/stake/src/component.rs +++ b/crates/core/component/stake/src/component.rs @@ -206,7 +206,7 @@ pub(crate) trait StakingImpl: StateWriteExt { // Finally, set the validator to be active. self.put(state_key, Active); - metrics::gauge!(metrics::MISSED_BLOCKS, 0.0, "identity_key" => identity_key.to_string()); + metrics::gauge!(metrics::MISSED_BLOCKS, "identity_key" => identity_key.to_string()); tracing::debug!(validator_identity = %identity_key, voting_power = ?power, "validator has become active"); } @@ -229,7 +229,7 @@ pub(crate) trait StakingImpl: StateWriteExt { self.put(state_key, new_state); - metrics::gauge!(metrics::MISSED_BLOCKS, 0.0, "identity_key" => identity_key.to_string()); + metrics::gauge!(metrics::MISSED_BLOCKS, "identity_key" => identity_key.to_string()); } (Jailed, Inactive) => { // After getting jailed, a validator can be released from jail when its operator @@ -353,20 +353,20 @@ pub(crate) trait StakingImpl: StateWriteExt { // Update the validator metrics once the state transition has been applied. match old_state { - Defined => metrics::decrement_gauge!(metrics::DEFINED_VALIDATORS, 1.0), - Inactive => metrics::decrement_gauge!(metrics::INACTIVE_VALIDATORS, 1.0), - Active => metrics::decrement_gauge!(metrics::ACTIVE_VALIDATORS, 1.0), - Disabled => metrics::decrement_gauge!(metrics::DISABLED_VALIDATORS, 1.0), - Jailed => metrics::decrement_gauge!(metrics::JAILED_VALIDATORS, 1.0), - Tombstoned => metrics::decrement_gauge!(metrics::TOMBSTONED_VALIDATORS, 1.0), + Defined => metrics::gauge!(metrics::DEFINED_VALIDATORS).decrement(1.0), + Inactive => metrics::gauge!(metrics::INACTIVE_VALIDATORS).decrement(1.0), + Active => metrics::gauge!(metrics::ACTIVE_VALIDATORS).decrement(1.0), + Disabled => metrics::gauge!(metrics::DISABLED_VALIDATORS).decrement(1.0), + Jailed => metrics::gauge!(metrics::JAILED_VALIDATORS).decrement(1.0), + Tombstoned => metrics::gauge!(metrics::TOMBSTONED_VALIDATORS).decrement(1.0), }; match new_state { - Defined => metrics::increment_gauge!(metrics::DEFINED_VALIDATORS, 1.0), - Inactive => metrics::increment_gauge!(metrics::INACTIVE_VALIDATORS, 1.0), - Active => metrics::increment_gauge!(metrics::ACTIVE_VALIDATORS, 1.0), - Disabled => metrics::increment_gauge!(metrics::DISABLED_VALIDATORS, 1.0), - Jailed => metrics::increment_gauge!(metrics::JAILED_VALIDATORS, 1.0), - Tombstoned => metrics::increment_gauge!(metrics::TOMBSTONED_VALIDATORS, 1.0), + Defined => metrics::gauge!(metrics::DEFINED_VALIDATORS).increment(1.0), + Inactive => metrics::gauge!(metrics::INACTIVE_VALIDATORS).increment(1.0), + Active => metrics::gauge!(metrics::ACTIVE_VALIDATORS).increment(1.0), + Disabled => metrics::gauge!(metrics::DISABLED_VALIDATORS).increment(1.0), + Jailed => metrics::gauge!(metrics::JAILED_VALIDATORS).increment(1.0), + Tombstoned => metrics::gauge!(metrics::TOMBSTONED_VALIDATORS).increment(1.0), }; Ok(()) @@ -934,7 +934,8 @@ pub(crate) trait StakingImpl: StateWriteExt { ?params.missed_blocks_maximum, "recorded vote info" ); - metrics::gauge!(metrics::MISSED_BLOCKS, uptime.num_missed_blocks() as f64, "identity_key" => identity_key.to_string()); + metrics::gauge!(metrics::MISSED_BLOCKS, "identity_key" => identity_key.to_string()) + .increment(uptime.num_missed_blocks() as f64); uptime.mark_height_as_signed(height, voted)?; if uptime.num_missed_blocks() as u64 >= params.missed_blocks_maximum { @@ -1697,15 +1698,15 @@ pub trait StateWriteExt: StateWrite { // Finally, update metrics for the new validator. match initial_state { validator::State::Active => { - metrics::increment_gauge!(metrics::ACTIVE_VALIDATORS, 1.0); + metrics::gauge!(metrics::ACTIVE_VALIDATORS).increment(1.0); } validator::State::Defined => { - metrics::increment_gauge!(metrics::DEFINED_VALIDATORS, 1.0); + metrics::gauge!(metrics::DEFINED_VALIDATORS).increment(1.0); } _ => unreachable!("the initial state was validated by the guard condition"), }; - metrics::gauge!(metrics::MISSED_BLOCKS, 0.0, "identity_key" => id.to_string()); + metrics::gauge!(metrics::MISSED_BLOCKS, "identity_key" => id.to_string()); Ok(()) } diff --git a/crates/core/component/stake/src/component/metrics.rs b/crates/core/component/stake/src/component/metrics.rs index 60f9b57878..2aa501bf68 100644 --- a/crates/core/component/stake/src/component/metrics.rs +++ b/crates/core/component/stake/src/component/metrics.rs @@ -15,37 +15,31 @@ pub use metrics::*; /// Registers all metrics used by this crate. pub fn register_metrics() { - register_gauge!(MISSED_BLOCKS); describe_gauge!( MISSED_BLOCKS, Unit::Count, "The number of missed blocks per validator" ); - register_gauge!(ACTIVE_VALIDATORS); describe_gauge!( ACTIVE_VALIDATORS, Unit::Count, "The number of active validators" ); - register_gauge!(INACTIVE_VALIDATORS); describe_gauge!( INACTIVE_VALIDATORS, Unit::Count, "The number of inactive validators" ); - register_gauge!(JAILED_VALIDATORS); describe_gauge!( JAILED_VALIDATORS, Unit::Count, "The number of jailed validators" ); - register_gauge!(DISABLED_VALIDATORS); describe_gauge!( DISABLED_VALIDATORS, Unit::Count, "The number of disabled validators" ); - register_gauge!(TOMBSTONED_VALIDATORS); describe_gauge!( TOMBSTONED_VALIDATORS, Unit::Count, From 100278cfb7b251f1e1e66c0efb7cc5e7b5857f5d Mon Sep 17 00:00:00 2001 From: Erwan Date: Tue, 6 Feb 2024 11:33:46 -0500 Subject: [PATCH 3/3] penumbra: `cargo fmt` --- .../core/component/dex/src/component/action_handler/swap.rs | 6 ++---- crates/core/component/dex/src/component/arb.rs | 6 ++---- crates/core/component/dex/src/component/dex.rs | 6 ++---- .../core/component/dex/src/component/router/path_search.rs | 6 ++---- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/crates/core/component/dex/src/component/action_handler/swap.rs b/crates/core/component/dex/src/component/action_handler/swap.rs index 30791079ef..87823df77a 100644 --- a/crates/core/component/dex/src/component/action_handler/swap.rs +++ b/crates/core/component/dex/src/component/action_handler/swap.rs @@ -61,10 +61,8 @@ impl ActionHandler for Swap { .add_swap_payload(self.body.payload.clone(), source) .await; - metrics::histogram!( - crate::component::metrics::DEX_SWAP_DURATION).record( - swap_start.elapsed() - ); + metrics::histogram!(crate::component::metrics::DEX_SWAP_DURATION) + .record(swap_start.elapsed()); state.record_proto(event::swap(self)); Ok(()) diff --git a/crates/core/component/dex/src/component/arb.rs b/crates/core/component/dex/src/component/arb.rs index 7dc8a2e375..0b053af03b 100644 --- a/crates/core/component/dex/src/component/arb.rs +++ b/crates/core/component/dex/src/component/arb.rs @@ -129,10 +129,8 @@ pub trait Arbitrage: StateWrite + Sized { }, }, ); - metrics::histogram!( - crate::component::metrics::DEX_ARB_DURATION).record( - arb_start.elapsed() - ); + metrics::histogram!(crate::component::metrics::DEX_ARB_DURATION) + .record(arb_start.elapsed()); return Ok(Value { amount: arb_profit, asset_id: arb_token, diff --git a/crates/core/component/dex/src/component/dex.rs b/crates/core/component/dex/src/component/dex.rs index 17b9e1fca2..212978aaf8 100644 --- a/crates/core/component/dex/src/component/dex.rs +++ b/crates/core/component/dex/src/component/dex.rs @@ -63,10 +63,8 @@ impl Component for Dex { ) .await .expect("handling batch swaps is infaillible"); - metrics::histogram!( - crate::component::metrics::DEX_BATCH_DURATION).record( - batch_start.elapsed() - ); + metrics::histogram!(crate::component::metrics::DEX_BATCH_DURATION) + .record(batch_start.elapsed()); } // Then, perform arbitrage: diff --git a/crates/core/component/dex/src/component/router/path_search.rs b/crates/core/component/dex/src/component/router/path_search.rs index 223567bfb3..b98567491e 100644 --- a/crates/core/component/dex/src/component/router/path_search.rs +++ b/crates/core/component/dex/src/component/router/path_search.rs @@ -54,10 +54,8 @@ pub trait PathSearch: StateRead + Clone + 'static { let nodes = path.nodes; let spill_price = spill.map(|p| p.price); tracing::debug!(price = %path.price, spill_price = %spill_price.unwrap_or_else(|| 0u64.into()), ?src, ?nodes, "found path"); - metrics::histogram!( - crate::component::metrics::DEX_PATH_SEARCH_DURATION).record( - path_start.elapsed() - ); + metrics::histogram!(crate::component::metrics::DEX_PATH_SEARCH_DURATION) + .record(path_start.elapsed()); match price_limit { // Note: previously, this branch was a load-bearing termination condition, primarily