Skip to content

Commit

Permalink
chore: init KeeperMetrics with chain_id and provider_address, bump ve…
Browse files Browse the repository at this point in the history
…rsion (#2318)

* chore: init KeeperMetrics with chain_id and provider_address, bump version

Co-Authored-By: Jayant Krishnamurthy <[email protected]>

* fix: properly handle RwLock return values in KeeperMetrics::new

Co-Authored-By: Jayant Krishnamurthy <[email protected]>

* fix: use keys() and values() instead of iter() for map iteration

Co-Authored-By: Jayant Krishnamurthy <[email protected]>

* refactor: simplify KeeperMetrics::new to use Vec<(String, Address)>

Co-Authored-By: Jayant Krishnamurthy <[email protected]>

* chore: update Cargo.lock with version bump

Co-Authored-By: Jayant Krishnamurthy <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Jayant Krishnamurthy <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and Jayant Krishnamurthy authored Jan 31, 2025
1 parent bfd8c12 commit dd39029
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/fortuna/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/fortuna/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fortuna"
version = "7.4.0"
version = "7.4.1"
edition = "2021"

[dependencies]
Expand Down
8 changes: 7 additions & 1 deletion apps/fortuna/src/command/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ pub async fn run_keeper(
rpc_metrics: Arc<RpcMetrics>,
) -> Result<()> {
let mut handles = Vec::new();
let keeper_metrics = Arc::new(KeeperMetrics::new(metrics_registry).await);
let keeper_metrics = Arc::new({
let chain_labels: Vec<(String, Address)> = chains
.iter()
.map(|(id, state)| (id.clone(), state.provider_address))
.collect();
KeeperMetrics::new(metrics_registry.clone(), chain_labels).await
});
for (chain_id, chain_config) in chains {
let chain_eth_config = config
.chains
Expand Down
59 changes: 58 additions & 1 deletion apps/fortuna/src/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ impl Default for KeeperMetrics {
}

impl KeeperMetrics {
pub async fn new(registry: Arc<RwLock<Registry>>) -> Self {
pub async fn new(
registry: Arc<RwLock<Registry>>,
chain_labels: Vec<(String, Address)>,
) -> Self {
let mut writable_registry = registry.write().await;
let keeper_metrics = KeeperMetrics::default();

Expand Down Expand Up @@ -246,6 +249,60 @@ impl KeeperMetrics {
keeper_metrics.gas_price_estimate.clone(),
);

// *Important*: When adding a new metric:
// 1. Register it above using `writable_registry.register(...)`
// 2. Add a get_or_create call in the loop below to initialize it for each chain/provider pair
for (chain_id, provider_address) in chain_labels {
let account_label = AccountLabel {
chain_id,
address: provider_address.to_string(),
};

let _ = keeper_metrics
.current_sequence_number
.get_or_create(&account_label);
let _ = keeper_metrics
.end_sequence_number
.get_or_create(&account_label);
let _ = keeper_metrics.balance.get_or_create(&account_label);
let _ = keeper_metrics.collected_fee.get_or_create(&account_label);
let _ = keeper_metrics.current_fee.get_or_create(&account_label);
let _ = keeper_metrics
.target_provider_fee
.get_or_create(&account_label);
let _ = keeper_metrics.total_gas_spent.get_or_create(&account_label);
let _ = keeper_metrics
.total_gas_fee_spent
.get_or_create(&account_label);
let _ = keeper_metrics.requests.get_or_create(&account_label);
let _ = keeper_metrics
.requests_processed
.get_or_create(&account_label);
let _ = keeper_metrics
.requests_processed_success
.get_or_create(&account_label);
let _ = keeper_metrics
.requests_processed_failure
.get_or_create(&account_label);
let _ = keeper_metrics
.requests_reprocessed
.get_or_create(&account_label);
let _ = keeper_metrics.reveals.get_or_create(&account_label);
let _ = keeper_metrics
.request_duration_ms
.get_or_create(&account_label);
let _ = keeper_metrics.retry_count.get_or_create(&account_label);
let _ = keeper_metrics
.final_gas_multiplier
.get_or_create(&account_label);
let _ = keeper_metrics
.final_fee_multiplier
.get_or_create(&account_label);
let _ = keeper_metrics
.gas_price_estimate
.get_or_create(&account_label);
}

keeper_metrics
}
}
Expand Down

0 comments on commit dd39029

Please sign in to comment.