Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(metrics-derive): minor fix of metric description, lint.
Browse files Browse the repository at this point in the history
andysim3d committed Oct 11, 2024
1 parent 298870f commit 8c9e405
Showing 15 changed files with 77 additions and 75 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ futures-util = "0.3.30"
itertools = "0.13.0"
jsonrpsee = "0.24.5"
metrics = "0.23.0"
metrics-derive = "0.1.0"
mockall = "0.13.0"
parse-display = "0.10.0"
pin-project = "1.1.5"
2 changes: 1 addition & 1 deletion bin/rundler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -47,4 +47,4 @@ tracing.workspace = true
tracing-appender = "0.2.3"
tracing-log = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "fmt", "json"] }
metrics-derive = "0.1.0"
metrics-derive.workspace = true
2 changes: 1 addition & 1 deletion bin/rundler/src/cli/metrics.rs
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ pub fn initialize<'a, T: TaskSpawner>(

#[allow(dead_code)]
#[derive(Metrics)]
#[metrics(scope = "rundler_tokio_rt")]
#[metrics(scope = "tokio_rt")]
pub(crate) struct TokioMetrics {
#[metric(describe = "the total number of tokio wokers.")]
num_workers: Gauge,
2 changes: 1 addition & 1 deletion crates/builder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ serde_json.workspace = true
strum.workspace = true

mockall = {workspace = true, optional = true }
metrics-derive = "0.1.0"
metrics-derive.workspace = true

[dev-dependencies]
mockall.workspace = true
72 changes: 36 additions & 36 deletions crates/builder/src/bundle_sender.rs
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ where
loop {
if let Err(e) = self.step_state(&mut state).await {
error!("Error in bundle sender loop: {e:#?}");
self.metrics.state_machine_errors.increment(1_u64);
self.metrics.state_machine_errors.increment(1);
state.reset();
}
}
@@ -278,7 +278,7 @@ where
"Abandoning bundle after {} fee increases, no operations available after fee increase",
inner.fee_increase_count
);
self.metrics.bundle_txns_abandoned.increment(1_u64);
self.metrics.bundle_txns_abandoned.increment(1);

// abandon the bundle by starting a new bundle process
// If the node we are using still has the transaction in the mempool, its
@@ -311,7 +311,7 @@ where
}
Err(error) => {
error!("Bundle send error {error:?}");
self.metrics.bundle_txns_failed.increment(1_u64);
self.metrics.bundle_txns_failed.increment(1);
state.bundle_error(error);
}
}
@@ -353,7 +353,7 @@ where
self.builder_index,
nonce,
));
self.metrics.bundle_txns_dropped.increment(1_u64);
self.metrics.bundle_txns_dropped.increment(1);
// try again, increasing fees
state.update(InnerState::Building(inner.to_building()));
}
@@ -363,7 +363,7 @@ where
self.builder_index,
nonce,
));
self.metrics.bundle_txns_nonce_used.increment(1_u64);
self.metrics.bundle_txns_nonce_used.increment(1);
state.reset();
}
}
@@ -376,7 +376,7 @@ where
self.settings.max_blocks_to_wait_for_mine,
inner.fee_increase_count + 1
);
self.metrics.bundle_txn_fee_increases.increment(1_u64);
self.metrics.bundle_txn_fee_increases.increment(1);
state.update(InnerState::Building(inner.to_building()))
}

