Skip to content

Commit

Permalink
expanding the view of registry with node provider data
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaMilosa committed Oct 18, 2024
1 parent dc6929d commit d31c92f
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 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 @@ -412,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 @@ -423,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 @@ -519,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

0 comments on commit d31c92f

Please sign in to comment.