feat: added impl for kube prometheus monitor
All checks were successful
Run Check Script / check (push) Successful in 1m46s
All checks were successful
Run Check Script / check (push) Successful in 1m46s
This commit is contained in:
parent
57eabc9834
commit
de3e7869f7
@ -1,4 +1,5 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use dyn_clone::DynClone;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
@ -13,19 +14,18 @@ use crate::{interpret::Outcome, topology::Topology};
|
|||||||
/// monitoring data, enabling consistent processing regardless of the underlying data source.
|
/// monitoring data, enabling consistent processing regardless of the underlying data source.
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Monitor<T: Topology>: Debug + Send + Sync {
|
pub trait Monitor<T: Topology>: Debug + Send + Sync {
|
||||||
async fn deploy_monitor(
|
async fn deploy_monitor(&self, topology: &T) -> Result<Outcome, InterpretError>;
|
||||||
&self,
|
|
||||||
topology: &T,
|
|
||||||
alert_receivers: Vec<AlertReceiver>,
|
|
||||||
) -> Result<Outcome, InterpretError>;
|
|
||||||
|
|
||||||
async fn delete_monitor(
|
async fn delete_monitor(&self, topolgy: &T) -> Result<Outcome, InterpretError>;
|
||||||
&self,
|
|
||||||
topolgy: &T,
|
|
||||||
alert_receivers: Vec<AlertReceiver>,
|
|
||||||
) -> Result<Outcome, InterpretError>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait AlertReceiverDeployment<T: Topology>: Debug + DynClone + Send + Sync {
|
||||||
|
async fn deploy_alert_receiver(&self, topology: &T) -> Result<Outcome, InterpretError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
dyn_clone::clone_trait_object!(<T> AlertReceiverDeployment<T>);
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct AlertReceiver {
|
pub struct AlertReceiver {
|
||||||
pub receiver_id: String,
|
pub receiver_id: String,
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
use super::discord_alert_manager::discord_alert_manager_score;
|
use super::{
|
||||||
|
discord_alert_manager::discord_alert_manager_score, kube_prometheus_monitor::AlertManagerConfig,
|
||||||
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_yaml::Value;
|
use serde_yaml::Value;
|
||||||
@ -11,10 +13,18 @@ use crate::{
|
|||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
score::Score,
|
score::Score,
|
||||||
topology::{
|
topology::{
|
||||||
HelmCommand, K8sAnywhereTopology, Topology, oberservability::monitoring::AlertReceiver,
|
HelmCommand, K8sAnywhereTopology, Topology,
|
||||||
|
oberservability::monitoring::{AlertReceiver, AlertReceiverDeployment},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl<T: Topology + DiscordWebhookReceiver> AlertReceiverDeployment<T> for DiscordWebhookConfig {
|
||||||
|
async fn deploy_alert_receiver(&self, topology: &T) -> Result<Outcome, InterpretError> {
|
||||||
|
topology.deploy_discord_webhook_receiver(self.clone()).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct DiscordWebhookConfig {
|
pub struct DiscordWebhookConfig {
|
||||||
pub webhook_url: Url,
|
pub webhook_url: Url,
|
||||||
@ -34,13 +44,9 @@ pub trait DiscordWebhookReceiver {
|
|||||||
) -> Result<Outcome, InterpretError>;
|
) -> Result<Outcome, InterpretError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait AlertManagerConfig<T> {
|
|
||||||
fn get_alert_manager_config(&self) -> Result<Value, InterpretError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<T: DiscordWebhookReceiver> AlertManagerConfig<T> for DiscordWebhookConfig {
|
impl<T: DiscordWebhookReceiver> AlertManagerConfig<T> for DiscordWebhookConfig {
|
||||||
fn get_alert_manager_config(&self) -> Result<Value, InterpretError> {
|
async fn get_alert_manager_config(&self) -> Result<Value, InterpretError> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
108
harmony/src/modules/monitoring/kube_prometheus_monitor.rs
Normal file
108
harmony/src/modules/monitoring/kube_prometheus_monitor.rs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
use serde::Serialize;
|
||||||
|
use serde_yaml::Value;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
data::{Id, Version},
|
||||||
|
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||||
|
inventory::Inventory,
|
||||||
|
score::Score,
|
||||||
|
topology::{
|
||||||
|
HelmCommand, Topology,
|
||||||
|
oberservability::monitoring::{AlertReceiverDeployment, Monitor},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
config::KubePrometheusConfig, kube_prometheus_helm_chart::kube_prometheus_helm_chart_score,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct KubePrometheus<T> {
|
||||||
|
alert_receivers: Vec<Box<dyn AlertReceiverDeployment<T>>>,
|
||||||
|
config: KubePrometheusConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait AlertManagerConfig<T> {
|
||||||
|
async fn get_alert_manager_config(&self) -> Result<Value, InterpretError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Topology> KubePrometheus<T> {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
alert_receivers: Vec::new(),
|
||||||
|
config: KubePrometheusConfig::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl<T: Topology + HelmCommand + std::fmt::Debug> Monitor<T> for KubePrometheus<T> {
|
||||||
|
async fn deploy_monitor(&self, topology: &T) -> Result<Outcome, InterpretError> {
|
||||||
|
for alert_receiver in &self.alert_receivers {
|
||||||
|
alert_receiver.deploy_alert_receiver(topology).await?;
|
||||||
|
}
|
||||||
|
let score = KubePrometheusScore {
|
||||||
|
config: self.config.clone(),
|
||||||
|
};
|
||||||
|
let inventory = Inventory::autoload();
|
||||||
|
score.create_interpret().execute(&inventory, topology).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete_monitor(&self, _topolgy: &T) -> Result<Outcome, InterpretError> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
struct KubePrometheusScore {
|
||||||
|
config: KubePrometheusConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Topology + HelmCommand> Score<T> for KubePrometheusScore {
|
||||||
|
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
||||||
|
Box::new(KubePromethusScoreInterpret {
|
||||||
|
score: self.clone(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name(&self) -> String {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
struct KubePromethusScoreInterpret {
|
||||||
|
score: KubePrometheusScore,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl<T: Topology + HelmCommand> Interpret<T> for KubePromethusScoreInterpret {
|
||||||
|
async fn execute(
|
||||||
|
&self,
|
||||||
|
inventory: &Inventory,
|
||||||
|
topology: &T,
|
||||||
|
) -> Result<Outcome, InterpretError> {
|
||||||
|
kube_prometheus_helm_chart_score(&self.score.config)
|
||||||
|
.create_interpret()
|
||||||
|
.execute(inventory, topology)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_name(&self) -> InterpretName {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_version(&self) -> Version {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_status(&self) -> InterpretStatus {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_children(&self) -> Vec<Id> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
@ -2,5 +2,6 @@ pub mod alertmanager_types;
|
|||||||
mod config;
|
mod config;
|
||||||
mod discord_alert_manager;
|
mod discord_alert_manager;
|
||||||
pub mod discord_webhook_sender;
|
pub mod discord_webhook_sender;
|
||||||
mod kube_prometheus;
|
mod kube_prometheus_helm_chart;
|
||||||
|
pub mod kube_prometheus_monitor;
|
||||||
pub mod monitoring_alerting;
|
pub mod monitoring_alerting;
|
||||||
|
@ -14,8 +14,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
config::KubePrometheusConfig, discord_alert_manager::discord_alert_manager_score,
|
config::KubePrometheusConfig, kube_prometheus_helm_chart::kube_prometheus_helm_chart_score,
|
||||||
kube_prometheus::kube_prometheus_helm_chart_score,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
Loading…
Reference in New Issue
Block a user