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

chore: init KeeperMetrics with chain_id and provider_address, bump version #2318

Merged
merged 5 commits into from
Jan 31, 2025
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
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
Loading