@@ -407,23 +407,23 @@ where
match cancel_res {
Ok(Some(_)) => {
info!("Cancellation transaction sent, waiting for confirmation");
self.metrics.cancellation_txns_sent.increment(1_u64);
self.metrics.cancellation_txns_sent.increment(1);

state.update(InnerState::CancelPending(inner.to_cancel_pending(
state.block_number() + self.settings.max_blocks_to_wait_for_mine,
)));
}
Ok(None) => {
info!("Soft cancellation or no transaction to cancel, starting new bundle attempt");
self.metrics.soft_cancellations.increment(1_u64);
self.metrics.soft_cancellations.increment(1);
state.reset();
}
Err(TransactionTrackerError::ReplacementUnderpriced) => {
info!("Replacement transaction underpriced during cancellation, trying again");
if inner.fee_increase_count >= self.settings.max_cancellation_fee_increases {
// abandon the cancellation
warn!("Abandoning cancellation after max fee increases {}, starting new bundle attempt", inner.fee_increase_count);
self.metrics.cancellations_abandoned.increment(1_u64);
self.metrics.cancellations_abandoned.increment(1);
state.reset();
} else {
// Increase fees again
@@ -441,7 +441,7 @@ where
}
Err(e) => {
error!("Failed to cancel transaction, moving back to building state: {e:#?}");
self.metrics.cancellation_txns_failed.increment(1_u64);
self.metrics.cancellation_txns_failed.increment(1);
state.reset();
}
}
@@ -466,7 +466,7 @@ where
// mined
let fee = gas_used.zip(gas_price).map(|(used, price)| used * price);
info!("Cancellation transaction mined. Price (wei) {fee:?}");
self.metrics.cancellation_txns_mined.increment(1_u64);
self.metrics.cancellation_txns_mined.increment(1);
if let Some(fee) = fee {
self.metrics
.cancellation_txns_total_fee
@@ -489,7 +489,7 @@ where
if inner.fee_increase_count >= self.settings.max_cancellation_fee_increases {
// abandon the cancellation
warn!("Abandoning cancellation after max fee increases {}, starting new bundle attempt", inner.fee_increase_count);
self.metrics.cancellations_abandoned.increment(1_u64);
self.metrics.cancellations_abandoned.increment(1);
state.reset();
} else {
// start replacement, don't wait for trigger
@@ -549,7 +549,7 @@ where
op_hashes,
} = bundle_tx;

self.metrics.bundle_txns_sent.increment(1_u64);
self.metrics.bundle_txns_sent.increment(1);

let send_result = state
.transaction_tracker
@@ -573,17 +573,17 @@ where
Ok(SendBundleAttemptResult::Success)
}
Err(TransactionTrackerError::NonceTooLow) => {
self.metrics.bundle_txn_nonce_too_low.increment(1_u64);
self.metrics.bundle_txn_nonce_too_low.increment(1);
warn!("Bundle attempt nonce too low");
Ok(SendBundleAttemptResult::NonceTooLow)
}
Err(TransactionTrackerError::ReplacementUnderpriced) => {
self.metrics.bundle_replacement_underpriced.increment(1_u64);
self.metrics.bundle_replacement_underpriced.increment(1);
warn!("Bundle attempt replacement transaction underpriced");
Ok(SendBundleAttemptResult::ReplacementUnderpriced)
}
Err(TransactionTrackerError::ConditionNotMet) => {
self.metrics.bundle_txn_condition_not_met.increment(1_u64);
self.metrics.bundle_txn_condition_not_met.increment(1);
warn!("Bundle attempt condition not met");
Ok(SendBundleAttemptResult::ConditionNotMet)
}
@@ -894,7 +894,7 @@ impl BuildingState {

// Finalize an underpriced round.
//
// This will clear out the number of fee increases and increment the number of underpriced rounds.
// This will clear out the count of fee increases and increment the count of underpriced rounds.
// Use this when we are in an underpriced state, but there are no longer any UOs available to bundle.
fn underpriced_round(self) -> Self {
let mut underpriced_info = self
@@ -1135,49 +1135,49 @@ impl BundleSenderTrigger {
#[derive(Metrics)]
#[metrics(scope = "builder")]
struct BuilderMetric {
#[metric(describe = "the number of bundle transactions already sent.")]
#[metric(describe = "the count of bundle transactions already sent.")]
bundle_txns_sent: Counter,
#[metric(describe = "the number of bundle transactions successed.")]
#[metric(describe = "the count of bundle transactions successed.")]
bundle_txns_success: Counter,
#[metric(describe = "the number of bundle gas limit.")]
#[metric(describe = "the count of bundle gas limit.")]
bundle_gas_limit: Counter,
#[metric(describe = "the number of bundle gas used.")]
#[metric(describe = "the count of bundle gas used.")]
bundle_gas_used: Counter,
#[metric(describe = "the number of dropped bundle transactions.")]
#[metric(describe = "the count of dropped bundle transactions.")]
bundle_txns_dropped: Counter,
#[metric(describe = "the number of anabdoned bundle transactions.")]
#[metric(describe = "the count of anabdoned bundle transactions.")]
bundle_txns_abandoned: Counter,
#[metric(describe = "the number of failed bundle transactions.")]
#[metric(describe = "the count of failed bundle transactions.")]
bundle_txns_failed: Counter,
#[metric(describe = "the number of bundle transactin nonce used event.")]
#[metric(describe = "the count of bundle transaction nonce used events.")]
bundle_txns_nonce_used: Counter,
#[metric(describe = "the number of bundle transactions fee increase event.")]
#[metric(describe = "the count of bundle transactions fee increase events.")]
bundle_txn_fee_increases: Counter,
#[metric(describe = "the number of bundle transactions underprice replaced event.")]
#[metric(describe = "the count of bundle transactions underprice replaced events.")]
bundle_replacement_underpriced: Counter,
#[metric(describe = "the number of bundle transactions nonce too low event.")]
#[metric(describe = "the count of bundle transactions nonce too low events.")]
bundle_txn_nonce_too_low: Counter,
#[metric(describe = "the number of bundle transactions condition not met event.")]
#[metric(describe = "the count of bundle transactions condition not met events.")]
bundle_txn_condition_not_met: Counter,
#[metric(describe = "the number of cancellation bundle transactions sent event.")]
#[metric(describe = "the count of cancellation bundle transactions sent events.")]
cancellation_txns_sent: Counter,
#[metric(describe = "the number of cancellation bundle transactions mined event.")]
#[metric(describe = "the count of cancellation bundle transactions mined events.")]
cancellation_txns_mined: Counter,
#[metric(describe = "the total fee of cancellation bundle transactions.")]
cancellation_txns_total_fee: Counter,
#[metric(describe = "the number of cancellation bundle transactions abandon event.")]
#[metric(describe = "the count of cancellation bundle transactions abandon events.")]
cancellations_abandoned: Counter,
#[metric(describe = "the number of soft cancellation bundle transactions event.")]
#[metric(describe = "the count of soft cancellation bundle transactions events.")]
soft_cancellations: Counter,
#[metric(describe = "the number of cancellation bundle transactions failed event.")]
#[metric(describe = "the count of cancellation bundle transactions failed events.")]
cancellation_txns_failed: Counter,
#[metric(describe = "the number of state machine errors.")]
#[metric(describe = "the count of state machine errors.")]
state_machine_errors: Counter,
}

impl BuilderMetric {
fn process_bundle_txn_success(&self, gas_limit: Option<u64>, gas_used: Option<u128>) {
self.bundle_txns_success.increment(1_u64);
self.bundle_txns_success.increment(1);
if let Some(limit) = gas_limit {
self.bundle_gas_limit.increment(limit);
}
4 changes: 2 additions & 2 deletions crates/builder/src/signer/mod.rs
Original file line number Diff line number Diff line change
@@ -73,13 +73,13 @@ struct BuilderMetric {
}

pub(crate) async fn monitor_account_balance<P: EvmProvider>(addr: Address, provider: P) {
let metric = BuilderMetric::new_with_labels(&[("addr", format!("{addr:?}"))]);
loop {
match provider.get_balance(addr, None).await {
Ok(balance) => {
let eth_balance = balance.to_f64().unwrap_or_default() / 1e18;
tracing::info!("account {addr:?} balance: {}", eth_balance);
let metric = BuilderMetric::new_with_labels(&[("addr", format!("{addr:?}"))]);
metric.account_balance.set(eth_balance);
tracing::info!("account {addr:?} balance: {}", eth_balance);
}
Err(err) => {
tracing::error!("Get account {addr:?} balance error {err:?}");
2 changes: 1 addition & 1 deletion crates/builder/src/transaction_tracker.rs
Original file line number Diff line number Diff line change
@@ -495,7 +495,7 @@ impl From<TxSenderError> for TransactionTrackerError {
struct TransactionTrackerMetrics {
#[metric(describe = "the number of pending transactions.")]
num_pending_transactions: Gauge,
#[metric(describe = "the nonce of transaction.")]
#[metric(describe = "the current account‘s nonce.")]
nonce: Gauge,
#[metric(describe = "the number of pending transactions.")]
attempt_count: Gauge,
2 changes: 1 addition & 1 deletion crates/pool/Cargo.toml
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ tracing.workspace = true
url.workspace = true

mockall = {workspace = true, optional = true }
metrics-derive = "0.1.0"
metrics-derive.workspace = true

[dev-dependencies]
mockall.workspace = true
15 changes: 7 additions & 8 deletions crates/pool/src/chain.rs
Original file line number Diff line number Diff line change
@@ -211,7 +211,7 @@ impl<P: EvmProvider> Chain<P> {

for i in 0..=self.settings.max_sync_retries {
if i > 0 {
self.metrics.sync_retries.increment(1_u64);
self.metrics.sync_retries.increment(1);
}

let update = self.sync_to_block(block.clone()).await;
@@ -229,7 +229,7 @@ impl<P: EvmProvider> Chain<P> {
"Failed to update chain at block {:?} after {} retries. Abandoning sync.",
block_hash, self.settings.max_sync_retries
);
self.metrics.sync_abandoned.increment(1_u64);
self.metrics.sync_abandoned.increment(1);
}
}

@@ -333,7 +333,7 @@ impl<P: EvmProvider> Chain<P> {

self.metrics.block_height.set(current_block_number as f64);
if reorg_depth > 0 {
self.metrics.reorgs_detected.increment(1_u64);
self.metrics.reorgs_detected.increment(1);
self.metrics.total_reorg_depth.increment(reorg_depth);
}

@@ -705,17 +705,16 @@ impl ChainUpdate {

#[derive(Metrics)]
#[metrics(scope = "op_pool_chain")]

struct ChainMetrics {
#[metric(describe = "the height of block.")]
block_height: Gauge,
#[metric(describe = "the number of reorg event detected.")]
#[metric(describe = "the count of reorg event detected.")]
reorgs_detected: Counter,
#[metric(describe = "the total number of reorg depth.")]
#[metric(describe = "the count of reorg depth.")]
total_reorg_depth: Counter,
#[metric(describe = "the number of removed entities.")]
#[metric(describe = "the count of sync retries.")]
sync_retries: Counter,
#[metric(describe = "the number of sync abanded.")]
#[metric(describe = "the count of sync abanded.")]
sync_abandoned: Counter,
}

6 changes: 3 additions & 3 deletions crates/pool/src/mempool/pool.rs
Original file line number Diff line number Diff line change
@@ -615,15 +615,15 @@ struct PoolMetrics {
num_ops_in_pool: Gauge,
#[metric(describe = "the size of mempool in bytes.")]
size_bytes: Gauge,
#[metric(describe = "the number of ops in mempool cache(mined but not persistent).")]
#[metric(describe = "the number of ops in mempool cache (mined but not persistent).")]
num_ops_in_cache: Gauge,
#[metric(describe = "the size of mempool cache in bytes.")]
cache_size_bytes: Gauge,
#[metric(describe = "the number of candidates.")]
num_candidates: Gauge,
#[metric(describe = "the duration of a bundle mined.")]
#[metric(describe = "the duration distribution of a bundle mined.")]
time_to_mine: Histogram,
#[metric(describe = "the duration of a blcoked mined.")]
#[metric(describe = "the duration distribution of a blocked mined.")]
blocks_to_mine: Histogram,
}

10 changes: 5 additions & 5 deletions crates/pool/src/mempool/uo_pool.rs
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ where
self.ep_specific_metrics
.removed_operations
.increment(count as u64);
self.ep_specific_metrics.removed_entities.increment(1_u64);
self.ep_specific_metrics.removed_entities.increment(1);
}

fn remove_entity(&self, entity: Entity) {
@@ -146,7 +146,7 @@ where
self.ep_specific_metrics
.removed_operations
.increment(count as u64);
self.ep_specific_metrics.removed_entities.increment(1_u64);
self.ep_specific_metrics.removed_entities.increment(1);
}
}

@@ -712,11 +712,11 @@ where
struct UoPoolMetricsEPSpecific {
#[metric(describe = "the number of ops seen.")]
ops_seen: Gauge,
#[metric(describe = "the number of unmined ops.")]
#[metric(describe = "the count of unmined ops.")]
unmined_operations: Counter,
#[metric(describe = "the number of removed ops.")]
#[metric(describe = "the count of removed ops.")]
removed_operations: Counter,
#[metric(describe = "the number of removed entities.")]
#[metric(describe = "the count of removed entities.")]
removed_entities: Counter,
}

2 changes: 1 addition & 1 deletion crates/rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ anyhow.workspace = true
async-trait.workspace = true
jsonrpsee = { workspace = true , features = ["client", "macros", "server"] }
metrics.workspace = true
metrics-derive.workspace = true
thiserror.workspace = true
tokio.workspace = true
tokio-util.workspace = true
@@ -33,7 +34,6 @@ strum.workspace = true
url.workspace = true
futures-util.workspace = true
http = "1.1.0"
metrics-derive = "0.1.0"

[dev-dependencies]
mockall.workspace = true
Loading

0 comments on commit 8c9e405

Please sign in to comment.