Skip to content

Commit

Permalink
Remove boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
mertwole committed Sep 6, 2024
1 parent 5d79598 commit 0ad538b
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 170 deletions.
27 changes: 0 additions & 27 deletions relayer/src/ethereum_checkpoints/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,3 @@ impl_metered_service! {
),
}
}

impl Updates {
fn new_inner() -> prometheus::Result<Self> {
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",
)?,
})
}
}
11 changes: 0 additions & 11 deletions relayer/src/message_relayer/common/ethereum_block_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ impl_metered_service! {
}
}

impl Metrics {
fn new_inner() -> prometheus::Result<Self> {
Ok(Self {
latest_block: IntGauge::new(
"ethereum_block_listener_latest_block",
"Latest ethereum block discovered by listener",
)?,
})
}
}

impl EthereumBlockListener {
pub fn new(eth_api: EthApi, from_block: u64) -> Self {
Self {
Expand Down
19 changes: 0 additions & 19 deletions relayer/src/message_relayer/common/ethereum_message_sender/era.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,6 @@ impl_metered_service! {
}
}

impl Metrics {
fn new_inner() -> prometheus::Result<Self> {
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",
)?,
})
}
}

impl Era {
pub fn new(metrics: Metrics) -> Self {
Self {
Expand Down
15 changes: 0 additions & 15 deletions relayer/src/message_relayer/common/ethereum_message_sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,6 @@ impl_metered_service! {
}
}

impl Metrics {
fn new_inner() -> prometheus::Result<Self> {
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",
)?,
})
}
}

impl EthereumMessageSender {
pub fn new(eth_api: EthApi, gear_api: GearApi) -> Self {
Self {
Expand Down
11 changes: 0 additions & 11 deletions relayer/src/message_relayer/common/gear_block_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ impl_metered_service! {
}
}

impl Metrics {
fn new_inner() -> prometheus::Result<Self> {
Ok(Self {
latest_block: IntGauge::new(
"gear_block_listener_latest_block",
"Latest gear block discovered by gear block listener",
)?,
})
}
}

impl GearBlockListener {
pub fn new(gear_api: GearApi, from_block: u32) -> Self {
Self {
Expand Down
11 changes: 0 additions & 11 deletions relayer/src/message_relayer/common/merkle_root_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ impl_metered_service! {
}
}

impl Metrics {
fn new_inner() -> prometheus::Result<Self> {
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",
)?,
})
}
}

impl MerkleRootExtractor {
pub fn new(eth_api: EthApi, gear_api: GearApi) -> Self {
Self {
Expand Down
11 changes: 0 additions & 11 deletions relayer/src/message_relayer/common/message_paid_event_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ impl_metered_service! {
}
}

impl Metrics {
fn new_inner() -> prometheus::Result<Self> {
Ok(Self {
total_messages_found: IntCounter::new(
"message_paid_event_extractor_total_messages_found",
"Total amount of paid messages discovered",
)?,
})
}
}

impl MessagePaidEventExtractor {
pub fn new(gear_api: GearApi, bridging_payment_address: H256) -> Self {
Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@ impl_metered_service! {
}
}

impl Metrics {
fn new_inner() -> prometheus::Result<Self> {
Ok(Self {
total_messages_found: IntCounter::new(
"message_queued_event_extractor_total_messages_found",
"Total amount of messages discovered",
)?,
})
}
}

impl MessageQueuedEventExtractor {
pub fn new(gear_api: GearApi) -> Self {
Self {
Expand Down
11 changes: 0 additions & 11 deletions relayer/src/message_relayer/common/paid_messages_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ impl_metered_service! {
}
}

impl Metrics {
fn new_inner() -> prometheus::Result<Self> {
Ok(Self {
pending_messages_count: IntGauge::new(
"paid_messages_filter_pending_messages_count",
"Amount of discovered but not paid messages",
)?,
})
}
}

impl PaidMessagesFilter {
pub fn new() -> Self {
Self {
Expand Down
11 changes: 0 additions & 11 deletions relayer/src/proof_storage/gear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@ impl_metered_service! {
}
}

impl Metrics {
fn new_inner() -> prometheus::Result<Self> {
Ok(Self {
fee_payer_balance: Gauge::new(
"gear_proof_storage_fee_payer_balance",
"Gear proof storage fee payer balance",
)?,
})
}
}

impl MeteredService for GearProofStorage {
fn get_sources(&self) -> impl IntoIterator<Item = Box<dyn prometheus::core::Collector>> {
self.metrics.get_sources()
Expand Down
31 changes: 0 additions & 31 deletions relayer/src/relay_merkle_roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,6 @@ impl_metered_service! {
}
}

impl Metrics {
fn new_inner() -> prometheus::Result<Self> {
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",
)?,
})
}
}

impl MeteredService for MerkleRootRelayer {
fn get_sources(&self) -> impl IntoIterator<Item = Box<dyn prometheus::core::Collector>> {
self.metrics
Expand Down Expand Up @@ -289,18 +270,6 @@ impl_metered_service! {
}
}

impl EraMetrics {
fn new_inner() -> prometheus::Result<Self> {
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")?,
})
}
}

impl Eras {
pub async fn new(
last_sealed: Option<u64>,
Expand Down
10 changes: 9 additions & 1 deletion utils-prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ macro_rules! impl_metered_service_inner {

impl $struct_name {
$vis fn new() -> Self {
Self::new_inner().expect("Failed to create metrics")
let new_inner = || -> prometheus::Result<Self> {
Ok(Self {
$(
$field_name: $constructor ?
),*
})
};

new_inner().expect("Failed to create metrics")
}
}
}
Expand Down

0 comments on commit 0ad538b

Please sign in to comment.