diff --git a/harmony/src/domain/instrumentation.rs b/harmony/src/domain/instrumentation.rs index eaea6f7..79787ec 100644 --- a/harmony/src/domain/instrumentation.rs +++ b/harmony/src/domain/instrumentation.rs @@ -13,11 +13,13 @@ pub enum HarmonyEvent { InterpretExecutionStarted { topology: String, interpret: String, + score: String, message: String, }, InterpretExecutionFinished { topology: String, interpret: String, + score: String, outcome: Result, }, TopologyStateChanged { diff --git a/harmony/src/domain/interpret/mod.rs b/harmony/src/domain/interpret/mod.rs index fca1817..cfbf2b5 100644 --- a/harmony/src/domain/interpret/mod.rs +++ b/harmony/src/domain/interpret/mod.rs @@ -24,6 +24,14 @@ pub enum InterpretName { TenantInterpret, Application, ArgoCD, + Alerting, + Ntfy, + HelmChart, + HelmCommand, + K8sResource, + Lamp, + ApplicationMonitoring, + K8sPrometheusCrdAlerting, } impl std::fmt::Display for InterpretName { @@ -42,6 +50,14 @@ impl std::fmt::Display for InterpretName { InterpretName::TenantInterpret => f.write_str("Tenant"), InterpretName::Application => f.write_str("Application"), InterpretName::ArgoCD => f.write_str("ArgoCD"), + InterpretName::Alerting => f.write_str("Alerting"), + InterpretName::Ntfy => f.write_str("Ntfy"), + InterpretName::HelmChart => f.write_str("HelmChart"), + InterpretName::HelmCommand => f.write_str("HelmCommand"), + InterpretName::K8sResource => f.write_str("K8sResource"), + InterpretName::Lamp => f.write_str("LAMP"), + InterpretName::ApplicationMonitoring => f.write_str("ApplicationMonitoring"), + InterpretName::K8sPrometheusCrdAlerting => f.write_str("K8sPrometheusCrdAlerting"), } } } diff --git a/harmony/src/domain/score.rs b/harmony/src/domain/score.rs index 00bb063..140d7f1 100644 --- a/harmony/src/domain/score.rs +++ b/harmony/src/domain/score.rs @@ -5,6 +5,7 @@ use serde::Serialize; use serde_value::Value; use super::{ + instrumentation::{self, HarmonyEvent}, interpret::{Interpret, InterpretError, Outcome}, inventory::Inventory, topology::Topology, @@ -20,7 +21,25 @@ pub trait Score: topology: &T, ) -> Result { let interpret = self.create_interpret(); - interpret.execute(inventory, topology).await + + instrumentation::instrument(HarmonyEvent::InterpretExecutionStarted { + topology: topology.name().into(), + interpret: interpret.get_name().to_string(), + score: self.name(), + message: format!("{} running...", interpret.get_name()), + }) + .unwrap(); + let result = interpret.execute(inventory, topology).await; + + instrumentation::instrument(HarmonyEvent::InterpretExecutionFinished { + topology: topology.name().into(), + interpret: interpret.get_name().to_string(), + score: self.name(), + outcome: result.clone(), + }) + .unwrap(); + + result } fn name(&self) -> String; diff --git a/harmony/src/domain/topology/oberservability/monitoring.rs b/harmony/src/domain/topology/oberservability/monitoring.rs index 7fa6eb4..c2e93d6 100644 --- a/harmony/src/domain/topology/oberservability/monitoring.rs +++ b/harmony/src/domain/topology/oberservability/monitoring.rs @@ -45,7 +45,7 @@ impl, T: Topology> Interpret for AlertingInte } fn get_name(&self) -> InterpretName { - todo!() + InterpretName::Alerting } fn get_version(&self) -> Version { diff --git a/harmony/src/modules/helm/chart.rs b/harmony/src/modules/helm/chart.rs index c4321d4..b21aa50 100644 --- a/harmony/src/modules/helm/chart.rs +++ b/harmony/src/modules/helm/chart.rs @@ -240,9 +240,11 @@ impl Interpret for HelmChartInterpret { )), } } + fn get_name(&self) -> InterpretName { - todo!() + InterpretName::HelmChart } + fn get_version(&self) -> Version { todo!() } diff --git a/harmony/src/modules/helm/command.rs b/harmony/src/modules/helm/command.rs index 60c6fb6..149d6c6 100644 --- a/harmony/src/modules/helm/command.rs +++ b/harmony/src/modules/helm/command.rs @@ -349,7 +349,7 @@ impl Interpret for HelmChartInterpretV } fn get_name(&self) -> InterpretName { - todo!() + InterpretName::HelmCommand } fn get_version(&self) -> Version { todo!() diff --git a/harmony/src/modules/k3d/install.rs b/harmony/src/modules/k3d/install.rs index 9490dee..d51e005 100644 --- a/harmony/src/modules/k3d/install.rs +++ b/harmony/src/modules/k3d/install.rs @@ -37,7 +37,7 @@ impl Score for K3DInstallationScore { } fn name(&self) -> String { - todo!() + "K3dInstallationScore".into() } } @@ -51,20 +51,14 @@ impl Interpret for K3dInstallationInterpret { async fn execute( &self, _inventory: &Inventory, - topology: &T, + _topology: &T, ) -> Result { - instrumentation::instrument(HarmonyEvent::InterpretExecutionStarted { - topology: topology.name().into(), - interpret: "k3d-installation".into(), - message: "installing k3d...".into(), - }) - .unwrap(); - let k3d = k3d_rs::K3d::new( self.score.installation_path.clone(), Some(self.score.cluster_name.clone()), ); - let outcome = match k3d.ensure_installed().await { + + match k3d.ensure_installed().await { Ok(_client) => { let msg = format!("k3d cluster '{}' installed ", self.score.cluster_name); debug!("{msg}"); @@ -73,16 +67,7 @@ impl Interpret for K3dInstallationInterpret { Err(msg) => Err(InterpretError::new(format!( "failed to ensure k3d is installed : {msg}" ))), - }; - - instrumentation::instrument(HarmonyEvent::InterpretExecutionFinished { - topology: topology.name().into(), - interpret: "k3d-installation".into(), - outcome: outcome.clone(), - }) - .unwrap(); - - outcome + } } fn get_name(&self) -> InterpretName { InterpretName::K3dInstallation diff --git a/harmony/src/modules/k8s/resource.rs b/harmony/src/modules/k8s/resource.rs index 3c0b2bf..b6709ea 100644 --- a/harmony/src/modules/k8s/resource.rs +++ b/harmony/src/modules/k8s/resource.rs @@ -89,7 +89,7 @@ where )) } fn get_name(&self) -> InterpretName { - todo!() + InterpretName::K8sResource } fn get_version(&self) -> Version { todo!() diff --git a/harmony/src/modules/lamp.rs b/harmony/src/modules/lamp.rs index 09c4592..1a853ea 100644 --- a/harmony/src/modules/lamp.rs +++ b/harmony/src/modules/lamp.rs @@ -160,7 +160,7 @@ impl Interpret for LAMPInterpret { } fn get_name(&self) -> InterpretName { - todo!() + InterpretName::Lamp } fn get_version(&self) -> Version { diff --git a/harmony/src/modules/monitoring/application_monitoring/application_monitoring_score.rs b/harmony/src/modules/monitoring/application_monitoring/application_monitoring_score.rs index b016db5..1bcaacc 100644 --- a/harmony/src/modules/monitoring/application_monitoring/application_monitoring_score.rs +++ b/harmony/src/modules/monitoring/application_monitoring/application_monitoring_score.rs @@ -69,7 +69,7 @@ impl> Interpret } fn get_name(&self) -> InterpretName { - todo!() + InterpretName::ApplicationMonitoring } fn get_version(&self) -> Version { diff --git a/harmony/src/modules/monitoring/ntfy/ntfy.rs b/harmony/src/modules/monitoring/ntfy/ntfy.rs index f57e680..2622c28 100644 --- a/harmony/src/modules/monitoring/ntfy/ntfy.rs +++ b/harmony/src/modules/monitoring/ntfy/ntfy.rs @@ -28,7 +28,7 @@ impl Score for NtfyScore { } fn name(&self) -> String { - "Ntfy".to_string() + "NtfyScore".to_string() } } @@ -123,8 +123,9 @@ impl Interpret for NtfyInterpret { } fn get_name(&self) -> InterpretName { - todo!() + InterpretName::Ntfy } + fn get_version(&self) -> Version { todo!() } diff --git a/harmony/src/modules/prometheus/k8s_prometheus_alerting_score.rs b/harmony/src/modules/prometheus/k8s_prometheus_alerting_score.rs index e806c63..df8fc49 100644 --- a/harmony/src/modules/prometheus/k8s_prometheus_alerting_score.rs +++ b/harmony/src/modules/prometheus/k8s_prometheus_alerting_score.rs @@ -99,7 +99,7 @@ impl> I } fn get_name(&self) -> InterpretName { - todo!() + InterpretName::K8sPrometheusCrdAlerting } fn get_version(&self) -> Version { @@ -118,7 +118,7 @@ impl> I impl K8sPrometheusCRDAlertingInterpret { async fn crd_exists(&self, crd: &str) -> bool { let status = Command::new("sh") - .args(["-c", "kubectl get crd -A | grep -i", crd]) + .args(["-c", &format!("kubectl get crd -A | grep -i {crd}")]) .status() .map_err(|e| InterpretError::new(format!("could not connect to cluster: {}", e))) .unwrap(); diff --git a/harmony/src/modules/tenant/credentials.rs b/harmony/src/modules/tenant/credentials.rs index 0e5917a..2ee24ec 100644 --- a/harmony/src/modules/tenant/credentials.rs +++ b/harmony/src/modules/tenant/credentials.rs @@ -17,7 +17,7 @@ impl Score for TenantCredentialScore { } fn name(&self) -> String { - todo!() + "TenantCredentialScore".into() } } diff --git a/harmony_cli/src/cli_logger.rs b/harmony_cli/src/cli_logger.rs index 12665a6..455a4eb 100644 --- a/harmony_cli/src/cli_logger.rs +++ b/harmony_cli/src/cli_logger.rs @@ -107,12 +107,21 @@ async fn handle_events() { HarmonyEvent::InterpretExecutionStarted { topology, interpret, + score, message, } => { let section_key = if (*sections).contains_key(&topology_key(&topology)) { topology_key(&topology) + } else if (*sections).contains_key(&score_key(&score)) { + score_key(&interpret) } else { - interpret_key(&interpret) + let key = score_key(&score); + let section = progress::new_section(format!( + "\n{} Interpreting score: {score}...", + crate::theme::EMOJI_SCORE, + )); + (*sections).insert(key.clone(), section); + key }; let section = (*sections).get(§ion_key).unwrap(); let progress_bar = progress::add_spinner(section, message); @@ -122,13 +131,14 @@ async fn handle_events() { HarmonyEvent::InterpretExecutionFinished { topology, interpret, + score, outcome, } => { let has_topology = (*sections).contains_key(&topology_key(&topology)); let section_key = if has_topology { topology_key(&topology) } else { - interpret_key(&interpret) + score_key(&score) }; let section = (*sections).get(§ion_key).unwrap(); @@ -138,9 +148,15 @@ async fn handle_events() { let _ = section.clear(); match outcome { - Ok(outcome) => { - progress::success(section, progress_bar, outcome.message); - } + Ok(outcome) => match outcome.status { + harmony::interpret::InterpretStatus::SUCCESS => { + progress::success(section, progress_bar, outcome.message) + } + harmony::interpret::InterpretStatus::NOOP => { + progress::skip(section, progress_bar, outcome.message) + } + _ => progress::error(section, progress_bar, outcome.message), + }, Err(err) => { progress::error(section, progress_bar, err.to_string()); } @@ -162,6 +178,10 @@ fn topology_key(topology: &str) -> String { format!("topology-{topology}") } +fn score_key(score: &str) -> String { + format!("score-{score}") +} + fn interpret_key(interpret: &str) -> String { format!("interpret-{interpret}") } diff --git a/harmony_cli/src/theme.rs b/harmony_cli/src/theme.rs index ee25077..6a059c5 100644 --- a/harmony_cli/src/theme.rs +++ b/harmony_cli/src/theme.rs @@ -8,6 +8,7 @@ pub static EMOJI_SKIP: Emoji<'_, '_> = Emoji("⏭️", ""); pub static EMOJI_ERROR: Emoji<'_, '_> = Emoji("⚠️", ""); pub static EMOJI_DEPLOY: Emoji<'_, '_> = Emoji("🚀", ""); pub static EMOJI_TOPOLOGY: Emoji<'_, '_> = Emoji("📦", ""); +pub static EMOJI_SCORE: Emoji<'_, '_> = Emoji("🎶", ""); lazy_static! { pub static ref SPINNER_STYLE: ProgressStyle = ProgressStyle::default_spinner()