diff --git a/harmony/src/domain/topology/k8s_anywhere.rs b/harmony/src/domain/topology/k8s_anywhere.rs index 4c92b0c..ef11f36 100644 --- a/harmony/src/domain/topology/k8s_anywhere.rs +++ b/harmony/src/domain/topology/k8s_anywhere.rs @@ -1,4 +1,4 @@ -use std::{io::Error, process::Command, sync::Arc}; +use std::{process::Command, sync::Arc}; use async_trait::async_trait; use inquire::Confirm; @@ -17,7 +17,6 @@ use crate::{ use super::{ HelmCommand, K8sclient, Topology, k8s::K8sClient, - oberservability::notification_adapter_deployer::NotificationAdapterDeployer, tenant::{ ResourceLimits, TenantConfig, TenantManager, TenantNetworkPolicy, k8s::K8sTenantManager, }, @@ -264,19 +263,3 @@ impl TenantManager for K8sAnywhereTopology { .await } } - -#[async_trait] -impl NotificationAdapterDeployer for K8sAnywhereTopology { - fn deploy_notification_adapter( - &self, - _notification_adapter_id: &str, - ) -> Result { - todo!() - } - fn remove_notification_adapter( - &self, - _notification_adapter_id: &str, - ) -> Result { - todo!() - } -} diff --git a/harmony/src/domain/topology/oberservability/mod.rs b/harmony/src/domain/topology/oberservability/mod.rs index aa75d09..7f2ac95 100644 --- a/harmony/src/domain/topology/oberservability/mod.rs +++ b/harmony/src/domain/topology/oberservability/mod.rs @@ -1,13 +1 @@ -use monitoring::AlertChannelConfig; - pub mod monitoring; -pub mod notification_adapter_deployer; - -pub enum MonitoringBackendType { - KubePrometheus, -} - -pub struct MonitorConfig { - pub backend: MonitoringBackendType, - pub alert_channels: Vec>, -} diff --git a/harmony/src/domain/topology/oberservability/monitoring.rs b/harmony/src/domain/topology/oberservability/monitoring.rs index 9e38358..485f633 100644 --- a/harmony/src/domain/topology/oberservability/monitoring.rs +++ b/harmony/src/domain/topology/oberservability/monitoring.rs @@ -1,62 +1,33 @@ use async_trait::async_trait; use dyn_clone::DynClone; -use serde_json::Value; use std::fmt::Debug; +use url::Url; use crate::interpret::InterpretError; use crate::{interpret::Outcome, topology::Topology}; -use super::notification_adapter_deployer::NotificationAdapterDeployer; -use super::{MonitorConfig, MonitoringBackendType}; - #[async_trait] -pub trait Monitor { - async fn provision_monitor( +pub trait Monitor: Debug + Send + Sync { + async fn deploy_monitor( &self, topology: &T, - monitor_config: &MonitorConfig, + config: Vec>>, ) -> Result; async fn delete_monitor( &self, topolgy: &T, - monitor_config: &MonitorConfig, + config: Vec>>, ) -> Result; - - async fn configure_alerting( - &self, - topology: &T, - monitor_config: &MonitorConfig, - ) -> Result; - - async fn ensure_alert_channel_dependencies( - &self, - topology: &T, - monitor_config: &MonitorConfig, - ) -> Result { - for channel in &monitor_config.alert_channels { - if let Some(notification_adapter_id) = - channel.requires_external_alert_channel_adapter(&monitor_config.backend) - { - topology.deploy_notification_adapter(¬ification_adapter_id.as_ref())?; - } - } - Ok(Outcome::success(format!( - "deployed alert channels {:?}", - &monitor_config.alert_channels - ))) - } } -pub trait AlertChannelConfig: Debug + DynClone + Send + Sync { - fn build_backend_integration_config( - &self, - backend: &MonitoringBackendType, - ) -> Result; - fn requires_external_alert_channel_adapter( - &self, - backend: &MonitoringBackendType, - ) -> Option; +#[async_trait] +pub trait AlertChannelConfig: Debug + DynClone + Send + Sync { + fn channel_identifier(&self) -> String; + + fn webhook_url(&self) -> Option; + + fn send_resolved_notifications(&self) -> bool; } diff --git a/harmony/src/domain/topology/oberservability/notification_adapter_deployer.rs b/harmony/src/domain/topology/oberservability/notification_adapter_deployer.rs deleted file mode 100644 index 02786ae..0000000 --- a/harmony/src/domain/topology/oberservability/notification_adapter_deployer.rs +++ /dev/null @@ -1,12 +0,0 @@ -use crate::interpret::{InterpretError, Outcome}; - -pub trait NotificationAdapterDeployer { - fn deploy_notification_adapter( - &self, - notification_adapter_id: &str, - ) -> Result; - fn remove_notification_adapter( - &self, - notication_adapter_id: &str, - ) -> Result; -} diff --git a/harmony/src/modules/monitoring/discord_webhook_sender.rs b/harmony/src/modules/monitoring/discord_webhook_sender.rs new file mode 100644 index 0000000..e5eea07 --- /dev/null +++ b/harmony/src/modules/monitoring/discord_webhook_sender.rs @@ -0,0 +1,56 @@ +use async_trait::async_trait; +use url::Url; + +use crate::{ + interpret::{InterpretError, Outcome}, + topology::{K8sAnywhereTopology, Topology, oberservability::monitoring::AlertChannelConfig}, +}; + +#[derive(Debug, Clone)] +pub struct DiscordWebhookConfig { + pub webhook_url: Url, + pub name: String, + pub send_resolved_notifications: bool, +} + +pub trait DiscordWebhookSender { + fn deploy_discord_webhook_sender( + &self, + _notification_adapter_id: &str, + ) -> Result; + + fn delete_discord_webhook_sender( + &self, + _notification_adapter_id: &str, + ) -> Result; +} + +#[async_trait] +impl AlertChannelConfig for DiscordWebhookConfig { + fn channel_identifier(&self) -> String { + self.name.clone() + } + fn webhook_url(&self) -> Option { + Some(self.webhook_url.clone()) + } + + fn send_resolved_notifications(&self) -> bool { + self.send_resolved_notifications.clone() + } +} + +#[async_trait] +impl DiscordWebhookSender for K8sAnywhereTopology { + fn deploy_discord_webhook_sender( + &self, + _notification_adapter_id: &str, + ) -> Result { + todo!() + } + fn delete_discord_webhook_sender( + &self, + _notification_adapter_id: &str, + ) -> Result { + todo!() + } +} diff --git a/harmony/src/modules/monitoring/mod.rs b/harmony/src/modules/monitoring/mod.rs index 914ae07..56c7f4d 100644 --- a/harmony/src/modules/monitoring/mod.rs +++ b/harmony/src/modules/monitoring/mod.rs @@ -1,4 +1,2 @@ mod config; -mod discord_alert_manager; -mod kube_prometheus; -pub mod monitoring_alerting; +pub mod discord_webhook_sender;