feat: Initial setup for monitoring and alerting #48

Merged
wjro merged 7 commits from feat/monitor into master 2025-06-03 18:17:17 +00:00
6 changed files with 106 additions and 0 deletions
Showing only changes of commit 7e3f1b1830 - Show all commits

View File

@@ -15,9 +15,12 @@ use crate::{
};
use super::{
k8s::K8sClient, oberservability::notification_adapter_deployer::NotificationAdapterDeployer, tenant::{
k8s::K8sTenantManager, ResourceLimits, TenantConfig, TenantManager, TenantNetworkPolicy
}, HelmCommand, K8sclient, Topology
HelmCommand, K8sclient, Topology,
k8s::K8sClient,
oberservability::notification_adapter_deployer::NotificationAdapterDeployer,
tenant::{
ResourceLimits, TenantConfig, TenantManager, TenantNetworkPolicy, k8s::K8sTenantManager,
},
};
struct K8sState {

View File

@@ -3,8 +3,8 @@ mod host_binding;
mod http;
mod k8s_anywhere;
mod localhost;
pub mod tenant;
pub mod oberservability;
pub mod tenant;
pub use k8s_anywhere::*;
pub use localhost::*;
pub mod k8s;

View File

@@ -11,6 +11,3 @@ pub struct MonitorConfig {
pub backend: MonitoringBackendType,
pub alert_channels: Vec<Box<dyn AlertChannelConfig>>,
}

View File

@@ -1,15 +1,12 @@
use async_trait::async_trait;
use std::fmt::Debug;
use dyn_clone::DynClone;
use serde_json::Value;
use std::fmt::Debug;
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};
johnride marked this conversation as resolved Outdated

A bit of rustdoc would be relevant here to explain the intended use of this trait.

A bit of rustdoc would be relevant here to explain the intended use of this trait.
@@ -43,18 +40,23 @@ pub trait Monitor<T: Topology + NotificationAdapterDeployer> {
if let Some(notification_adapter_id) =
channel.requires_external_alert_channel_adapter(&monitor_config.backend)
{
topology.deploy_notification_adapter(
&notification_adapter_id.as_ref(),
)?;
topology.deploy_notification_adapter(&notification_adapter_id.as_ref())?;
}
}
Ok(Outcome::success(format!("deployed alert channels {:?}", &monitor_config.alert_channels)))
Ok(Outcome::success(format!(
"deployed alert channels {:?}",
&monitor_config.alert_channels
)))
}
}
pub trait AlertChannelConfig: Debug + DynClone + Send + Sync {

I think we can solve the dependency issue by introducing a T here :

pub trait AlertChannelConfig<T> {
 // only alertChannel related stuff, be careful about SRP here, no dependency management at this level other than the T itself
}

impl <T: DiscordWebhookSender> AlertChannelConfig<T> for DiscordWebhookConfig { // The dependency on the DiscordWebHookSender is declared here
 // implement functions
}

pub trait Monitor<T> {
 config: Vec<Box<dyn AlertChannelConfig<T>>> // The T from alertChannelConfig here will force the Monitor to provide a T that implements DiscordWebhookSender
}

impl DiscordWebhookSender for K8sAnywhereTopology { // Satisfy here the trait bound on the DiscordWehbookConfig 
 // implement functions that make sure DiscordAlertManager is installed, use the same pattern as for k8sClient that autoinstalls k3d if no k8s cluster is available
}
I think we can solve the dependency issue by introducing a T here : ```rust pub trait AlertChannelConfig<T> { // only alertChannel related stuff, be careful about SRP here, no dependency management at this level other than the T itself } impl <T: DiscordWebhookSender> AlertChannelConfig<T> for DiscordWebhookConfig { // The dependency on the DiscordWebHookSender is declared here // implement functions } pub trait Monitor<T> { config: Vec<Box<dyn AlertChannelConfig<T>>> // The T from alertChannelConfig here will force the Monitor to provide a T that implements DiscordWebhookSender } impl DiscordWebhookSender for K8sAnywhereTopology { // Satisfy here the trait bound on the DiscordWehbookConfig // implement functions that make sure DiscordAlertManager is installed, use the same pattern as for k8sClient that autoinstalls k3d if no k8s cluster is available } ```
fn build_backend_integration_config(&self, backend: &MonitoringBackendType) -> Result<Value, InterpretError>;
fn requires_external_alert_channel_adapter(&self, backend: &MonitoringBackendType) -> Option<String>;
fn build_backend_integration_config(
&self,
backend: &MonitoringBackendType,
) -> Result<Value, InterpretError>;
fn requires_external_alert_channel_adapter(
&self,
backend: &MonitoringBackendType,
) -> Option<String>;
}