Skip to content

Commit

Permalink
Inline constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
mertwole committed Sep 6, 2024
1 parent e09a027 commit 5d79598
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 26 deletions.
25 changes: 20 additions & 5 deletions relayer/src/ethereum_checkpoints/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}
}

Expand Down
15 changes: 12 additions & 3 deletions relayer/src/message_relayer/common/ethereum_message_sender/era.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}

Expand Down
5 changes: 4 additions & 1 deletion relayer/src/message_relayer/common/gear_block_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}

Expand Down
5 changes: 4 additions & 1 deletion relayer/src/message_relayer/common/merkle_root_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}
}

Expand Down
5 changes: 4 additions & 1 deletion relayer/src/message_relayer/common/paid_messages_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}

Expand Down
5 changes: 4 additions & 1 deletion relayer/src/proof_storage/gear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}

Expand Down
22 changes: 17 additions & 5 deletions relayer/src/relay_merkle_roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}

Expand Down Expand Up @@ -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"),
}
}

Expand Down
14 changes: 10 additions & 4 deletions utils-prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*
}
Expand All @@ -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<dyn prometheus::core::Collector>
Expand Down

0 comments on commit 5d79598

Please sign in to comment.