feat/monitoring_alerting #61
@ -1,11 +1,11 @@
|
|||||||
use harmony::{
|
use harmony::{
|
||||||
inventory::Inventory, maestro::Maestro,
|
inventory::Inventory, maestro::Maestro,
|
||||||
modules::monitoring::alert_score::PrometheusAlertingScore, topology::K8sAnywhereTopology,
|
modules::monitoring::alert_score::HelmPrometheusAlertingScore, topology::K8sAnywhereTopology,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let alerting_score = PrometheusAlertingScore { receivers: vec![] };
|
let alerting_score = HelmPrometheusAlertingScore { receivers: vec![] };
|
||||||
let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
|
let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
|
||||||
Inventory::autoload(),
|
Inventory::autoload(),
|
||||||
K8sAnywhereTopology::from_env(),
|
K8sAnywhereTopology::from_env(),
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use serde::Serialize;
|
use serde::{Serializer, Serialize};
|
||||||
|
|
||||||
use crate::{
|
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]
|
#[async_trait]
|
||||||
@ -12,12 +16,29 @@ pub trait Installable {
|
|||||||
|
|
||||||
pub trait AlertSender: Send + Sync + std::fmt::Debug + Installable {}
|
pub trait AlertSender: Send + Sync + std::fmt::Debug + Installable {}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
pub trait AlertReceiver<S: AlertSender>: std::fmt::Debug + Send + Sync {
|
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)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
pub struct PrometheusAlertingScore {
|
pub struct HelmPrometheusAlertingScore {
|
||||||
pub receivers: Vec<Box<dyn AlertReceiver<Prometheus>>>,
|
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>> {
|
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 {
|
fn name(&self) -> String {
|
||||||
"PrometheusAlertingScore".to_string()
|
"HelmPrometheusAlertingScore".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Prometheus;
|
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)]
|
#[derive(Debug)]
|
||||||
pub struct AlertingInterpret<S: AlertSender> {
|
pub struct AlertingInterpret<S: AlertSender> {
|
||||||
pub sender: S,
|
pub sender: S,
|
||||||
@ -61,11 +124,10 @@ impl<S: AlertSender, T: Topology> Interpret<T> for AlertingInterpret<S> {
|
|||||||
inventory: &Inventory,
|
inventory: &Inventory,
|
||||||
topology: &T,
|
topology: &T,
|
||||||
) -> Result<Outcome, InterpretError> {
|
) -> Result<Outcome, InterpretError> {
|
||||||
|
for receiver in self.receivers.iter() {
|
||||||
self.receivers.iter().try_for_each(|r| {
|
receiver.install(&self.sender).await?;
|
||||||
r.install(&self.sender)
|
}
|
||||||
})?;
|
todo!()
|
||||||
todo!();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_name(&self) -> InterpretName {
|
fn get_name(&self) -> InterpretName {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user