From c16276b62b6fd0d5a7099fe34b32c361156a31d6 Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Fri, 13 Jun 2025 12:36:02 -0400 Subject: [PATCH] wip Alerting abstractions architecture --- harmony/src/modules/monitoring/mod.rs | 1 + .../src/modules/monitoring/monitoring_2.rs | 59 +++++++++++++++ .../modules/monitoring/monitoring_alerting.rs | 73 +++++++++++++++++-- 3 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 harmony/src/modules/monitoring/monitoring_2.rs diff --git a/harmony/src/modules/monitoring/mod.rs b/harmony/src/modules/monitoring/mod.rs index a84bd9f..8baa019 100644 --- a/harmony/src/modules/monitoring/mod.rs +++ b/harmony/src/modules/monitoring/mod.rs @@ -1,3 +1,4 @@ pub mod alert_channel; pub mod kube_prometheus; pub mod monitoring_alerting; +mod monitoring_2; diff --git a/harmony/src/modules/monitoring/monitoring_2.rs b/harmony/src/modules/monitoring/monitoring_2.rs new file mode 100644 index 0000000..b8e1dfc --- /dev/null +++ b/harmony/src/modules/monitoring/monitoring_2.rs @@ -0,0 +1,59 @@ +use crate::{score::Score, topology::Topology}; + +pub trait AlertSender {} + +struct Prometheus {} + +impl Prometheus { + fn configure_receiver(&self, receiver: PrometheusReceiver) -> Result<(), String> { + todo!() + } +} + +impl AlertSender for Prometheus {} + +struct DiscordWebhook; +struct PrometheusReceiver; + +impl DiscordWebhook { + fn as_prometheus_receiver(&self) -> PrometheusReceiver { + PrometheusReceiver {} + } +} + +impl AlertReceiver for DiscordWebhook { + type Sender = Prometheus; + + fn install(&self, sender: &Self::Sender) -> Result<(), String> { + sender.configure_receiver(self.as_prometheus_receiver()) + } +} + +pub trait AlertReceiver { + type Sender: AlertSender; + + fn install(&self) -> Result<(), String>; +} + +struct AlertReceiverConfig { + config: String, // Or whatever + sender: S, +} + +struct DiscordWebhookScore { + config: DiscordWebhook, +} + +impl Score for DiscordWebhookScore { + fn create_interpret(&self) -> Box { + AlertReceiverInterpret { receiver: Box::new(self.config.clone())} + } + + fn name(&self) -> String { + todo!() + } +} + +struct AlertReceiverInterpret { + receiver: Box, +} diff --git a/harmony/src/modules/monitoring/monitoring_alerting.rs b/harmony/src/modules/monitoring/monitoring_alerting.rs index df1c8a2..1d0d48e 100644 --- a/harmony/src/modules/monitoring/monitoring_alerting.rs +++ b/harmony/src/modules/monitoring/monitoring_alerting.rs @@ -1,5 +1,6 @@ use async_trait::async_trait; use serde::Serialize; +use serde_value::Value; use crate::topology::oberservability::monitoring::{AlertChannelConfig, Monitor}; use crate::{ @@ -10,13 +11,74 @@ use crate::{ topology::{HelmCommand, Topology}, }; -#[derive(Debug, Clone, Serialize)] -pub struct MonitoringAlertingScore { - #[serde(skip)] - pub alert_channel_configs: Option>>, +pub trait MonitoringSystem {} + +trait PrometheusReceiver { + fn get_config(&self) -> PrometheusReceiverConfig; } -impl Score for MonitoringAlertingScore { +struct PrometheusReceiverConfig { + config: Value, // either a serde Value or a more specific type that understands prometheus + // config +} + +struct PrometheusRule { + definition: String, // Not a string but an actual prometheus rule config +} + +struct PrometheusScrapeTarget { + definition: String, // Not a string but an actual prometheus scraping config +} + +pub struct PrometheusMonitoringScore { + alert_receivers: Vec>, + alert_rules: Vec>, + scrape_targets: Vec>, +} + +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!() + } +} + +pub trait PrometheusCapability { + fn install_alert_receivers(&self, receivers: Vec>); + fn install_alert_rules(&self, rules: Vec>); + fn install_scrape_targets(&self, receivers: Vec>); +} + +#[derive(Debug, Clone, Serialize)] +pub struct MonitoringAlertingScore { + alert_receivers: Vec>>, + alert_rules: Vec>>, + monitoring_targets: Vec>>, +} + +impl Score for MonitoringAlertingScore { fn create_interpret(&self) -> Box> { Box::new(MonitoringAlertingInterpret { score: self.clone(), @@ -65,3 +127,4 @@ impl Interpret for MonitoringAlertingInt todo!() } } +