diff --git a/relayer/src/ethereum_checkpoints/metrics.rs b/relayer/src/ethereum_checkpoints/metrics.rs index e9de5177..9c28875b 100644 --- a/relayer/src/ethereum_checkpoints/metrics.rs +++ b/relayer/src/ethereum_checkpoints/metrics.rs @@ -3,41 +3,25 @@ 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, - } -} - -impl Updates { - pub fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - fetched_sync_update_slot: IntGauge::new( - "checkpoints_relayer_fetched_sync_update_slot", - "The slot of the last applied update", - )?, - total_fetched_finality_updates: IntCounter::new( - "checkpoints_relayer_total_fetched_finality_updates", - "Total amount of fetched finality updates", - )?, - processed_finality_updates: IntCounter::new( - "checkpoints_relayer_processed_finality_updates", - "Amount of processed finality updates", - )?, - processed_committee_updates: IntCounter::new( - "checkpoints_relayer_processed_committee_updates", - "Amount of processed committee updates", - )?, - account_total_balance: IntGauge::new( - "checkpoints_relayer_account_total_balance", - "The total balance of the account used to send messages", - )?, - }) + 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 f02e4d0c..cb02f8de 100644 --- a/relayer/src/message_relayer/common/ethereum_block_listener.rs +++ b/relayer/src/message_relayer/common/ethereum_block_listener.rs @@ -26,22 +26,10 @@ impl MeteredService for EthereumBlockListener { impl_metered_service! { struct Metrics { - latest_block: IntGauge, - } -} - -impl Metrics { - fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - latest_block: IntGauge::new( - "ethereum_block_listener_latest_block", - "Latest ethereum block discovered by listener", - )?, - }) + 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 7b92fd91..c539d019 100644 --- a/relayer/src/message_relayer/common/ethereum_message_sender/era.rs +++ b/relayer/src/message_relayer/common/ethereum_message_sender/era.rs @@ -25,32 +25,18 @@ struct RelayMessagePendingTx { impl_metered_service! { pub struct Metrics { - total_submitted_txs: IntCounter, - total_failed_txs: IntCounter, - total_failed_txs_because_processed: IntCounter, - } -} - -impl Metrics { - pub fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - total_submitted_txs: IntCounter::new( - "ethereum_message_sender_total_submitted_txs", - "Total amount of txs sent to ethereum", - )?, - total_failed_txs: IntCounter::new( - "ethereum_message_sender_total_failed_txs", - "Total amount of txs sent to ethereum and failed", - )?, - total_failed_txs_because_processed: IntCounter::new( - "ethereum_message_sender_total_failed_txs_because_processed", - "Amount of txs sent to ethereum and failed because they've already been processed", - )?, - }) + 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 fca39c71..a0df272f 100644 --- a/relayer/src/message_relayer/common/ethereum_message_sender/mod.rs +++ b/relayer/src/message_relayer/common/ethereum_message_sender/mod.rs @@ -35,27 +35,14 @@ impl MeteredService for EthereumMessageSender { impl_metered_service! { struct Metrics { - pending_tx_count: IntGauge, - fee_payer_balance: Gauge - } -} - -impl Metrics { - fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - pending_tx_count: IntGauge::new( - "ethereum_message_sender_pending_tx_count", - "Amount of txs pending finalization on ethereum", - )?, - fee_payer_balance: Gauge::new( - "ethereum_message_sender_fee_payer_balance", - "Transaction fee payer balance", - )?, - }) + 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 3873554a..5e1b932a 100644 --- a/relayer/src/message_relayer/common/gear_block_listener.rs +++ b/relayer/src/message_relayer/common/gear_block_listener.rs @@ -26,22 +26,10 @@ impl MeteredService for GearBlockListener { impl_metered_service! { struct Metrics { - latest_block: IntGauge, - } -} - -impl Metrics { - fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - latest_block: IntGauge::new( - "gear_block_listener_latest_block", - "Latest gear block discovered by gear block listener", - )?, - }) + 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 6bcbd511..42b55ac6 100644 --- a/relayer/src/message_relayer/common/merkle_root_extractor.rs +++ b/relayer/src/message_relayer/common/merkle_root_extractor.rs @@ -23,22 +23,10 @@ impl MeteredService for MerkleRootExtractor { impl_metered_service! { struct Metrics { - latest_merkle_root_for_block: IntGauge - } -} - -impl Metrics { - fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - latest_merkle_root_for_block: IntGauge::new( - "merkle_root_extractor_latest_merkle_root_for_block", - "Latest gear block present in found merkle roots", - )?, - }) + 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 f14bbd0c..1a0e0cc8 100644 --- a/relayer/src/message_relayer/common/message_paid_event_extractor.rs +++ b/relayer/src/message_relayer/common/message_paid_event_extractor.rs @@ -34,22 +34,10 @@ impl MeteredService for MessagePaidEventExtractor { impl_metered_service! { struct Metrics { - total_messages_found: IntCounter, - } -} - -impl Metrics { - fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - total_messages_found: IntCounter::new( - "message_paid_event_extractor_total_messages_found", - "Total amount of paid messages discovered", - )?, - }) + 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 5aab0c5e..140afb4e 100644 --- a/relayer/src/message_relayer/common/message_queued_event_extractor.rs +++ b/relayer/src/message_relayer/common/message_queued_event_extractor.rs @@ -21,22 +21,10 @@ impl MeteredService for MessageQueuedEventExtractor { impl_metered_service! { struct Metrics { - total_messages_found: IntCounter, - } -} - -impl Metrics { - fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - total_messages_found: IntCounter::new( - "message_queued_event_extractor_total_messages_found", - "Total amount of messages discovered", - )?, - }) + 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 4ee40b26..cb8399fe 100644 --- a/relayer/src/message_relayer/common/paid_messages_filter.rs +++ b/relayer/src/message_relayer/common/paid_messages_filter.rs @@ -23,22 +23,10 @@ impl MeteredService for PaidMessagesFilter { impl_metered_service! { struct Metrics { - pending_messages_count: IntGauge - } -} - -impl Metrics { - fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - pending_messages_count: IntGauge::new( - "paid_messages_filter_pending_messages_count", - "Amount of discovered but not paid messages", - )?, - }) + 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 b96300a4..919a4cb1 100644 --- a/relayer/src/proof_storage/gear.rs +++ b/relayer/src/proof_storage/gear.rs @@ -44,22 +44,10 @@ struct Cache { impl_metered_service! { struct Metrics { - fee_payer_balance: Gauge - } -} - -impl Metrics { - fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - fee_payer_balance: Gauge::new( - "gear_proof_storage_fee_payer_balance", - "Gear proof storage fee payer balance", - )?, - }) + 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 0dd92bd4..fdff7f44 100644 --- a/relayer/src/relay_merkle_roots.rs +++ b/relayer/src/relay_merkle_roots.rs @@ -28,32 +28,18 @@ pub struct MerkleRootRelayer { impl_metered_service! { struct Metrics { - latest_proven_era: IntGauge, - latest_observed_gear_era: IntGauge, - fee_payer_balance: Gauge - } -} - -impl Metrics { - fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - latest_proven_era: IntGauge::new( - "merkle_root_relayer_latest_proven_era", - "Latest proven era number", - )?, - latest_observed_gear_era: IntGauge::new( - "merkle_root_relayer_latest_observed_gear_era", - "Latest era number observed by relayer", - )?, - fee_payer_balance: Gauge::new( - "merkle_root_relayer_fee_payer_balance", - "Transaction fee payer balance", - )?, - }) + 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", + ) } } @@ -276,24 +262,11 @@ impl MeteredService for Eras { impl_metered_service! { struct EraMetrics { - sealed_not_finalized_count: IntGauge, - last_sealed_era: IntGauge - } -} - -impl EraMetrics { - fn new() -> Self { - Self::new_inner().expect("Failed to create metrics") - } - - fn new_inner() -> prometheus::Result { - Ok(Self { - sealed_not_finalized_count: 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::new("last_sealed_era", "Latest era that have been sealed")?, - }) + 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 36efa7de..22d3ac78 100644 --- a/utils-prometheus/src/lib.rs +++ b/utils-prometheus/src/lib.rs @@ -21,12 +21,12 @@ macro_rules! impl_metered_service { $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, Debug)] + #[derive(Clone)] $(#[$($struct_attributes)*])* $vis struct $struct_name { $( @@ -51,6 +51,20 @@ macro_rules! impl_metered_service { ] } } + + impl $struct_name { + $vis fn new() -> Self { + let new_inner = || -> prometheus::Result { + Ok(Self { + $( + $field_name: $constructor ? + ),* + }) + }; + + new_inner().expect("Failed to create metrics") + } + } } }