Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(prometheus-utils): Refactor impl_metered_service macro #122

Merged
merged 5 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 20 additions & 36 deletions relayer/src/ethereum_checkpoints/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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",
)?,
})
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",
),
}
}
20 changes: 4 additions & 16 deletions relayer/src/message_relayer/common/ethereum_block_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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",
),
}
}

Expand Down
38 changes: 12 additions & 26 deletions relayer/src/message_relayer/common/ethereum_message_sender/era.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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",
)?,
})
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
29 changes: 8 additions & 21 deletions relayer/src/message_relayer/common/ethereum_message_sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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",
)?,
})
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
20 changes: 4 additions & 16 deletions relayer/src/message_relayer/common/gear_block_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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",
)
}
}

Expand Down
20 changes: 4 additions & 16 deletions relayer/src/message_relayer/common/merkle_root_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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",
)?,
})
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
20 changes: 4 additions & 16 deletions relayer/src/message_relayer/common/message_paid_event_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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",
),
}
}

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

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

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

Expand Down
Loading
Loading