wip: modified initial monitoring architecture based on pr review
This commit is contained in:
parent
7e3f1b1830
commit
691540fe64
@ -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<Outcome, InterpretError> {
|
||||
todo!()
|
||||
}
|
||||
fn remove_notification_adapter(
|
||||
&self,
|
||||
_notification_adapter_id: &str,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
@ -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<Box<dyn AlertChannelConfig>>,
|
||||
}
|
||||
|
@ -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<T: Topology + NotificationAdapterDeployer> {
|
||||
async fn provision_monitor(
|
||||
pub trait Monitor<T: Topology>: Debug + Send + Sync {
|
||||
async fn deploy_monitor(
|
||||
&self,
|
||||
topology: &T,
|
||||
monitor_config: &MonitorConfig,
|
||||
config: Vec<Box<dyn AlertChannelConfig<T>>>,
|
||||
) -> Result<Outcome, InterpretError>;
|
||||
|
||||
async fn delete_monitor(
|
||||
&self,
|
||||
topolgy: &T,
|
||||
monitor_config: &MonitorConfig,
|
||||
config: Vec<Box<dyn AlertChannelConfig<T>>>,
|
||||
) -> 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(¬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<Value, InterpretError>;
|
||||
fn requires_external_alert_channel_adapter(
|
||||
&self,
|
||||
backend: &MonitoringBackendType,
|
||||
) -> Option<String>;
|
||||
#[async_trait]
|
||||
pub trait AlertChannelConfig<T>: Debug + DynClone + Send + Sync {
|
||||
fn channel_identifier(&self) -> String;
|
||||
|
||||
fn webhook_url(&self) -> Option<Url>;
|
||||
|
||||
fn send_resolved_notifications(&self) -> bool;
|
||||
}
|
||||
|
@ -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>;
|
||||
}
|
56
harmony/src/modules/monitoring/discord_webhook_sender.rs
Normal file
56
harmony/src/modules/monitoring/discord_webhook_sender.rs
Normal 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!()
|
||||
}
|
||||
}
|
@ -1,4 +1,2 @@
|
||||
mod config;
|
||||
mod discord_alert_manager;
|
||||
mod kube_prometheus;
|
||||
pub mod monitoring_alerting;
|
||||
pub mod discord_webhook_sender;
|
||||
|
Loading…
Reference in New Issue
Block a user