diff --git a/examples/monitoring/src/main.rs b/examples/monitoring/src/main.rs index 91ddfd3..18ba474 100644 --- a/examples/monitoring/src/main.rs +++ b/examples/monitoring/src/main.rs @@ -1,6 +1,6 @@ use harmony::{ inventory::Inventory, maestro::Maestro, - modules::monitoring::monitoring_alerting::MonitoringAlertingScore, + modules::monitoring::monitoring_alerting::{MonitoringAlertingScore, MonitoringSystem}, topology::K8sAnywhereTopology, }; @@ -13,10 +13,11 @@ async fn main() { .await .unwrap(); - let monitoring = MonitoringAlertingScore { - alert_channel_configs: None, - }; - - maestro.register_all(vec![Box::new(monitoring)]); + //let monitoring = MonitoringAlertingScore { + // alert_receivers: vec![], + // alert_rules: vec![], + // scrape_targets: vec![], + //}; + //maestro.register_all(vec![Box::new(monitoring)]); harmony_cli::init(maestro, None).await.unwrap(); } 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 6f5b3c8..7556c54 100644 --- a/harmony/src/modules/monitoring/alert_channel/discord_alert_channel.rs +++ b/harmony/src/modules/monitoring/alert_channel/discord_alert_channel.rs @@ -1,3 +1,4 @@ +use log::debug; use serde::Serialize; use crate::{ @@ -14,16 +15,16 @@ pub struct DiscordWebhook { } impl AlertReceiver for DiscordWebhook { - type Sender = Prometheus; + type M = Prometheus; - fn install(&self, sender: &Self::Sender) -> Result<(), String> { - sender.configure_receiver(Box::new(self)) + fn install(&self, sender: &Self::M) -> Result<(), String> { + sender.configure_receiver(Box::new(self))?; + debug!("DiscordWebhook installed for Prometheus"); + Ok(()) } - fn clone(&self) -> Self - where - Self: Sized { - ::clone(self) + fn clone_box(&self) -> Box> { + Box::new(self.clone()) } } diff --git a/harmony/src/modules/monitoring/alert_receiver.rs b/harmony/src/modules/monitoring/alert_receiver.rs index 0943d6e..53251cd 100644 --- a/harmony/src/modules/monitoring/alert_receiver.rs +++ b/harmony/src/modules/monitoring/alert_receiver.rs @@ -9,27 +9,28 @@ use crate::{ topology::Topology, }; -use super::prometheus::AlertSender; +use super::monitoring_alerting::MonitoringSystem; + pub trait AlertReceiver: Debug + Send + Sync { - type Sender: AlertSender; + type M: MonitoringSystem; - fn install(&self, sender: &Self::Sender) -> Result<(), String>; - fn clone_box(&self) -> Box>; + fn install(&self, sender: &Self::M) -> Result<(), String>; + fn clone_box(&self) -> Box>; } -struct AlertReceiverConfig { +struct AlertReceiverConfig { config: String, // Or whatever - sender: S, + sender: M, } #[derive(Debug)] -pub struct AlertReceiverInterpret { - pub receiver: Box>, +pub struct AlertReceiverInterpret { + pub receiver: Box>, } #[async_trait] -impl Interpret for AlertReceiverInterpret { +impl Interpret for AlertReceiverInterpret { async fn execute( &self, _inventory: &Inventory, diff --git a/harmony/src/modules/monitoring/alert_rule.rs b/harmony/src/modules/monitoring/alert_rule.rs index d9fbca3..f6fd535 100644 --- a/harmony/src/modules/monitoring/alert_rule.rs +++ b/harmony/src/modules/monitoring/alert_rule.rs @@ -2,10 +2,12 @@ use std::fmt::Debug; use dyn_clone::DynClone; -use super::prometheus::AlertSender; +use super::monitoring_alerting::MonitoringSystem; + pub trait AlertRule: Debug + Send + Sync + DynClone { - type Sender: AlertSender; + type M: MonitoringSystem; - fn install(&self, sender: &Self::Sender); + fn install(&self, sender: &Self::M); + fn clone_box(&self) -> Box>; } diff --git a/harmony/src/modules/monitoring/monitoring_alerting.rs b/harmony/src/modules/monitoring/monitoring_alerting.rs index b612cba..cbf830e 100644 --- a/harmony/src/modules/monitoring/monitoring_alerting.rs +++ b/harmony/src/modules/monitoring/monitoring_alerting.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use async_trait::async_trait; +use log::debug; use serde::Serialize; use crate::{ @@ -11,37 +12,42 @@ use crate::{ topology::Topology, }; -use super::{alert_receiver::AlertReceiver, prometheus::AlertSender}; +use super::{alert_receiver::AlertReceiver, prometheus::Installable}; use super::alert_rule::AlertRule; use super::scrape_target::ScrapeTarget; -pub trait MonitoringSystem: std::fmt::Debug + Clone + Serialize + 'static {} +#[async_trait] +pub trait MonitoringSystem: std::fmt::Debug + Clone + Serialize + 'static + Send + Sync { +} #[derive(Debug, Clone)] pub struct MonitoringAlertingScore { - pub alert_receivers: Vec>>, - pub alert_rules: Vec>>, - pub scrape_targets: Vec>>, + pub alert_receivers: Vec>>, + pub alert_rules: Vec>>, + pub scrape_targets: Vec>>, } +#[derive(Clone)] +struct MonitoringConfig { + receivers: Vec>>, +} -impl Clone for Box>{ +impl Clone for Box> { fn clone(&self) -> Self { self.clone_box() } } -impl Clone for Box>{ +impl Clone for Box> { fn clone(&self) -> Self { - todo!() + self.clone_box() } } -impl Clone for Box>{ +impl Clone for Box> { fn clone(&self) -> Self { - todo!() + self.clone_box() } } - impl Serialize for MonitoringAlertingScore { fn serialize(&self, serializer: S) -> Result where @@ -51,7 +57,9 @@ impl Serialize for MonitoringAlertingScore { } } -impl Score for MonitoringAlertingScore { +impl Score + for MonitoringAlertingScore +{ fn create_interpret(&self) -> Box> { Box::new(MonitoringAlertingInterpret { score: Arc::new(self.clone()), @@ -68,14 +76,19 @@ struct MonitoringAlertingInterpret { score: Arc>, } + + #[async_trait] -impl Interpret for MonitoringAlertingInterpret { +impl Interpret + for MonitoringAlertingInterpret +{ async fn execute( &self, inventory: &Inventory, topology: &T, ) -> Result { - todo!() + debug!("score {:#?}", self.score); + monitoring_system.install().await } fn get_name(&self) -> InterpretName { @@ -94,3 +107,9 @@ impl Interpret for MonitoringAlertingInterp todo!() } } + +impl MonitoringAlertingInterpret { + fn build_config(&self) -> MonitoringConfig { + todo!() + } +} diff --git a/harmony/src/modules/monitoring/prometheus.rs b/harmony/src/modules/monitoring/prometheus.rs index e6d2e76..b849d5d 100644 --- a/harmony/src/modules/monitoring/prometheus.rs +++ b/harmony/src/modules/monitoring/prometheus.rs @@ -6,22 +6,18 @@ use crate::{ data::{Id, Version}, interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, inventory::Inventory, - topology::Topology, + topology::{HelmCommand, K8sAnywhereTopology, Topology}, }; use std::fmt::Debug; -use super::monitoring_alerting::MonitoringSystem; - -pub trait AlertSender: std::fmt::Debug {} +use super::monitoring_alerting::{MonitoringSystem, MonitoringSystemInstaller}; #[derive(Debug, Clone, Serialize)] pub struct Prometheus {} impl Prometheus { - pub fn configure_receiver( - &self, - _receiver: Box<&dyn PrometheusReceiver>, - ) -> Result<(), String> { + pub fn configure_receiver(&self, receiver: Box<&dyn PrometheusReceiver>) -> Result<(), String> { + let receiver_config = receiver.get_prometheus_config(); todo!() } pub fn configure_rule(&self, _rule: Box<&dyn PrometheusRule>) { @@ -40,8 +36,6 @@ pub trait PrometheusCapability { fn install_scrape_targets(&self, receivers: Vec>); } -impl AlertSender for Prometheus {} - pub trait PrometheusReceiver { fn get_prometheus_config(&self) -> PrometheusReceiverConfig; } @@ -102,3 +96,17 @@ impl Interpret for PrometheusMonitoringIn todo!() } } + +#[async_trait] +pub trait Installable { + async fn install(&self) -> Result; + type Installer; +} + +#[async_trait] +impl Installable for Prometheus { + type Installer = K8sAnywhereTopology; + async fn install(&self) -> Result { + todo!() + } +} diff --git a/harmony/src/modules/monitoring/scrape_target.rs b/harmony/src/modules/monitoring/scrape_target.rs index 37d35b7..86e3b2d 100644 --- a/harmony/src/modules/monitoring/scrape_target.rs +++ b/harmony/src/modules/monitoring/scrape_target.rs @@ -2,11 +2,13 @@ use std::fmt::Debug; use dyn_clone::DynClone; -use super::prometheus::AlertSender; +use super::monitoring_alerting::MonitoringSystem; + pub trait ScrapeTarget: Debug + Send + Sync + DynClone { - type Sender: AlertSender; + type M: MonitoringSystem; - fn install(&self, sender: &Self::Sender); + fn install(&self, sender: &Self::M); + fn clone_box(&self) -> Box>; }