diff --git a/ant-networking/src/driver.rs b/ant-networking/src/driver.rs index bb1637a099..6622264d1b 100644 --- a/ant-networking/src/driver.rs +++ b/ant-networking/src/driver.rs @@ -594,19 +594,17 @@ impl NetworkBuilder { let kademlia = { match record_store_cfg { Some(store_cfg) => { + #[cfg(feature = "open-metrics")] + let record_stored_metrics = + metrics_recorder.as_ref().map(|r| r.records_stored.clone()); let node_record_store = NodeRecordStore::with_config( peer_id, store_cfg, network_event_sender.clone(), local_swarm_cmd_sender.clone(), + #[cfg(feature = "open-metrics")] + record_stored_metrics, ); - #[cfg(feature = "open-metrics")] - let mut node_record_store = node_record_store; - #[cfg(feature = "open-metrics")] - if let Some(metrics_recorder) = &metrics_recorder { - node_record_store = node_record_store - .set_record_count_metric(metrics_recorder.records_stored.clone()); - } let store = UnifiedRecordStore::Node(node_record_store); debug!("Using Kademlia with NodeRecordStore!"); diff --git a/ant-networking/src/record_store.rs b/ant-networking/src/record_store.rs index b4ab4ff6b3..20e5f7bca9 100644 --- a/ant-networking/src/record_store.rs +++ b/ant-networking/src/record_store.rs @@ -348,6 +348,7 @@ impl NodeRecordStore { config: NodeRecordStoreConfig, network_event_sender: mpsc::Sender, swarm_cmd_sender: mpsc::Sender, + #[cfg(feature = "open-metrics")] record_count_metric: Option, ) -> Self { info!("Using encryption_seed of {:?}", config.encryption_seed); let encryption_details = derive_aes256gcm_siv_from_seed(&config.encryption_seed); @@ -386,7 +387,7 @@ impl NodeRecordStore { local_swarm_cmd_sender: swarm_cmd_sender, responsible_distance_range: None, #[cfg(feature = "open-metrics")] - record_count_metric: None, + record_count_metric, received_payment_count, encryption_details, timestamp, @@ -397,14 +398,12 @@ impl NodeRecordStore { record_store.flush_historic_quoting_metrics(); - record_store - } + #[cfg(feature = "open-metrics")] + if let Some(metric) = &record_store.record_count_metric { + let _ = metric.set(record_store.records.len() as i64); + } - /// Set the record_count_metric to report the number of records stored to the metrics server - #[cfg(feature = "open-metrics")] - pub fn set_record_count_metric(mut self, metric: Gauge) -> Self { - self.record_count_metric = Some(metric); - self + record_store } /// Returns the current distance ilog2 (aka bucket) range of CLOSE_GROUP nodes. @@ -1076,6 +1075,8 @@ mod tests { Default::default(), network_event_sender, swarm_cmd_sender, + #[cfg(feature = "open-metrics")] + None, ); // An initial unverified put should not write to disk @@ -1152,6 +1153,8 @@ mod tests { store_config.clone(), network_event_sender.clone(), swarm_cmd_sender.clone(), + #[cfg(feature = "open-metrics")] + None, ); // Create a chunk @@ -1189,6 +1192,8 @@ mod tests { store_config, network_event_sender.clone(), swarm_cmd_sender.clone(), + #[cfg(feature = "open-metrics")] + None, ); // Sleep a lit bit to let OS completes restoring @@ -1210,6 +1215,8 @@ mod tests { store_config_diff, network_event_sender, swarm_cmd_sender, + #[cfg(feature = "open-metrics")] + None, ); // Sleep a lit bit to let OS completes restoring (if has) @@ -1247,6 +1254,8 @@ mod tests { store_config, network_event_sender, swarm_cmd_sender, + #[cfg(feature = "open-metrics")] + None, ); // Create a chunk @@ -1311,6 +1320,8 @@ mod tests { store_config, network_event_sender, swarm_cmd_sender, + #[cfg(feature = "open-metrics")] + None, ); // Create a scratchpad @@ -1404,6 +1415,8 @@ mod tests { store_config.clone(), network_event_sender, swarm_cmd_sender, + #[cfg(feature = "open-metrics")] + None, ); // keep track of everything ever stored, to check missing at the end are further away let mut stored_records_at_some_point: Vec = vec![]; @@ -1528,6 +1541,8 @@ mod tests { store_config, network_event_sender, swarm_cmd_sender, + #[cfg(feature = "open-metrics")] + None, ); let mut stored_records: Vec = vec![]; @@ -1612,6 +1627,8 @@ mod tests { store_config.clone(), network_event_sender.clone(), swarm_cmd_sender.clone(), + #[cfg(feature = "open-metrics")] + None, ); store.payment_received(); @@ -1624,6 +1641,8 @@ mod tests { store_config, network_event_sender, swarm_cmd_sender, + #[cfg(feature = "open-metrics")] + None, ); assert_eq!(1, new_store.received_payment_count);