From dec4b76b577530babd153a3c37003648ffb66c1a Mon Sep 17 00:00:00 2001 From: tahahawa Date: Fri, 20 Jun 2025 16:10:16 -0400 Subject: [PATCH] fix checks --- examples/lamp/src/main.rs | 2 +- .../topology/oberservability/monitoring.rs | 4 +++- .../alert_channel/discord_alert_channel.rs | 12 +++++----- .../monitoring/kube_prometheus/helm/config.rs | 3 +-- .../helm/kube_prometheus_helm_chart.rs | 23 ++++++++----------- .../helm_prometheus_alert_score.rs | 1 - .../monitoring/kube_prometheus/prometheus.rs | 19 +++++++++------ 7 files changed, 33 insertions(+), 31 deletions(-) diff --git a/examples/lamp/src/main.rs b/examples/lamp/src/main.rs index 4518165..276e255 100644 --- a/examples/lamp/src/main.rs +++ b/examples/lamp/src/main.rs @@ -43,7 +43,7 @@ async fn main() { // K8sAnywhereTopology as it is the most automatic one that enables you to easily deploy // locally, to development environment from a CI, to staging, and to production with settings // that automatically adapt to each environment grade. - let mut maestro = Maestro::::initialize( + let maestro = Maestro::::initialize( Inventory::autoload(), K8sAnywhereTopology::from_env(), ) diff --git a/harmony/src/domain/topology/oberservability/monitoring.rs b/harmony/src/domain/topology/oberservability/monitoring.rs index c66cfc2..3cdd1bd 100644 --- a/harmony/src/domain/topology/oberservability/monitoring.rs +++ b/harmony/src/domain/topology/oberservability/monitoring.rs @@ -19,7 +19,9 @@ pub struct AlertingInterpret { } #[async_trait] -impl, T: Topology + HelmCommand> Interpret for AlertingInterpret { +impl, T: Topology + HelmCommand> Interpret + for AlertingInterpret +{ async fn execute( &self, inventory: &Inventory, diff --git a/harmony/src/modules/monitoring/alert_channel/discord_alert_channel.rs b/harmony/src/modules/monitoring/alert_channel/discord_alert_channel.rs index 05e313e..fb85a98 100644 --- a/harmony/src/modules/monitoring/alert_channel/discord_alert_channel.rs +++ b/harmony/src/modules/monitoring/alert_channel/discord_alert_channel.rs @@ -1,4 +1,5 @@ use async_trait::async_trait; +use serde::Serialize; use serde_yaml::{Mapping, Value}; use crate::{ @@ -10,7 +11,7 @@ use crate::{ topology::{Url, oberservability::monitoring::AlertReceiver}, }; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize)] pub struct DiscordWebhook { pub name: String, pub url: Url, @@ -52,7 +53,6 @@ impl AlertChannelConfig for DiscordWebhook { } impl DiscordWebhook { - async fn alert_channel_route(&self) -> serde_yaml::Value { let mut route = Mapping::new(); route.insert( @@ -93,15 +93,15 @@ impl DiscordWebhook { mod tests { use super::*; - #[test] - fn discord_serialize_should_match() { + #[tokio::test] + async fn discord_serialize_should_match() { let discord_receiver = DiscordWebhook { name: "test-discord".to_string(), url: Url::Url(url::Url::parse("https://discord.i.dont.exist.com").unwrap()), }; let discord_receiver_receiver = - serde_yaml::to_string(&discord_receiver.alert_channel_receiver()).unwrap(); + serde_yaml::to_string(&discord_receiver.alert_channel_receiver().await).unwrap(); println!("receiver \n{:#}", discord_receiver_receiver); let discord_receiver_receiver_yaml = r#"name: test-discord discord_configs: @@ -110,7 +110,7 @@ discord_configs: .to_string(); let discord_receiver_route = - serde_yaml::to_string(&discord_receiver.alert_channel_route()).unwrap(); + serde_yaml::to_string(&discord_receiver.alert_channel_route().await).unwrap(); println!("route \n{:#}", discord_receiver_route); let discord_receiver_route_yaml = r#"receiver: test-discord matchers: diff --git a/harmony/src/modules/monitoring/kube_prometheus/helm/config.rs b/harmony/src/modules/monitoring/kube_prometheus/helm/config.rs index 631d9d8..741cd1b 100644 --- a/harmony/src/modules/monitoring/kube_prometheus/helm/config.rs +++ b/harmony/src/modules/monitoring/kube_prometheus/helm/config.rs @@ -1,7 +1,6 @@ use serde::Serialize; -use serde_yaml::Value; -use crate::modules::monitoring::kube_prometheus::{prometheus::PrometheusReceiver, types::AlertManagerChannelConfig}; +use crate::modules::monitoring::kube_prometheus::types::AlertManagerChannelConfig; #[derive(Debug, Clone, Serialize)] pub struct KubePrometheusConfig { diff --git a/harmony/src/modules/monitoring/kube_prometheus/helm/kube_prometheus_helm_chart.rs b/harmony/src/modules/monitoring/kube_prometheus/helm/kube_prometheus_helm_chart.rs index 8420fca..c262cae 100644 --- a/harmony/src/modules/monitoring/kube_prometheus/helm/kube_prometheus_helm_chart.rs +++ b/harmony/src/modules/monitoring/kube_prometheus/helm/kube_prometheus_helm_chart.rs @@ -10,8 +10,7 @@ use std::{ use crate::modules::{ helm::chart::HelmChartScore, monitoring::kube_prometheus::types::{ - AlertManager, AlertManagerChannelConfig, AlertManagerConfig, AlertManagerRoute, - AlertManagerValues, + AlertManager, AlertManagerConfig, AlertManagerRoute, AlertManagerValues, }, }; @@ -157,18 +156,16 @@ prometheus: "#, ); - let mut null_receiver = Mapping::new(); - null_receiver.insert( - Value::String("receiver".to_string()), - Value::String("null".to_string()), - ); - null_receiver.insert( - Value::String("matchers".to_string()), - Value::Sequence(vec![Value::String("alertname!=Watchdog".to_string())]), - ); - null_receiver.insert(Value::String("continue".to_string()), Value::Bool(true)); - + null_receiver.insert( + Value::String("receiver".to_string()), + Value::String("null".to_string()), + ); + null_receiver.insert( + Value::String("matchers".to_string()), + Value::Sequence(vec![Value::String("alertname!=Watchdog".to_string())]), + ); + null_receiver.insert(Value::String("continue".to_string()), Value::Bool(true)); let mut alert_manager_channel_config = AlertManagerConfig { global: Mapping::new(), diff --git a/harmony/src/modules/monitoring/kube_prometheus/helm_prometheus_alert_score.rs b/harmony/src/modules/monitoring/kube_prometheus/helm_prometheus_alert_score.rs index 1d8cbaf..f1f5322 100644 --- a/harmony/src/modules/monitoring/kube_prometheus/helm_prometheus_alert_score.rs +++ b/harmony/src/modules/monitoring/kube_prometheus/helm_prometheus_alert_score.rs @@ -6,7 +6,6 @@ use crate::{ score::Score, topology::{ HelmCommand, Topology, - installable::Installable, oberservability::monitoring::{AlertReceiver, AlertingInterpret}, }, }; diff --git a/harmony/src/modules/monitoring/kube_prometheus/prometheus.rs b/harmony/src/modules/monitoring/kube_prometheus/prometheus.rs index f4a81d8..e7ddb9a 100644 --- a/harmony/src/modules/monitoring/kube_prometheus/prometheus.rs +++ b/harmony/src/modules/monitoring/kube_prometheus/prometheus.rs @@ -2,23 +2,24 @@ use std::sync::{Arc, Mutex}; use async_trait::async_trait; use log::debug; -use serde_yaml::Value; use crate::{ interpret::{InterpretError, Outcome}, inventory::Inventory, score, topology::{ - HelmCommand, K8sAnywhereTopology, Topology, installable::Installable, - oberservability::monitoring::AlertSender, + HelmCommand, Topology, installable::Installable, oberservability::monitoring::AlertSender, }, }; use score::Score; -use super::{helm::{ - config::KubePrometheusConfig, kube_prometheus_helm_chart::kube_prometheus_helm_chart_score, -}, types::AlertManagerChannelConfig}; +use super::{ + helm::{ + config::KubePrometheusConfig, kube_prometheus_helm_chart::kube_prometheus_helm_chart_score, + }, + types::AlertManagerChannelConfig, +}; #[async_trait] impl AlertSender for Prometheus { @@ -29,7 +30,11 @@ impl AlertSender for Prometheus { #[async_trait] impl Installable for Prometheus { - async fn ensure_installed(&self, inventory: &Inventory, topology: &T) -> Result<(), InterpretError> { + async fn ensure_installed( + &self, + inventory: &Inventory, + topology: &T, + ) -> Result<(), InterpretError> { //install_prometheus self.install_prometheus(inventory, topology).await?; Ok(())