Przeglądaj źródła

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

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

Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz>

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

Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz>

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

Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz>

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

Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz>

* chore: update Cargo.lock with version bump

Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Jayant Krishnamurthy <jayant@dourolabs.xyz>
devin-ai-integration[bot] 9 miesięcy temu
rodzic
commit
dd390294a1

+ 1 - 1
apps/fortuna/Cargo.lock

@@ -1503,7 +1503,7 @@ dependencies = [
 
 [[package]]
 name = "fortuna"
-version = "7.4.0"
+version = "7.4.1"
 dependencies = [
  "anyhow",
  "axum",

+ 1 - 1
apps/fortuna/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "fortuna"
-version = "7.4.0"
+version = "7.4.1"
 edition = "2021"
 
 [dependencies]

+ 7 - 1
apps/fortuna/src/command/run.rs

@@ -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

+ 58 - 1
apps/fortuna/src/keeper.rs

@@ -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();
 
@@ -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
     }
 }