wip: modified initial monitoring architecture based on pr review
Some checks failed
Run Check Script / check (push) Failing after 46s
Run Check Script / check (pull_request) Failing after 43s

This commit is contained in:
Willem 2025-06-02 11:42:37 -04:00
parent 7e3f1b1830
commit 691540fe64
6 changed files with 70 additions and 86 deletions

View File

@ -1,4 +1,4 @@
use std::{io::Error, process::Command, sync::Arc}; use std::{process::Command, sync::Arc};
use async_trait::async_trait; use async_trait::async_trait;
use inquire::Confirm; use inquire::Confirm;
@ -17,7 +17,6 @@ use crate::{
use super::{ use super::{
HelmCommand, K8sclient, Topology, HelmCommand, K8sclient, Topology,
k8s::K8sClient, k8s::K8sClient,
oberservability::notification_adapter_deployer::NotificationAdapterDeployer,
tenant::{ tenant::{
ResourceLimits, TenantConfig, TenantManager, TenantNetworkPolicy, k8s::K8sTenantManager, ResourceLimits, TenantConfig, TenantManager, TenantNetworkPolicy, k8s::K8sTenantManager,
}, },
@ -264,19 +263,3 @@ impl TenantManager for K8sAnywhereTopology {
.await .await
} }
} }
#[async_trait]
impl NotificationAdapterDeployer for K8sAnywhereTopology {
fn deploy_notification_adapter(
&self,
_notification_adapter_id: &str,
) -> Result<Outcome, InterpretError> {
todo!()
}
fn remove_notification_adapter(
&self,
_notification_adapter_id: &str,
) -> Result<Outcome, InterpretError> {
todo!()
}
}

View File

@ -1,13 +1 @@
use monitoring::AlertChannelConfig;
pub mod monitoring; pub mod monitoring;
pub mod notification_adapter_deployer;
pub enum MonitoringBackendType {
KubePrometheus,
}
pub struct MonitorConfig {
pub backend: MonitoringBackendType,
pub alert_channels: Vec<Box<dyn AlertChannelConfig>>,
}

View File

@ -1,62 +1,33 @@
use async_trait::async_trait; use async_trait::async_trait;
use dyn_clone::DynClone; use dyn_clone::DynClone;
use serde_json::Value;
use std::fmt::Debug; use std::fmt::Debug;
use url::Url;
use crate::interpret::InterpretError; use crate::interpret::InterpretError;
use crate::{interpret::Outcome, topology::Topology}; use crate::{interpret::Outcome, topology::Topology};
use super::notification_adapter_deployer::NotificationAdapterDeployer;
use super::{MonitorConfig, MonitoringBackendType};
#[async_trait] #[async_trait]
pub trait Monitor<T: Topology + NotificationAdapterDeployer> { pub trait Monitor<T: Topology>: Debug + Send + Sync {
async fn provision_monitor( async fn deploy_monitor(
&self, &self,
topology: &T, topology: &T,
monitor_config: &MonitorConfig, config: Vec<Box<dyn AlertChannelConfig<T>>>,
) -> Result<Outcome, InterpretError>; ) -> Result<Outcome, InterpretError>;
async fn delete_monitor( async fn delete_monitor(
&self, &self,
topolgy: &T, topolgy: &T,
monitor_config: &MonitorConfig, config: Vec<Box<dyn AlertChannelConfig<T>>>,
) -> Result<Outcome, InterpretError>; ) -> Result<Outcome, InterpretError>;
async fn configure_alerting(
&self,
topology: &T,
monitor_config: &MonitorConfig,
) -> Result<Outcome, InterpretError>;
async fn ensure_alert_channel_dependencies(
&self,
topology: &T,
monitor_config: &MonitorConfig,
) -> Result<Outcome, InterpretError> {
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(&notification_adapter_id.as_ref())?;
}
}
Ok(Outcome::success(format!(
"deployed alert channels {:?}",
&monitor_config.alert_channels
)))
}
} }
pub trait AlertChannelConfig: Debug + DynClone + Send + Sync { #[async_trait]
fn build_backend_integration_config( pub trait AlertChannelConfig<T>: Debug + DynClone + Send + Sync {
&self, fn channel_identifier(&self) -> String;
backend: &MonitoringBackendType,
) -> Result<Value, InterpretError>; fn webhook_url(&self) -> Option<Url>;
fn requires_external_alert_channel_adapter(
&self, fn send_resolved_notifications(&self) -> bool;
backend: &MonitoringBackendType,
) -> Option<String>;
} }

View File

@ -1,12 +0,0 @@
use crate::interpret::{InterpretError, Outcome};
pub trait NotificationAdapterDeployer {
fn deploy_notification_adapter(
&self,
notification_adapter_id: &str,
) -> Result<Outcome, InterpretError>;
fn remove_notification_adapter(
&self,
notication_adapter_id: &str,
) -> Result<Outcome, InterpretError>;
}

View File

@ -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<Outcome, InterpretError>;
fn delete_discord_webhook_sender(
&self,
_notification_adapter_id: &str,
) -> Result<Outcome, InterpretError>;
}
#[async_trait]
impl<T: Topology + DiscordWebhookSender> AlertChannelConfig<T> for DiscordWebhookConfig {
fn channel_identifier(&self) -> String {
self.name.clone()
}
fn webhook_url(&self) -> Option<Url> {
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<Outcome, InterpretError> {
todo!()
}
fn delete_discord_webhook_sender(
&self,
_notification_adapter_id: &str,
) -> Result<Outcome, InterpretError> {
todo!()
}
}

View File

@ -1,4 +1,2 @@
mod config; mod config;
mod discord_alert_manager; pub mod discord_webhook_sender;
mod kube_prometheus;
pub mod monitoring_alerting;