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

feat(dre): number of nodes per subnet for node operators #1017

Merged
merged 2 commits into from
Oct 21, 2024
Merged
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
55 changes: 54 additions & 1 deletion rs/cli/src/commands/registry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use std::{collections::BTreeMap, path::PathBuf, str::FromStr, sync::Arc};
use std::{
collections::{BTreeMap, HashMap},
path::PathBuf,
str::FromStr,
sync::Arc,
};

use clap::Args;
use ic_management_backend::{
Expand Down Expand Up @@ -157,6 +162,7 @@ impl Registry {
node_operators: node_operators.values().cloned().collect_vec(),
node_rewards_table,
api_bns,
node_providers: get_node_providers(&local_registry).await?,
})
}
}
Expand Down Expand Up @@ -186,6 +192,10 @@ async fn get_node_operators(local_registry: &Arc<dyn LazyRegistry>, network: &Ne
});
// Find the number of nodes registered by this operator
let operator_registered_nodes_num = all_nodes.iter().filter(|(nk, _)| nk == &k).count() as u64;
let nodes_in_subnets = all_nodes
.iter()
.filter(|(_, value)| value.operator.principal == record.principal && value.subnet_id.is_some())
.count() as u64;
(
record.principal,
NodeOperator {
Expand All @@ -200,6 +210,7 @@ async fn get_node_operators(local_registry: &Arc<dyn LazyRegistry>, network: &Ne
total_up_nodes: 0,
nodes_health: Default::default(),
rewards_correct: false,
nodes_in_subnets,
},
)
})
Expand Down Expand Up @@ -407,6 +418,37 @@ fn get_api_boundary_nodes(local_registry: &Arc<dyn LazyRegistry>) -> anyhow::Res
Ok(api_bns)
}

async fn get_node_providers(local_registry: &Arc<dyn LazyRegistry>) -> anyhow::Result<Vec<NodeProvider>> {
let all_nodes = local_registry.nodes().await?;
let node_providers = local_registry
.operators()
.await?
.values()
.map(|operator| operator.provider.clone())
.dedup_by(|x, y| x.principal == y.principal)
.collect_vec();

Ok(node_providers
.iter()
.map(|provider| {
let provider_nodes = all_nodes.values().filter(|node| node.operator.provider.principal == provider.principal);

NodeProvider {
principal: provider.principal,
total_nodes: provider_nodes.clone().count(),
nodes_in_subnet: provider_nodes.clone().filter(|node| node.subnet_id.is_some()).count(),
nodes_per_dc: provider_nodes
.map(|node| match &node.operator.datacenter {
Some(dc) => dc.name.clone(),
None => "Unknown".to_string(),
})
.counts_by(|dc_name| dc_name),
name: provider.name.clone().unwrap_or("Unknown".to_string()),
}
})
.collect())
}

#[derive(Debug, Serialize)]
struct RegistryDump {
subnets: Vec<SubnetRecord>,
Expand All @@ -418,6 +460,7 @@ struct RegistryDump {
api_bns: Vec<ApiBoundaryNodeDetails>,
elected_guest_os_versions: Vec<ReplicaVersionRecord>,
elected_host_os_versions: Vec<HostosVersionRecord>,
node_providers: Vec<NodeProvider>,
}

#[derive(Clone, Debug, Serialize)]
Expand Down Expand Up @@ -482,6 +525,7 @@ struct NodeOperator {
total_up_nodes: u32,
nodes_health: IndexMap<String, Vec<PrincipalId>>,
rewards_correct: bool,
nodes_in_subnets: u64,
}

// We re-create the rewards structs here in order to convert the output of get-rewards-table into the format
Expand Down Expand Up @@ -513,6 +557,15 @@ pub struct NodeRewardsTableFlattened {
pub table: BTreeMap<String, NodeRewardRatesFlattened>,
}

#[derive(serde::Serialize, Debug)]
struct NodeProvider {
name: String,
principal: PrincipalId,
total_nodes: usize,
nodes_in_subnet: usize,
nodes_per_dc: HashMap<String, usize>,
}

#[derive(Debug, Clone)]
enum Comparison {
Equal,
Expand Down
Loading