From d11cedbb6e476728af7fa3084abb91800c154750 Mon Sep 17 00:00:00 2001 From: Andre Popovitch Date: Mon, 25 Nov 2024 15:48:00 -0600 Subject: [PATCH] feat(sns): Add indication of whether a canister is frozen in `sns health` (#2804) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Example output: | Name | Memory | Cycles | Upgrades Remaining | |-------------------------|---------------------|--------------------------------------------------------------------------------------------------------------------------------|--------------------| | BOOM DAO | 👍 | ❌ governance: (6.96 TC), index: (0.00 TC 🥶) | 24 | | CYCLES-TRANSFER-STATION | 👍 | 👍 | 8 | | Catalyze | 👍 | ❌ governance: (9.76 TC), swap: (8.83 TC), archive: (9.30 TC) | 1 | (This is using test data, BOOM DAO's index canister is fine) The benefit of this is that it draws attention to the canisters that are really in trouble - the frozen ones. The definition of frozen used by the tool is: the number of cycles is below the freezing threshold (as reported by the canister summary) --- rs/sns/cli/src/health.rs | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/rs/sns/cli/src/health.rs b/rs/sns/cli/src/health.rs index 87590de709d..0b316ccdb05 100644 --- a/rs/sns/cli/src/health.rs +++ b/rs/sns/cli/src/health.rs @@ -20,11 +20,17 @@ pub struct HealthArgs { include_dapps: bool, } +#[derive(Debug, Serialize, Deserialize)] +struct Cycles { + cycles: u128, + freezing_threshold: u64, +} + #[derive(Debug, Serialize, Deserialize)] struct SnsHealthInfo { name: String, memory_consumption: Vec<(u64, SnsCanisterType)>, - cycles: Vec<(u64, SnsCanisterType)>, + cycles: Vec<(Cycles, SnsCanisterType)>, num_remaining_upgrade_steps: usize, } @@ -34,16 +40,21 @@ impl TableRow for SnsHealthInfo { } fn column_values(&self) -> Vec { + const MEMORY_THRESHOLD_GIB: f64 = 2.5; + const CYCLES_THRESHOLD_TC: f64 = 10.0; + const GIB: f64 = 1024.0 * 1024.0 * 1024.0; + const TC: f64 = 1000.0 * 1000.0 * 1000.0 * 1000.0; + let high_memory_consumption = self .memory_consumption .iter() .filter(|(memory_consumption, _)| { - (*memory_consumption as f64) > 2.5 * 1024.0 * 1024.0 * 1024.0 + (*memory_consumption as f64) > MEMORY_THRESHOLD_GIB * GIB }) .map(|(memory_consumption, canister_type)| { format!( "{canister_type}: ({:.2} GiB)", - *memory_consumption as f64 / 1024.0 / 1024.0 / 1024.0 + *memory_consumption as f64 / GIB ) }) .join(", "); @@ -57,11 +68,16 @@ impl TableRow for SnsHealthInfo { let low_cycles = self .cycles .iter() - .filter(|(cycles, _)| (*cycles as f64) < 10.0 * 1000.0 * 1000.0 * 1000.0 * 1000.0) + .filter(|(cycles, _)| (cycles.cycles as f64) < CYCLES_THRESHOLD_TC * TC) .map(|(cycles, canister_type)| { format!( - "{canister_type}: ({:.2} TC)", - *cycles as f64 / 1000.0 / 1000.0 / 1000.0 / 1000.0 + "{canister_type}: ({:.2} TC{frozen})", + cycles.cycles as f64 / TC, + frozen = if cycles.cycles < cycles.freezing_threshold as u128 { + " 🥶".to_string() + } else { + "".to_string() + } ) }) .join(", "); @@ -128,7 +144,16 @@ pub async fn exec(args: HealthArgs, agent: &Agent) -> Result<()> { .map(|(canister_status, ctype)| { ( (u64::try_from(canister_status.memory_size.0).unwrap(), ctype), - (u64::try_from(canister_status.cycles.0).unwrap(), ctype), + ( + Cycles { + freezing_threshold: u64::try_from( + canister_status.settings.freezing_threshold.0, + ) + .unwrap(), + cycles: u128::try_from(canister_status.cycles.0).unwrap(), + }, + ctype, + ), ) }) .unzip();