diff --git a/examples/lamp/src/main.rs b/examples/lamp/src/main.rs index 37fd0f9..0b1f93c 100644 --- a/examples/lamp/src/main.rs +++ b/examples/lamp/src/main.rs @@ -4,10 +4,7 @@ use harmony::{ maestro::Maestro, modules::{ lamp::{LAMPConfig, LAMPScore}, - monitoring::{ - alert_channel::discord_alert_channel::DiscordWebhook, - monitoring_alerting::MonitoringAlertingScore, - }, + monitoring::alert_channel::discord_alert_channel::DiscordWebhook, }, topology::{K8sAnywhereTopology, Url}, }; @@ -35,15 +32,15 @@ async fn main() { }, }; - let monitoring = MonitoringAlertingScore { - alert_receivers: vec![Box::new(DiscordWebhook { - url: Url::Url(url::Url::parse("https://discord.idonotexist.com").unwrap()), - // TODO write url macro - // url: url!("https://discord.idonotexist.com"), - })], - alert_rules: vec![], - scrape_targets: vec![], - }; + //let monitoring = MonitoringAlertingScore { + // alert_receivers: vec![Box::new(DiscordWebhook { + // url: Url::Url(url::Url::parse("https://discord.idonotexist.com").unwrap()), + // // TODO write url macro + // // url: url!("https://discord.idonotexist.com"), + // })], + // alert_rules: vec![], + // scrape_targets: vec![], + //}; // You can choose the type of Topology you want, we suggest starting with the // K8sAnywhereTopology as it is the most automatic one that enables you to easily deploy @@ -57,7 +54,6 @@ async fn main() { .unwrap(); // maestro.register_all(vec![Box::new(lamp_stack)]); - maestro.register_all(vec![Box::new(monitoring)]); // Here we bootstrap the CLI, this gives some nice features if you need them harmony_cli::init(maestro, None).await.unwrap(); } diff --git a/examples/monitoring/src/main.rs b/examples/monitoring/src/main.rs index cccc999..d52c649 100644 --- a/examples/monitoring/src/main.rs +++ b/examples/monitoring/src/main.rs @@ -1,6 +1,7 @@ use harmony::{ inventory::Inventory, maestro::Maestro, - modules::monitoring::alert_score::HelmPrometheusAlertingScore, topology::K8sAnywhereTopology, + modules::monitoring::kube_prometheus::helm_prometheus_alert_score::HelmPrometheusAlertingScore, + topology::K8sAnywhereTopology, }; #[tokio::main] diff --git a/harmony/src/domain/topology/installable.rs b/harmony/src/domain/topology/installable.rs new file mode 100644 index 0000000..9b9054f --- /dev/null +++ b/harmony/src/domain/topology/installable.rs @@ -0,0 +1,8 @@ +use async_trait::async_trait; + +use crate::interpret::InterpretError; + +#[async_trait] +pub trait Installable { + async fn ensure_installed(&self) -> Result<(), InterpretError>; +} diff --git a/harmony/src/domain/topology/mod.rs b/harmony/src/domain/topology/mod.rs index faa7fee..7d3830d 100644 --- a/harmony/src/domain/topology/mod.rs +++ b/harmony/src/domain/topology/mod.rs @@ -1,6 +1,7 @@ mod ha_cluster; mod host_binding; mod http; +pub mod installable; mod k8s_anywhere; mod localhost; pub mod oberservability; diff --git a/harmony/src/domain/topology/oberservability/k8s.rs b/harmony/src/domain/topology/oberservability/k8s.rs deleted file mode 100644 index 004f9ec..0000000 --- a/harmony/src/domain/topology/oberservability/k8s.rs +++ /dev/null @@ -1,71 +0,0 @@ -use std::sync::Arc; - -use async_trait::async_trait; -use serde::Serialize; - -use crate::score::Score; - -use crate::topology::HelmCommand; -use crate::{ - interpret::{InterpretError, Outcome}, - inventory::Inventory, - topology::Topology, -}; - -use super::{ - K8sMonitorConfig, - monitoring::{AlertChannel, AlertChannelConfig, Monitor}, -}; - -#[derive(Debug, Clone, Serialize)] -pub struct K8sMonitor { - pub config: K8sMonitorConfig, -} - -#[async_trait] -impl Monitor for K8sMonitor { - async fn provision_monitor( - &self, - inventory: &Inventory, - topology: &T, - alert_channels: Option>>, - ) -> Result { - if let Some(channels) = alert_channels { - let alert_channels = self.build_alert_channels(channels).await?; - for channel in alert_channels { - channel.register_alert_channel().await?; - } - } - let chart = self.config.chart.clone(); - chart - .create_interpret() - .execute(inventory, topology) - .await?; - Ok(Outcome::success("installed monitor".to_string())) - } - - fn delete_monitor(&self) -> Result { - todo!() - } -} - -#[async_trait] -impl AlertChannelConfig for K8sMonitor { - async fn build_alert_channel(&self) -> Result, InterpretError> { - todo!() - } -} - -impl K8sMonitor { - pub async fn build_alert_channels( - &self, - alert_channel_configs: Vec>, - ) -> Result>, InterpretError> { - let mut alert_channels = Vec::new(); - for config in alert_channel_configs { - let channel = config.build_alert_channel().await?; - alert_channels.push(channel) - } - Ok(alert_channels) - } -} diff --git a/harmony/src/domain/topology/oberservability/mod.rs b/harmony/src/domain/topology/oberservability/mod.rs index 387709a..7f2ac95 100644 --- a/harmony/src/domain/topology/oberservability/mod.rs +++ b/harmony/src/domain/topology/oberservability/mod.rs @@ -1,23 +1 @@ -use serde::Serialize; - -use crate::modules::{ - helm::chart::HelmChartScore, - monitoring::kube_prometheus::kube_prometheus_helm_chart_score::kube_prometheus_helm_chart_score, -}; - -pub mod k8s; pub mod monitoring; - -#[derive(Debug, Clone, Serialize)] -pub struct K8sMonitorConfig { - //probably need to do something better here - pub chart: HelmChartScore, -} - -impl K8sMonitorConfig { - pub fn cluster_monitor() -> Self { - Self { - chart: kube_prometheus_helm_chart_score(), - } - } -} diff --git a/harmony/src/domain/topology/oberservability/monitoring.rs b/harmony/src/domain/topology/oberservability/monitoring.rs index 1d6a159..a3a6164 100644 --- a/harmony/src/domain/topology/oberservability/monitoring.rs +++ b/harmony/src/domain/topology/oberservability/monitoring.rs @@ -1,39 +1,61 @@ use async_trait::async_trait; -use dyn_clone::DynClone; -use std::fmt::Debug; -use crate::executors::ExecutorError; -use crate::interpret::InterpretError; +use crate::{ + data::{Id, Version}, + interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, + inventory::Inventory, + topology::{Topology, installable::Installable}, +}; -use crate::inventory::Inventory; -use crate::topology::HelmCommand; -use crate::{interpret::Outcome, topology::Topology}; +pub trait AlertSender: Send + Sync + std::fmt::Debug + Installable {} + +#[derive(Debug)] +pub struct AlertingInterpret { + pub sender: S, + pub receivers: Vec>>, +} -/// Represents an entity responsible for collecting and organizing observability data -/// from various telemetry sources such as Prometheus or Datadog -/// A `Monitor` abstracts the logic required to scrape, aggregate, and structure -/// monitoring data, enabling consistent processing regardless of the underlying data source. #[async_trait] -pub trait Monitor { - async fn provision_monitor( +impl Interpret for AlertingInterpret { + async fn execute( &self, inventory: &Inventory, topology: &T, - alert_receivers: Option>>, - ) -> Result; + ) -> Result { + for receiver in self.receivers.iter() { + receiver.install(&self.sender).await?; + } + todo!() + } - fn delete_monitor(&self) -> Result; + fn get_name(&self) -> InterpretName { + todo!() + } + + fn get_version(&self) -> Version { + todo!() + } + + fn get_status(&self) -> InterpretStatus { + todo!() + } + + fn get_children(&self) -> Vec { + todo!() + } } #[async_trait] -pub trait AlertChannel: Debug + Send + Sync { - async fn register_alert_channel(&self) -> Result; - //async fn get_channel_id(&self) -> String; +pub trait AlertReceiver: std::fmt::Debug + Send + Sync { + async fn install(&self, sender: &S) -> Result<(), InterpretError>; } #[async_trait] -pub trait AlertChannelConfig: Debug + Send + Sync + DynClone { - async fn build_alert_channel(&self) -> Result, InterpretError>; +pub trait AlertRule { + async fn install(&self, sender: &S) -> Result<(), InterpretError>; } -dyn_clone::clone_trait_object!(AlertChannelConfig); +#[async_trait] +pub trait ScrapeTarger { + async fn install(&self, sender: &S) -> Result<(), InterpretError>; +} 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 7556c54..42f4450 100644 --- a/harmony/src/modules/monitoring/alert_channel/discord_alert_channel.rs +++ b/harmony/src/modules/monitoring/alert_channel/discord_alert_channel.rs @@ -1,54 +1,20 @@ -use log::debug; -use serde::Serialize; +use async_trait::async_trait; use crate::{ - modules::monitoring::{ - alert_receiver::AlertReceiver, - prometheus::{Prometheus, PrometheusReceiver}, - }, - topology::Url, + interpret::InterpretError, + modules::monitoring::kube_prometheus::prometheus::{Prometheus, PrometheusReceiver}, + topology::{Url, oberservability::monitoring::AlertReceiver}, }; -#[derive(Debug, Clone, Serialize)] +#[derive(Debug)] pub struct DiscordWebhook { + pub name: String, pub url: Url, } -impl AlertReceiver for DiscordWebhook { - type M = Prometheus; - - fn install(&self, sender: &Self::M) -> Result<(), String> { - sender.configure_receiver(Box::new(self))?; - debug!("DiscordWebhook installed for Prometheus"); - Ok(()) - } - - fn clone_box(&self) -> Box> { - Box::new(self.clone()) +#[async_trait] +impl AlertReceiver for DiscordWebhook { + async fn install(&self, sender: &Prometheus) -> Result<(), InterpretError> { + sender.install_receiver(PrometheusReceiver {}).await } } - -impl PrometheusReceiver for DiscordWebhook { - fn get_prometheus_config( - &self, - ) -> crate::modules::monitoring::prometheus::PrometheusReceiverConfig { - todo!() - } -} - -// #[derive(Debug, Clone, Serialize)] -// pub struct DiscordWebhookScore { -// pub config: DiscordWebhook, -// } -// -// impl Score for DiscordWebhookScore { -// fn create_interpret(&self) -> Box> { -// Box::new(AlertReceiverInterpret { -// receiver: Box::new(self.config.clone()), -// }) -// } -// -// fn name(&self) -> String { -// todo!() -// } -// } diff --git a/harmony/src/modules/monitoring/alert_receiver.rs b/harmony/src/modules/monitoring/alert_receiver.rs deleted file mode 100644 index 53251cd..0000000 --- a/harmony/src/modules/monitoring/alert_receiver.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::fmt::Debug; - -use async_trait::async_trait; - -use crate::{ - data::{Id, Version}, - interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, - inventory::Inventory, - topology::Topology, -}; - -use super::monitoring_alerting::MonitoringSystem; - - -pub trait AlertReceiver: Debug + Send + Sync { - type M: MonitoringSystem; - - fn install(&self, sender: &Self::M) -> Result<(), String>; - fn clone_box(&self) -> Box>; -} - -struct AlertReceiverConfig { - config: String, // Or whatever - sender: M, -} - -#[derive(Debug)] -pub struct AlertReceiverInterpret { - pub receiver: Box>, -} - -#[async_trait] -impl Interpret for AlertReceiverInterpret { - async fn execute( - &self, - _inventory: &Inventory, - _topology: &T, - ) -> Result { - todo!() - } - - fn get_name(&self) -> InterpretName { - todo!() - } - - fn get_version(&self) -> Version { - todo!() - } - - fn get_status(&self) -> InterpretStatus { - todo!() - } - - fn get_children(&self) -> Vec { - todo!() - } -} diff --git a/harmony/src/modules/monitoring/alert_rule.rs b/harmony/src/modules/monitoring/alert_rule.rs deleted file mode 100644 index f6fd535..0000000 --- a/harmony/src/modules/monitoring/alert_rule.rs +++ /dev/null @@ -1,13 +0,0 @@ -use std::fmt::Debug; - -use dyn_clone::DynClone; - -use super::monitoring_alerting::MonitoringSystem; - - -pub trait AlertRule: Debug + Send + Sync + DynClone { - type M: MonitoringSystem; - - fn install(&self, sender: &Self::M); - fn clone_box(&self) -> Box>; -} diff --git a/harmony/src/modules/monitoring/alert_score.rs b/harmony/src/modules/monitoring/alert_score.rs deleted file mode 100644 index 6197128..0000000 --- a/harmony/src/modules/monitoring/alert_score.rs +++ /dev/null @@ -1,148 +0,0 @@ -use async_trait::async_trait; -use serde::{Serializer, Serialize}; - -use crate::{ - data::{Id, Version}, - interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, - inventory::Inventory, - score::Score, - topology::{HelmCommand, Topology, Url}, -}; - -#[async_trait] -pub trait Installable { - async fn ensure_installed(&self) -> Result<(), InterpretError>; -} - -pub trait AlertSender: Send + Sync + std::fmt::Debug + Installable {} - -#[async_trait] -pub trait AlertReceiver: std::fmt::Debug + Send + Sync { - async fn install(&self, sender: &S) -> Result<(), InterpretError>; -} - -#[derive(Debug)] -pub struct DiscordWebhook { - name: String, - url: Url, -} - -#[async_trait] -impl AlertReceiver for DiscordWebhook { - async fn install(&self, sender: &Prometheus) -> Result<(), InterpretError> { - sender - .install_receiver(PrometheusReceiver { - }) - .await - } -} - -#[derive(Clone, Debug, Serialize)] -pub struct HelmPrometheusAlertingScore { - pub receivers: Vec>>, -} - -impl Serialize for Box> { - fn serialize(&self, _serializer: S) -> Result - where - S: serde::Serializer, - { - todo!() - } -} -impl Clone for Box> { - fn clone(&self) -> Self { - todo!() - } -} - -impl Score for HelmPrometheusAlertingScore { - fn create_interpret(&self) -> Box> { - Box::new(AlertingInterpret { - sender: Prometheus {}, - receivers: vec![Box::new(DiscordWebhook {url:todo!(), name: todo!() })], - }) - } - - fn name(&self) -> String { - "HelmPrometheusAlertingScore".to_string() - } -} - -#[derive(Debug)] -pub struct Prometheus; - -impl Prometheus { - async fn install_receiver( - &self, - prometheus_receiver: PrometheusReceiver, - ) -> Result<(), InterpretError> { - todo!() - } -} - -pub struct PrometheusReceiver { -} - -impl PrometheusReceiver { - fn get_prometheus_receiver_config(&self) {} -} - -pub struct AlertChannelGlobalConfig {} - -#[derive(Serialize)] -pub struct AlertReceiverRoute { - pub receiver: String, - pub matchers: Vec, - #[serde(default)] - pub r#continue: bool, -} -pub struct AlertChannelReceiver { - pub name: String, -} - -impl AlertSender for Prometheus {} - -#[async_trait] -impl Installable for Prometheus { - async fn ensure_installed(&self) -> Result<(), InterpretError> { - todo!() - } -} - -#[derive(Debug)] -pub struct AlertingInterpret { - pub sender: S, - pub receivers: Vec>>, -} - -#[async_trait] -impl Interpret for AlertingInterpret { - #[must_use] - async fn execute( - &self, - inventory: &Inventory, - topology: &T, - ) -> Result { - for receiver in self.receivers.iter() { - receiver.install(&self.sender).await?; - } - todo!() - } - - fn get_name(&self) -> InterpretName { - todo!() - } - - fn get_version(&self) -> Version { - todo!() - } - - fn get_status(&self) -> InterpretStatus { - todo!() - } - - fn get_children(&self) -> Vec { - todo!() - } -} diff --git a/harmony/src/modules/monitoring/kube_prometheus/config.rs b/harmony/src/modules/monitoring/kube_prometheus/helm/config.rs similarity index 90% rename from harmony/src/modules/monitoring/kube_prometheus/config.rs rename to harmony/src/modules/monitoring/kube_prometheus/helm/config.rs index 74fdf6f..0e62c0f 100644 --- a/harmony/src/modules/monitoring/kube_prometheus/config.rs +++ b/harmony/src/modules/monitoring/kube_prometheus/helm/config.rs @@ -1,7 +1,5 @@ use serde::Serialize; -use super::types::AlertManagerChannelConfig; - #[derive(Debug, Clone, Serialize)] pub struct KubePrometheusConfig { pub namespace: String, @@ -21,7 +19,6 @@ pub struct KubePrometheusConfig { pub kube_proxy: bool, pub kube_state_metrics: bool, pub prometheus_operator: bool, - pub alert_channels: Vec, } impl KubePrometheusConfig { pub fn new() -> Self { @@ -43,7 +40,6 @@ impl KubePrometheusConfig { prometheus_operator: true, core_dns: false, kube_scheduler: false, - alert_channels: Vec::new(), } } } diff --git a/harmony/src/modules/monitoring/kube_prometheus/kube_prometheus_helm_chart_score.rs b/harmony/src/modules/monitoring/kube_prometheus/helm/kube_prometheus_helm_chart.rs similarity index 100% rename from harmony/src/modules/monitoring/kube_prometheus/kube_prometheus_helm_chart_score.rs rename to harmony/src/modules/monitoring/kube_prometheus/helm/kube_prometheus_helm_chart.rs diff --git a/harmony/src/modules/monitoring/kube_prometheus/helm/mod.rs b/harmony/src/modules/monitoring/kube_prometheus/helm/mod.rs new file mode 100644 index 0000000..4b07750 --- /dev/null +++ b/harmony/src/modules/monitoring/kube_prometheus/helm/mod.rs @@ -0,0 +1,2 @@ +pub mod config; +pub mod kube_prometheus_helm_chart; 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 new file mode 100644 index 0000000..c090f13 --- /dev/null +++ b/harmony/src/modules/monitoring/kube_prometheus/helm_prometheus_alert_score.rs @@ -0,0 +1,47 @@ +use serde::Serialize; + +use crate::{ + modules::monitoring::alert_channel::discord_alert_channel::DiscordWebhook, + score::Score, + topology::{ + HelmCommand, Topology, + oberservability::monitoring::{AlertReceiver, AlertingInterpret}, + }, +}; + +use super::prometheus::Prometheus; + +#[derive(Clone, Debug, Serialize)] +pub struct HelmPrometheusAlertingScore { + pub receivers: Vec>>, +} + +impl Score for HelmPrometheusAlertingScore { + fn create_interpret(&self) -> Box> { + Box::new(AlertingInterpret { + sender: Prometheus {}, + receivers: vec![Box::new(DiscordWebhook { + url: todo!(), + name: todo!(), + })], + }) + } + + fn name(&self) -> String { + "HelmPrometheusAlertingScore".to_string() + } +} + +impl Serialize for Box> { + fn serialize(&self, _serializer: S) -> Result + where + S: serde::Serializer, + { + todo!() + } +} +impl Clone for Box> { + fn clone(&self) -> Self { + todo!() + } +} diff --git a/harmony/src/modules/monitoring/kube_prometheus/mod.rs b/harmony/src/modules/monitoring/kube_prometheus/mod.rs index 8ad49f0..7c8233a 100644 --- a/harmony/src/modules/monitoring/kube_prometheus/mod.rs +++ b/harmony/src/modules/monitoring/kube_prometheus/mod.rs @@ -1,3 +1,4 @@ -pub mod config; -pub mod kube_prometheus_helm_chart_score; +pub mod helm; +pub mod helm_prometheus_alert_score; +pub mod prometheus; pub mod types; diff --git a/harmony/src/modules/monitoring/kube_prometheus/prometheus.rs b/harmony/src/modules/monitoring/kube_prometheus/prometheus.rs new file mode 100644 index 0000000..c5be07e --- /dev/null +++ b/harmony/src/modules/monitoring/kube_prometheus/prometheus.rs @@ -0,0 +1,34 @@ +use async_trait::async_trait; + +use crate::{ + interpret::InterpretError, + topology::{installable::Installable, oberservability::monitoring::AlertSender}, +}; + +impl AlertSender for Prometheus {} + +#[async_trait] +impl Installable for Prometheus { + async fn ensure_installed(&self) -> Result<(), InterpretError> { + todo!() + } +} +#[derive(Debug)] +pub struct Prometheus; + +impl Prometheus { + pub async fn install_receiver( + &self, + prometheus_receiver: PrometheusReceiver, + ) -> Result<(), InterpretError> { + todo!() + } +} + +pub struct PrometheusReceiver {} + +impl PrometheusReceiver { + fn get_prometheus_receiver_config(&self) {} +} + +pub struct AlertChannelGlobalConfig {} diff --git a/harmony/src/modules/monitoring/kube_prometheus/types.rs b/harmony/src/modules/monitoring/kube_prometheus/types.rs index fa66f99..224b125 100644 --- a/harmony/src/modules/monitoring/kube_prometheus/types.rs +++ b/harmony/src/modules/monitoring/kube_prometheus/types.rs @@ -1,14 +1,12 @@ use serde::Serialize; -#[derive(Debug, Clone, Serialize)] -pub struct AlertManagerChannelConfig { - pub global_configs: AlertManagerChannelGlobalConfigs, - pub route: AlertManagerChannelRoute, - pub receiver: AlertManagerChannelReceiver, +#[derive(Serialize)] +pub struct AlertReceiverRoute { + pub receiver: String, + pub matchers: Vec, + #[serde(default)] + pub r#continue: bool, +} +pub struct AlertChannelReceiver { + pub name: String, } -#[derive(Debug, Clone, Serialize)] -pub struct AlertManagerChannelGlobalConfigs {} -#[derive(Debug, Clone, Serialize)] -pub struct AlertManagerChannelReceiver {} -#[derive(Debug, Clone, Serialize)] -pub struct AlertManagerChannelRoute {} diff --git a/harmony/src/modules/monitoring/mod.rs b/harmony/src/modules/monitoring/mod.rs index 5f5fc19..7cdb3a9 100644 --- a/harmony/src/modules/monitoring/mod.rs +++ b/harmony/src/modules/monitoring/mod.rs @@ -1,8 +1,2 @@ pub mod alert_channel; -pub mod alert_receiver; -pub mod alert_rule; pub mod kube_prometheus; -pub mod monitoring_alerting; -pub mod prometheus; -pub mod scrape_target; -pub mod alert_score; diff --git a/harmony/src/modules/monitoring/monitoring_alerting.rs b/harmony/src/modules/monitoring/monitoring_alerting.rs deleted file mode 100644 index a847a04..0000000 --- a/harmony/src/modules/monitoring/monitoring_alerting.rs +++ /dev/null @@ -1,115 +0,0 @@ -use std::sync::Arc; - -use async_trait::async_trait; -use log::debug; -use serde::Serialize; - -use crate::{ - data::{Id, Version}, - interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, - inventory::Inventory, - score::Score, - topology::Topology, -}; - -use super::{alert_receiver::AlertReceiver, prometheus::Installable}; -use super::alert_rule::AlertRule; -use super::scrape_target::ScrapeTarget; - -#[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>>, -} - -impl Clone for Box> { - fn clone(&self) -> Self { - self.clone_box() - } -} -impl Clone for Box> { - fn clone(&self) -> Self { - self.clone_box() - } -} -impl Clone for Box> { - fn clone(&self) -> Self { - self.clone_box() - } -} - -impl Serialize for MonitoringAlertingScore { - fn serialize(&self, _serializer: S) -> Result - where - S: serde::Serializer, - { - todo!() - } -} - -impl Score - for MonitoringAlertingScore -{ - fn create_interpret(&self) -> Box> { - Box::new(MonitoringAlertingInterpret { - score: Arc::new(self.clone()), - }) - } - - fn name(&self) -> String { - "MonitoringAlertingScore".to_string() - } -} - -#[derive(Debug)] -struct MonitoringAlertingInterpret { - score: Arc>, -} - - - -#[async_trait] -impl Interpret - for MonitoringAlertingInterpret -{ - async fn execute( - &self, - _inventory: &Inventory, - _topology: &T, - ) -> Result { - debug!("score {:#?}", self.score); - todo!("Figure out a clean way to have things come together here : - We want Prometheus to be bound like this : - - DiscordWebhook (AlertReceiver) - | - Prometheus (AlertSender + Scraper + Installable) - ^ - MonitoringScore {{ alert_rules, alert_receivers, scrape_endpoints }} - (Interpret InterpretName { - todo!() - } - - fn get_version(&self) -> Version { - todo!() - } - - fn get_status(&self) -> InterpretStatus { - todo!() - } - - fn get_children(&self) -> Vec { - todo!() - } -} - diff --git a/harmony/src/modules/monitoring/prometheus.rs b/harmony/src/modules/monitoring/prometheus.rs deleted file mode 100644 index 4849a98..0000000 --- a/harmony/src/modules/monitoring/prometheus.rs +++ /dev/null @@ -1,112 +0,0 @@ -use async_trait::async_trait; -use serde::Serialize; -use serde_value::Value; - -use crate::{ - data::{Id, Version}, - interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, - inventory::Inventory, - topology::{K8sAnywhereTopology, Topology}, -}; -use std::fmt::Debug; - -use super::monitoring_alerting::MonitoringSystem; - -#[derive(Debug, Clone, Serialize)] -pub struct Prometheus {} - -impl Prometheus { - 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>) { - todo!() - } - pub fn configure_scrape_target(&self, _target: Box<&dyn PrometheusScrapeTarget>) { - todo!() - } -} - -impl MonitoringSystem for Prometheus {} - -pub trait PrometheusCapability { - fn install_alert_receivers(&self, receivers: Vec>); - fn install_alert_rules(&self, rules: Vec>); - fn install_scrape_targets(&self, receivers: Vec>); -} - -pub trait PrometheusReceiver { - fn get_prometheus_config(&self) -> PrometheusReceiverConfig; -} - -pub struct PrometheusReceiverConfig { - config: Value, // either a serde Value or a more specific type that understands prometheus - // config -} - -pub trait PrometheusRule { - fn get_prometheus_config(&self) -> PrometheusRuleConfig; -} - -pub struct PrometheusRuleConfig { - pub definition: String, // Not a string but an actual prometheus rule config -} - -pub trait PrometheusScrapeTarget { - fn get_prometheus_config(&self) -> PrometheusScrapeTargetConfig; -} - -pub struct PrometheusScrapeTargetConfig { - pub definition: String, // Not a string but an actual prometheus scraping config -} - -pub struct PrometheusMonitoringScore { - alert_receivers: Vec>, - alert_rules: Vec>, - scrape_targets: Vec>, -} - -#[derive(Debug)] -pub struct PrometheusMonitoringInterpret {} - -#[async_trait] -impl Interpret for PrometheusMonitoringInterpret { - async fn execute( - &self, - _inventory: &Inventory, - _topology: &T, - ) -> Result { - todo!() - } - - fn get_name(&self) -> InterpretName { - todo!() - } - - fn get_version(&self) -> Version { - todo!() - } - - fn get_status(&self) -> InterpretStatus { - todo!() - } - - fn get_children(&self) -> Vec { - 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 deleted file mode 100644 index 86e3b2d..0000000 --- a/harmony/src/modules/monitoring/scrape_target.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::fmt::Debug; - -use dyn_clone::DynClone; - -use super::monitoring_alerting::MonitoringSystem; - - -pub trait ScrapeTarget: Debug + Send + Sync + DynClone { - type M: MonitoringSystem; - - fn install(&self, sender: &Self::M); - fn clone_box(&self) -> Box>; -} -