Skip to content

Commit

Permalink
use a component name in metering
Browse files Browse the repository at this point in the history
  • Loading branch information
montekki committed Sep 28, 2023
1 parent 8873270 commit c1d16ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions finalizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ where
) -> Self {
let withdrawals_meterer = withdrawals_meterer::WithdrawalsMeter::new(
pgpool.clone(),
"era_withdrawal_finalizer_withdrawn_tokens",
"era_withdrawal_finalizer_meter",
);
let tx_fee_limit = ethers::utils::parse_ether(TX_FEE_LIMIT)
.expect("{TX_FEE_LIMIT} ether is a parsable amount; qed");
Expand Down Expand Up @@ -216,7 +216,7 @@ where

if let Err(e) = self
.withdrawals_meterer
.meter_finalized_withdrawals_storage(&ids)
.meter_withdrawals_storage(&ids)
.await
{
vlog::error!("Failed to meter the withdrawals: {e}");
Expand Down
4 changes: 2 additions & 2 deletions watcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
pub fn new(l2_provider: Arc<M2>, pgpool: PgPool) -> Self {
let withdrawals_meterer = withdrawals_meterer::WithdrawalsMeter::new(
pgpool.clone(),
"era_withdrawn_tokens_amounts_tracker",
"era_withdrawal_finalizer_watcher_meter",
);

Self {
Expand Down Expand Up @@ -316,7 +316,7 @@ async fn process_withdrawals_in_block(
}

if let Err(e) = withdrawals_meterer
.meter_finalized_withdrawals(&stored_withdrawals)
.meter_withdrawals(&stored_withdrawals)
.await
{
vlog::error!("Failed to meter requested withdrawals: {e}");
Expand Down
21 changes: 10 additions & 11 deletions withdrawals-meterer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use storage::StoredWithdrawal;
pub struct WithdrawalsMeter {
pool: PgPool,
token_decimals: HashMap<Address, u32>,
metric_name: &'static str,
component_name: &'static str,
}

impl WithdrawalsMeter {
Expand All @@ -25,26 +25,25 @@ impl WithdrawalsMeter {
/// # Arguments
///
/// * `pool`: DB connection pool
/// * `metric_name`: Name of the metric to meter to
pub fn new(pool: PgPool, metric_name: &'static str) -> Self {
/// * `component_name`: Name of the component that does metering, metric names will be
/// derived from it
pub fn new(pool: PgPool, component_name: &'static str) -> Self {
let mut token_decimals = HashMap::new();
token_decimals.insert(ETH_TOKEN_ADDRESS, 18_u32);

Self {
pool,
token_decimals,
metric_name,
component_name,
}
}

/// Given a set of withdrawal ids meter all of them to a metric
/// with a given name.
pub async fn meter_finalized_withdrawals_storage(
&mut self,
ids: &[i64],
) -> Result<(), storage::Error> {
pub async fn meter_withdrawals_storage(&mut self, ids: &[i64]) -> Result<(), storage::Error> {
let withdrawals = storage::get_withdrawals(&self.pool, ids).await?;

self.meter_finalized_withdrawals(&withdrawals).await?;
self.meter_withdrawals(&withdrawals).await?;

Ok(())
}
Expand All @@ -54,7 +53,7 @@ impl WithdrawalsMeter {
///
/// This function returns only storage error, all formatting, etc
/// errors will be just logged.
pub async fn meter_finalized_withdrawals(
pub async fn meter_withdrawals(
&mut self,
withdrawals: &[StoredWithdrawal],
) -> Result<(), storage::Error> {
Expand Down Expand Up @@ -90,7 +89,7 @@ impl WithdrawalsMeter {
};

metrics::increment_gauge!(
self.metric_name,
format!("{}_withdrawals", self.component_name),
formatted_f64,
"token" => format!("{:?}", w.event.token)
)
Expand Down

0 comments on commit c1d16ed

Please sign in to comment.