feat/monitoring_alerting #61

Merged
johnride merged 12 commits from feat/monitoring_alerting into master 2025-06-19 14:37:20 +00:00
2 changed files with 76 additions and 14 deletions
Showing only changes of commit 3ad8cd60f8 - Show all commits

View File

@ -1,11 +1,11 @@
use harmony::{
inventory::Inventory, maestro::Maestro,
modules::monitoring::alert_score::PrometheusAlertingScore, topology::K8sAnywhereTopology,
modules::monitoring::alert_score::HelmPrometheusAlertingScore, topology::K8sAnywhereTopology,
};
#[tokio::main]
async fn main() {
let alerting_score = PrometheusAlertingScore { receivers: vec![] };
let alerting_score = HelmPrometheusAlertingScore { receivers: vec![] };
let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
Inventory::autoload(),
K8sAnywhereTopology::from_env(),

View File

@ -1,8 +1,12 @@
use async_trait::async_trait;
use serde::Serialize;
use serde::{Serializer, Serialize};
use crate::{
data::{Id, Version}, interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, inventory::Inventory, score::Score, topology::{HelmCommand, Topology}
data::{Id, Version},
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
inventory::Inventory,
score::Score,
topology::{HelmCommand, Topology, Url},
};
#[async_trait]
@ -12,12 +16,29 @@ pub trait Installable {
pub trait AlertSender: Send + Sync + std::fmt::Debug + Installable {}
#[async_trait]
pub trait AlertReceiver<S: AlertSender>: std::fmt::Debug + Send + Sync {
fn install(&self, sender: &S) -> Result<(), InterpretError>;
async fn install(&self, sender: &S) -> Result<(), InterpretError>;
}
#[derive(Debug)]
pub struct DiscordWebhook {
name: String,
url: Url,
}
#[async_trait]
impl AlertReceiver<Prometheus> for DiscordWebhook {
async fn install(&self, sender: &Prometheus) -> Result<(), InterpretError> {
sender
.install_receiver(PrometheusReceiver {
})
.await
}
}
#[derive(Clone, Debug, Serialize)]
pub struct PrometheusAlertingScore {
pub struct HelmPrometheusAlertingScore {
pub receivers: Vec<Box<dyn AlertReceiver<Prometheus>>>,
}
@ -35,18 +56,60 @@ impl Clone for Box<dyn AlertReceiver<Prometheus>> {
}
}
impl<T: Topology + HelmCommand> Score<T> for PrometheusAlertingScore {
impl<T: Topology + HelmCommand> Score<T> for HelmPrometheusAlertingScore {
fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
Box::new(AlertingInterpret { sender: Prometheus {}, receivers: todo!() })
Box::new(AlertingInterpret {
sender: Prometheus {},
receivers: vec![Box::new(DiscordWebhook {url:todo!(), name: todo!() })],
})
}
fn name(&self) -> String {
"PrometheusAlertingScore".to_string()
"HelmPrometheusAlertingScore".to_string()
}
}
#[derive(Debug)]
pub struct Prometheus;
impl Prometheus {
async fn install_receiver(
&self,
prometheus_receiver: PrometheusReceiver,
) -> Result<(), InterpretError> {
todo!()
}
}
pub struct PrometheusReceiver {
}
impl PrometheusReceiver {
fn get_prometheus_receiver_config(&self) {}
}
pub struct AlertChannelGlobalConfig {}
#[derive(Serialize)]
pub struct AlertReceiverRoute {
pub receiver: String,
pub matchers: Vec<String>,
#[serde(default)]
pub r#continue: bool,
}
pub struct AlertChannelReceiver {
pub name: String,
}
impl AlertSender for Prometheus {}
#[async_trait]
impl Installable for Prometheus {
async fn ensure_installed(&self) -> Result<(), InterpretError> {
todo!()
}
}
#[derive(Debug)]
pub struct AlertingInterpret<S: AlertSender> {
pub sender: S,
@ -61,11 +124,10 @@ impl<S: AlertSender, T: Topology> Interpret<T> for AlertingInterpret<S> {
inventory: &Inventory,
topology: &T,
) -> Result<Outcome, InterpretError> {
self.receivers.iter().try_for_each(|r| {
r.install(&self.sender)
})?;
todo!();
for receiver in self.receivers.iter() {
receiver.install(&self.sender).await?;
}
todo!()
}
fn get_name(&self) -> InterpretName {