From 5d79598405e286696470c0b1aed0cd6bc57a8807 Mon Sep 17 00:00:00 2001 From: mertwole Date: Fri, 6 Sep 2024 05:37:41 +0000 Subject: [PATCH] Inline constructors --- relayer/src/ethereum_checkpoints/metrics.rs | 25 +++++++++++++++---- .../common/ethereum_block_listener.rs | 5 +++- .../common/ethereum_message_sender/era.rs | 15 ++++++++--- .../common/ethereum_message_sender/mod.rs | 10 ++++++-- .../common/gear_block_listener.rs | 5 +++- .../common/merkle_root_extractor.rs | 5 +++- .../common/message_paid_event_extractor.rs | 5 +++- .../common/message_queued_event_extractor.rs | 5 +++- .../common/paid_messages_filter.rs | 5 +++- relayer/src/proof_storage/gear.rs | 5 +++- relayer/src/relay_merkle_roots.rs | 22 ++++++++++++---- utils-prometheus/src/lib.rs | 14 ++++++++--- 12 files changed, 95 insertions(+), 26 deletions(-) diff --git a/relayer/src/ethereum_checkpoints/metrics.rs b/relayer/src/ethereum_checkpoints/metrics.rs index 2b41e551..0decf007 100644 --- a/relayer/src/ethereum_checkpoints/metrics.rs +++ b/relayer/src/ethereum_checkpoints/metrics.rs @@ -3,11 +3,26 @@ use utils_prometheus::impl_metered_service; impl_metered_service! { pub struct Updates { - pub fetched_sync_update_slot: IntGauge, - pub total_fetched_finality_updates: IntCounter, - pub processed_finality_updates: IntCounter, - pub processed_committee_updates: IntCounter, - pub account_total_balance: IntGauge, + pub fetched_sync_update_slot: IntGauge = IntGauge::new( + "checkpoints_relayer_fetched_sync_update_slot", + "The slot of the last applied update", + ), + pub total_fetched_finality_updates: IntCounter = IntCounter::new( + "checkpoints_relayer_total_fetched_finality_updates", + "Total amount of fetched finality updates", + ), + pub processed_finality_updates: IntCounter = IntCounter::new( + "checkpoints_relayer_processed_finality_updates", + "Amount of processed finality updates", + ), + pub processed_committee_updates: IntCounter = IntCounter::new( + "checkpoints_relayer_processed_committee_updates", + "Amount of processed committee updates", + ), + pub account_total_balance: IntGauge = IntGauge::new( + "checkpoints_relayer_account_total_balance", + "The total balance of the account used to send messages", + ), } } diff --git a/relayer/src/message_relayer/common/ethereum_block_listener.rs b/relayer/src/message_relayer/common/ethereum_block_listener.rs index a4eb1fa3..618f3646 100644 --- a/relayer/src/message_relayer/common/ethereum_block_listener.rs +++ b/relayer/src/message_relayer/common/ethereum_block_listener.rs @@ -26,7 +26,10 @@ impl MeteredService for EthereumBlockListener { impl_metered_service! { struct Metrics { - latest_block: IntGauge, + latest_block: IntGauge = IntGauge::new( + "ethereum_block_listener_latest_block", + "Latest ethereum block discovered by listener", + ), } } diff --git a/relayer/src/message_relayer/common/ethereum_message_sender/era.rs b/relayer/src/message_relayer/common/ethereum_message_sender/era.rs index 95e56f9b..3c31525c 100644 --- a/relayer/src/message_relayer/common/ethereum_message_sender/era.rs +++ b/relayer/src/message_relayer/common/ethereum_message_sender/era.rs @@ -25,9 +25,18 @@ struct RelayMessagePendingTx { impl_metered_service! { pub struct Metrics { - total_submitted_txs: IntCounter, - total_failed_txs: IntCounter, - total_failed_txs_because_processed: IntCounter, + total_submitted_txs: IntCounter = IntCounter::new( + "ethereum_message_sender_total_submitted_txs", + "Total amount of txs sent to ethereum", + ), + total_failed_txs: IntCounter = IntCounter::new( + "ethereum_message_sender_total_failed_txs", + "Total amount of txs sent to ethereum and failed", + ), + total_failed_txs_because_processed: IntCounter = IntCounter::new( + "ethereum_message_sender_total_failed_txs_because_processed", + "Amount of txs sent to ethereum and failed because they've already been processed", + ), } } diff --git a/relayer/src/message_relayer/common/ethereum_message_sender/mod.rs b/relayer/src/message_relayer/common/ethereum_message_sender/mod.rs index 6e38d6e9..b30423b0 100644 --- a/relayer/src/message_relayer/common/ethereum_message_sender/mod.rs +++ b/relayer/src/message_relayer/common/ethereum_message_sender/mod.rs @@ -35,8 +35,14 @@ impl MeteredService for EthereumMessageSender { impl_metered_service! { struct Metrics { - pending_tx_count: IntGauge, - fee_payer_balance: Gauge + pending_tx_count: IntGauge = IntGauge::new( + "ethereum_message_sender_pending_tx_count", + "Amount of txs pending finalization on ethereum", + ), + fee_payer_balance: Gauge = Gauge::new( + "ethereum_message_sender_fee_payer_balance", + "Transaction fee payer balance", + ) } } diff --git a/relayer/src/message_relayer/common/gear_block_listener.rs b/relayer/src/message_relayer/common/gear_block_listener.rs index fe885454..72af1d15 100644 --- a/relayer/src/message_relayer/common/gear_block_listener.rs +++ b/relayer/src/message_relayer/common/gear_block_listener.rs @@ -26,7 +26,10 @@ impl MeteredService for GearBlockListener { impl_metered_service! { struct Metrics { - latest_block: IntGauge, + latest_block: IntGauge = IntGauge::new( + "gear_block_listener_latest_block", + "Latest gear block discovered by gear block listener", + ) } } diff --git a/relayer/src/message_relayer/common/merkle_root_extractor.rs b/relayer/src/message_relayer/common/merkle_root_extractor.rs index 5e803dd4..17c9c91a 100644 --- a/relayer/src/message_relayer/common/merkle_root_extractor.rs +++ b/relayer/src/message_relayer/common/merkle_root_extractor.rs @@ -23,7 +23,10 @@ impl MeteredService for MerkleRootExtractor { impl_metered_service! { struct Metrics { - latest_merkle_root_for_block: IntGauge + latest_merkle_root_for_block: IntGauge = IntGauge::new( + "merkle_root_extractor_latest_merkle_root_for_block", + "Latest gear block present in found merkle roots", + ) } } diff --git a/relayer/src/message_relayer/common/message_paid_event_extractor.rs b/relayer/src/message_relayer/common/message_paid_event_extractor.rs index 37755e0b..80238a46 100644 --- a/relayer/src/message_relayer/common/message_paid_event_extractor.rs +++ b/relayer/src/message_relayer/common/message_paid_event_extractor.rs @@ -34,7 +34,10 @@ impl MeteredService for MessagePaidEventExtractor { impl_metered_service! { struct Metrics { - total_messages_found: IntCounter, + total_messages_found: IntCounter = IntCounter::new( + "message_paid_event_extractor_total_messages_found", + "Total amount of paid messages discovered", + ), } } diff --git a/relayer/src/message_relayer/common/message_queued_event_extractor.rs b/relayer/src/message_relayer/common/message_queued_event_extractor.rs index 930c2a02..33d33c0a 100644 --- a/relayer/src/message_relayer/common/message_queued_event_extractor.rs +++ b/relayer/src/message_relayer/common/message_queued_event_extractor.rs @@ -21,7 +21,10 @@ impl MeteredService for MessageQueuedEventExtractor { impl_metered_service! { struct Metrics { - total_messages_found: IntCounter, + total_messages_found: IntCounter = IntCounter::new( + "message_queued_event_extractor_total_messages_found", + "Total amount of messages discovered", + ), } } diff --git a/relayer/src/message_relayer/common/paid_messages_filter.rs b/relayer/src/message_relayer/common/paid_messages_filter.rs index ec5c53ee..05676b7a 100644 --- a/relayer/src/message_relayer/common/paid_messages_filter.rs +++ b/relayer/src/message_relayer/common/paid_messages_filter.rs @@ -23,7 +23,10 @@ impl MeteredService for PaidMessagesFilter { impl_metered_service! { struct Metrics { - pending_messages_count: IntGauge + pending_messages_count: IntGauge = IntGauge::new( + "paid_messages_filter_pending_messages_count", + "Amount of discovered but not paid messages", + ) } } diff --git a/relayer/src/proof_storage/gear.rs b/relayer/src/proof_storage/gear.rs index 63e0d82f..17ba0ced 100644 --- a/relayer/src/proof_storage/gear.rs +++ b/relayer/src/proof_storage/gear.rs @@ -44,7 +44,10 @@ struct Cache { impl_metered_service! { struct Metrics { - fee_payer_balance: Gauge + fee_payer_balance: Gauge = Gauge::new( + "gear_proof_storage_fee_payer_balance", + "Gear proof storage fee payer balance", + ) } } diff --git a/relayer/src/relay_merkle_roots.rs b/relayer/src/relay_merkle_roots.rs index 13ecc48b..c361d7ed 100644 --- a/relayer/src/relay_merkle_roots.rs +++ b/relayer/src/relay_merkle_roots.rs @@ -28,9 +28,18 @@ pub struct MerkleRootRelayer { impl_metered_service! { struct Metrics { - latest_proven_era: IntGauge, - latest_observed_gear_era: IntGauge, - fee_payer_balance: Gauge + latest_proven_era: IntGauge = IntGauge::new( + "merkle_root_relayer_latest_proven_era", + "Latest proven era number", + ), + latest_observed_gear_era: IntGauge = IntGauge::new( + "merkle_root_relayer_latest_observed_gear_era", + "Latest era number observed by relayer", + ), + fee_payer_balance: Gauge = Gauge::new( + "merkle_root_relayer_fee_payer_balance", + "Transaction fee payer balance", + ) } } @@ -272,8 +281,11 @@ impl MeteredService for Eras { impl_metered_service! { struct EraMetrics { - sealed_not_finalized_count: IntGauge, - last_sealed_era: IntGauge + sealed_not_finalized_count: IntGauge = IntGauge::new( + "sealed_not_finalized_count", + "Amount of eras that have been sealed but tx is not yet finalized by ethereum", + ), + last_sealed_era: IntGauge = IntGauge::new("last_sealed_era", "Latest era that have been sealed"), } } diff --git a/utils-prometheus/src/lib.rs b/utils-prometheus/src/lib.rs index f1e492e6..70b3bf0c 100644 --- a/utils-prometheus/src/lib.rs +++ b/utils-prometheus/src/lib.rs @@ -17,9 +17,6 @@ pub trait MeteredService { #[macro_export] macro_rules! impl_metered_service { ($($impl:tt)*) => { - #[derive(::core::clone::Clone)] - $($impl)* - $crate::impl_metered_service_inner! { $($impl)* } @@ -33,11 +30,20 @@ macro_rules! impl_metered_service_inner { $vis:vis struct $struct_name:ident { $( $(#[$($attributes:tt)*])* - $field_vis:vis $field_name:ident: $field_type:ty + $field_vis:vis $field_name:ident : $field_type:ty = $constructor:expr ),* $(,)? } ) => { + #[derive(Clone)] + $(#[$($struct_attributes)*])* + $vis struct $struct_name { + $( + $(#[$($attributes)*])* + $field_vis $field_name: $field_type + ),* + } + impl $crate::MeteredService for $struct_name { fn get_sources(&self) -> impl ::core::iter::IntoIterator< Item = ::std::boxed::Box