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

fix(network): set the record count metric as soon as we restart #2617

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
12 changes: 5 additions & 7 deletions ant-networking/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down
35 changes: 27 additions & 8 deletions ant-networking/src/record_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ impl NodeRecordStore {
config: NodeRecordStoreConfig,
network_event_sender: mpsc::Sender<NetworkEvent>,
swarm_cmd_sender: mpsc::Sender<LocalSwarmCmd>,
#[cfg(feature = "open-metrics")] record_count_metric: Option<Gauge>,
) -> Self {
info!("Using encryption_seed of {:?}", config.encryption_seed);
let encryption_details = derive_aes256gcm_siv_from_seed(&config.encryption_seed);
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -1247,6 +1254,8 @@ mod tests {
store_config,
network_event_sender,
swarm_cmd_sender,
#[cfg(feature = "open-metrics")]
None,
);

// Create a chunk
Expand Down Expand Up @@ -1311,6 +1320,8 @@ mod tests {
store_config,
network_event_sender,
swarm_cmd_sender,
#[cfg(feature = "open-metrics")]
None,
);

// Create a scratchpad
Expand Down Expand Up @@ -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<RecordKey> = vec![];
Expand Down Expand Up @@ -1528,6 +1541,8 @@ mod tests {
store_config,
network_event_sender,
swarm_cmd_sender,
#[cfg(feature = "open-metrics")]
None,
);

let mut stored_records: Vec<RecordKey> = vec![];
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Loading