chore: clean up unused old code, organized traits, impls, etc into logical locations
This commit is contained in:
parent
3ad8cd60f8
commit
1771f47eca
@ -4,10 +4,7 @@ use harmony::{
|
||||
maestro::Maestro,
|
||||
modules::{
|
||||
lamp::{LAMPConfig, LAMPScore},
|
||||
monitoring::{
|
||||
alert_channel::discord_alert_channel::DiscordWebhook,
|
||||
monitoring_alerting::MonitoringAlertingScore,
|
||||
},
|
||||
monitoring::alert_channel::discord_alert_channel::DiscordWebhook,
|
||||
},
|
||||
topology::{K8sAnywhereTopology, Url},
|
||||
};
|
||||
@ -35,15 +32,15 @@ async fn main() {
|
||||
},
|
||||
};
|
||||
|
||||
let monitoring = MonitoringAlertingScore {
|
||||
alert_receivers: vec![Box::new(DiscordWebhook {
|
||||
url: Url::Url(url::Url::parse("https://discord.idonotexist.com").unwrap()),
|
||||
// TODO write url macro
|
||||
// url: url!("https://discord.idonotexist.com"),
|
||||
})],
|
||||
alert_rules: vec![],
|
||||
scrape_targets: vec![],
|
||||
};
|
||||
//let monitoring = MonitoringAlertingScore {
|
||||
// alert_receivers: vec![Box::new(DiscordWebhook {
|
||||
// url: Url::Url(url::Url::parse("https://discord.idonotexist.com").unwrap()),
|
||||
// // TODO write url macro
|
||||
// // url: url!("https://discord.idonotexist.com"),
|
||||
// })],
|
||||
// alert_rules: vec![],
|
||||
// scrape_targets: vec![],
|
||||
//};
|
||||
|
||||
// You can choose the type of Topology you want, we suggest starting with the
|
||||
// K8sAnywhereTopology as it is the most automatic one that enables you to easily deploy
|
||||
@ -57,7 +54,6 @@ async fn main() {
|
||||
.unwrap();
|
||||
|
||||
// maestro.register_all(vec![Box::new(lamp_stack)]);
|
||||
maestro.register_all(vec![Box::new(monitoring)]);
|
||||
// Here we bootstrap the CLI, this gives some nice features if you need them
|
||||
harmony_cli::init(maestro, None).await.unwrap();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
use harmony::{
|
||||
inventory::Inventory, maestro::Maestro,
|
||||
modules::monitoring::alert_score::HelmPrometheusAlertingScore, topology::K8sAnywhereTopology,
|
||||
modules::monitoring::kube_prometheus::helm_prometheus_alert_score::HelmPrometheusAlertingScore,
|
||||
topology::K8sAnywhereTopology,
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
|
8
harmony/src/domain/topology/installable.rs
Normal file
8
harmony/src/domain/topology/installable.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::interpret::InterpretError;
|
||||
|
||||
#[async_trait]
|
||||
pub trait Installable {
|
||||
async fn ensure_installed(&self) -> Result<(), InterpretError>;
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
mod ha_cluster;
|
||||
mod host_binding;
|
||||
mod http;
|
||||
pub mod installable;
|
||||
mod k8s_anywhere;
|
||||
mod localhost;
|
||||
pub mod oberservability;
|
||||
|
@ -1,71 +0,0 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::score::Score;
|
||||
|
||||
use crate::topology::HelmCommand;
|
||||
use crate::{
|
||||
interpret::{InterpretError, Outcome},
|
||||
inventory::Inventory,
|
||||
topology::Topology,
|
||||
};
|
||||
|
||||
use super::{
|
||||
K8sMonitorConfig,
|
||||
monitoring::{AlertChannel, AlertChannelConfig, Monitor},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct K8sMonitor {
|
||||
pub config: K8sMonitorConfig,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Monitor for K8sMonitor {
|
||||
async fn provision_monitor<T: Topology + HelmCommand>(
|
||||
&self,
|
||||
inventory: &Inventory,
|
||||
topology: &T,
|
||||
alert_channels: Option<Vec<Box<dyn AlertChannelConfig>>>,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
if let Some(channels) = alert_channels {
|
||||
let alert_channels = self.build_alert_channels(channels).await?;
|
||||
for channel in alert_channels {
|
||||
channel.register_alert_channel().await?;
|
||||
}
|
||||
}
|
||||
let chart = self.config.chart.clone();
|
||||
chart
|
||||
.create_interpret()
|
||||
.execute(inventory, topology)
|
||||
.await?;
|
||||
Ok(Outcome::success("installed monitor".to_string()))
|
||||
}
|
||||
|
||||
fn delete_monitor(&self) -> Result<Outcome, InterpretError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl AlertChannelConfig for K8sMonitor {
|
||||
async fn build_alert_channel(&self) -> Result<Box<dyn AlertChannel>, InterpretError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl K8sMonitor {
|
||||
pub async fn build_alert_channels(
|
||||
&self,
|
||||
alert_channel_configs: Vec<Box<dyn AlertChannelConfig>>,
|
||||
) -> Result<Vec<Box<dyn AlertChannel>>, InterpretError> {
|
||||
let mut alert_channels = Vec::new();
|
||||
for config in alert_channel_configs {
|
||||
let channel = config.build_alert_channel().await?;
|
||||
alert_channels.push(channel)
|
||||
}
|
||||
Ok(alert_channels)
|
||||
}
|
||||
}
|
@ -1,23 +1 @@
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::modules::{
|
||||
helm::chart::HelmChartScore,
|
||||
monitoring::kube_prometheus::kube_prometheus_helm_chart_score::kube_prometheus_helm_chart_score,
|
||||
};
|
||||
|
||||
pub mod k8s;
|
||||
pub mod monitoring;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct K8sMonitorConfig {
|
||||
//probably need to do something better here
|
||||
pub chart: HelmChartScore,
|
||||
}
|
||||
|
||||
impl K8sMonitorConfig {
|
||||
pub fn cluster_monitor() -> Self {
|
||||
Self {
|
||||
chart: kube_prometheus_helm_chart_score(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,61 @@
|
||||
use async_trait::async_trait;
|
||||
use dyn_clone::DynClone;
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::executors::ExecutorError;
|
||||
use crate::interpret::InterpretError;
|
||||
use crate::{
|
||||
data::{Id, Version},
|
||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||
inventory::Inventory,
|
||||
topology::{Topology, installable::Installable},
|
||||
};
|
||||
|
||||
use crate::inventory::Inventory;
|
||||
use crate::topology::HelmCommand;
|
||||
use crate::{interpret::Outcome, topology::Topology};
|
||||
pub trait AlertSender: Send + Sync + std::fmt::Debug + Installable {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AlertingInterpret<S: AlertSender> {
|
||||
pub sender: S,
|
||||
pub receivers: Vec<Box<dyn AlertReceiver<S>>>,
|
||||
}
|
||||
|
||||
/// Represents an entity responsible for collecting and organizing observability data
|
||||
/// from various telemetry sources such as Prometheus or Datadog
|
||||
/// A `Monitor` abstracts the logic required to scrape, aggregate, and structure
|
||||
/// monitoring data, enabling consistent processing regardless of the underlying data source.
|
||||
#[async_trait]
|
||||
pub trait Monitor {
|
||||
async fn provision_monitor<T: Topology + HelmCommand>(
|
||||
impl<S: AlertSender, T: Topology> Interpret<T> for AlertingInterpret<S> {
|
||||
async fn execute(
|
||||
&self,
|
||||
inventory: &Inventory,
|
||||
topology: &T,
|
||||
alert_receivers: Option<Vec<Box<dyn AlertChannelConfig>>>,
|
||||
) -> Result<Outcome, InterpretError>;
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
for receiver in self.receivers.iter() {
|
||||
receiver.install(&self.sender).await?;
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn delete_monitor(&self) -> Result<Outcome, InterpretError>;
|
||||
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!()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait AlertChannel: Debug + Send + Sync {
|
||||
async fn register_alert_channel(&self) -> Result<Outcome, ExecutorError>;
|
||||
//async fn get_channel_id(&self) -> String;
|
||||
pub trait AlertReceiver<S: AlertSender>: std::fmt::Debug + Send + Sync {
|
||||
async fn install(&self, sender: &S) -> Result<(), InterpretError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait AlertChannelConfig: Debug + Send + Sync + DynClone {
|
||||
async fn build_alert_channel(&self) -> Result<Box<dyn AlertChannel>, InterpretError>;
|
||||
pub trait AlertRule<S: AlertSender> {
|
||||
async fn install(&self, sender: &S) -> Result<(), InterpretError>;
|
||||
}
|
||||
|
||||
dyn_clone::clone_trait_object!(AlertChannelConfig);
|
||||
#[async_trait]
|
||||
pub trait ScrapeTarger<S: AlertSender> {
|
||||
async fn install(&self, sender: &S) -> Result<(), InterpretError>;
|
||||
}
|
||||
|
@ -1,54 +1,20 @@
|
||||
use log::debug;
|
||||
use serde::Serialize;
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
modules::monitoring::{
|
||||
alert_receiver::AlertReceiver,
|
||||
prometheus::{Prometheus, PrometheusReceiver},
|
||||
},
|
||||
topology::Url,
|
||||
interpret::InterpretError,
|
||||
modules::monitoring::kube_prometheus::prometheus::{Prometheus, PrometheusReceiver},
|
||||
topology::{Url, oberservability::monitoring::AlertReceiver},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[derive(Debug)]
|
||||
pub struct DiscordWebhook {
|
||||
pub name: String,
|
||||
pub url: Url,
|
||||
}
|
||||
|
||||
impl AlertReceiver for DiscordWebhook {
|
||||
type M = Prometheus;
|
||||
|
||||
fn install(&self, sender: &Self::M) -> Result<(), String> {
|
||||
sender.configure_receiver(Box::new(self))?;
|
||||
debug!("DiscordWebhook installed for Prometheus");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clone_box(&self) -> Box<dyn AlertReceiver<M = Self::M>> {
|
||||
Box::new(self.clone())
|
||||
#[async_trait]
|
||||
impl AlertReceiver<Prometheus> for DiscordWebhook {
|
||||
async fn install(&self, sender: &Prometheus) -> Result<(), InterpretError> {
|
||||
sender.install_receiver(PrometheusReceiver {}).await
|
||||
}
|
||||
}
|
||||
|
||||
impl PrometheusReceiver for DiscordWebhook {
|
||||
fn get_prometheus_config(
|
||||
&self,
|
||||
) -> crate::modules::monitoring::prometheus::PrometheusReceiverConfig {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
// #[derive(Debug, Clone, Serialize)]
|
||||
// pub struct DiscordWebhookScore {
|
||||
// pub config: DiscordWebhook,
|
||||
// }
|
||||
//
|
||||
// impl<T: Topology> Score<T> for DiscordWebhookScore {
|
||||
// fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
||||
// Box::new(AlertReceiverInterpret {
|
||||
// receiver: Box::new(self.config.clone()),
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// fn name(&self) -> String {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
|
@ -1,57 +0,0 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
data::{Id, Version},
|
||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||
inventory::Inventory,
|
||||
topology::Topology,
|
||||
};
|
||||
|
||||
use super::monitoring_alerting::MonitoringSystem;
|
||||
|
||||
|
||||
pub trait AlertReceiver: Debug + Send + Sync {
|
||||
type M: MonitoringSystem;
|
||||
|
||||
fn install(&self, sender: &Self::M) -> Result<(), String>;
|
||||
fn clone_box(&self) -> Box<dyn AlertReceiver<M = Self::M>>;
|
||||
}
|
||||
|
||||
struct AlertReceiverConfig<M: MonitoringSystem> {
|
||||
config: String, // Or whatever
|
||||
sender: M,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AlertReceiverInterpret<M: MonitoringSystem> {
|
||||
pub receiver: Box<dyn AlertReceiver<M = M>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: Topology, M: MonitoringSystem> Interpret<T> for AlertReceiverInterpret<M> {
|
||||
async fn execute(
|
||||
&self,
|
||||
_inventory: &Inventory,
|
||||
_topology: &T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
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!()
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use dyn_clone::DynClone;
|
||||
|
||||
use super::monitoring_alerting::MonitoringSystem;
|
||||
|
||||
|
||||
pub trait AlertRule: Debug + Send + Sync + DynClone {
|
||||
type M: MonitoringSystem;
|
||||
|
||||
fn install(&self, sender: &Self::M);
|
||||
fn clone_box(&self) -> Box<dyn AlertRule<M = Self::M>>;
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
use async_trait::async_trait;
|
||||
use serde::{Serializer, Serialize};
|
||||
|
||||
use crate::{
|
||||
data::{Id, Version},
|
||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||
inventory::Inventory,
|
||||
score::Score,
|
||||
topology::{HelmCommand, Topology, Url},
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
pub trait Installable {
|
||||
async fn ensure_installed(&self) -> Result<(), InterpretError>;
|
||||
}
|
||||
|
||||
pub trait AlertSender: Send + Sync + std::fmt::Debug + Installable {}
|
||||
|
||||
#[async_trait]
|
||||
pub trait AlertReceiver<S: AlertSender>: std::fmt::Debug + Send + Sync {
|
||||
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 HelmPrometheusAlertingScore {
|
||||
pub receivers: Vec<Box<dyn AlertReceiver<Prometheus>>>,
|
||||
}
|
||||
|
||||
impl Serialize for Box<dyn AlertReceiver<Prometheus>> {
|
||||
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
impl Clone for Box<dyn AlertReceiver<Prometheus>> {
|
||||
fn clone(&self) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Topology + HelmCommand> Score<T> for HelmPrometheusAlertingScore {
|
||||
fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
|
||||
Box::new(AlertingInterpret {
|
||||
sender: Prometheus {},
|
||||
receivers: vec![Box::new(DiscordWebhook {url:todo!(), name: todo!() })],
|
||||
})
|
||||
}
|
||||
|
||||
fn name(&self) -> 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,
|
||||
pub receivers: Vec<Box<dyn AlertReceiver<S>>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S: AlertSender, T: Topology> Interpret<T> for AlertingInterpret<S> {
|
||||
#[must_use]
|
||||
async fn execute(
|
||||
&self,
|
||||
inventory: &Inventory,
|
||||
topology: &T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
for receiver in self.receivers.iter() {
|
||||
receiver.install(&self.sender).await?;
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
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!()
|
||||
}
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
use serde::Serialize;
|
||||
|
||||
use super::types::AlertManagerChannelConfig;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct KubePrometheusConfig {
|
||||
pub namespace: String,
|
||||
@ -21,7 +19,6 @@ pub struct KubePrometheusConfig {
|
||||
pub kube_proxy: bool,
|
||||
pub kube_state_metrics: bool,
|
||||
pub prometheus_operator: bool,
|
||||
pub alert_channels: Vec<AlertManagerChannelConfig>,
|
||||
}
|
||||
impl KubePrometheusConfig {
|
||||
pub fn new() -> Self {
|
||||
@ -43,7 +40,6 @@ impl KubePrometheusConfig {
|
||||
prometheus_operator: true,
|
||||
core_dns: false,
|
||||
kube_scheduler: false,
|
||||
alert_channels: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
pub mod config;
|
||||
pub mod kube_prometheus_helm_chart;
|
@ -0,0 +1,47 @@
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
modules::monitoring::alert_channel::discord_alert_channel::DiscordWebhook,
|
||||
score::Score,
|
||||
topology::{
|
||||
HelmCommand, Topology,
|
||||
oberservability::monitoring::{AlertReceiver, AlertingInterpret},
|
||||
},
|
||||
};
|
||||
|
||||
use super::prometheus::Prometheus;
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
pub struct HelmPrometheusAlertingScore {
|
||||
pub receivers: Vec<Box<dyn AlertReceiver<Prometheus>>>,
|
||||
}
|
||||
|
||||
impl<T: Topology + HelmCommand> Score<T> for HelmPrometheusAlertingScore {
|
||||
fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
|
||||
Box::new(AlertingInterpret {
|
||||
sender: Prometheus {},
|
||||
receivers: vec![Box::new(DiscordWebhook {
|
||||
url: todo!(),
|
||||
name: todo!(),
|
||||
})],
|
||||
})
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
"HelmPrometheusAlertingScore".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for Box<dyn AlertReceiver<Prometheus>> {
|
||||
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
impl Clone for Box<dyn AlertReceiver<Prometheus>> {
|
||||
fn clone(&self) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod config;
|
||||
pub mod kube_prometheus_helm_chart_score;
|
||||
pub mod helm;
|
||||
pub mod helm_prometheus_alert_score;
|
||||
pub mod prometheus;
|
||||
pub mod types;
|
||||
|
34
harmony/src/modules/monitoring/kube_prometheus/prometheus.rs
Normal file
34
harmony/src/modules/monitoring/kube_prometheus/prometheus.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
interpret::InterpretError,
|
||||
topology::{installable::Installable, oberservability::monitoring::AlertSender},
|
||||
};
|
||||
|
||||
impl AlertSender for Prometheus {}
|
||||
|
||||
#[async_trait]
|
||||
impl Installable for Prometheus {
|
||||
async fn ensure_installed(&self) -> Result<(), InterpretError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub struct Prometheus;
|
||||
|
||||
impl Prometheus {
|
||||
pub 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 {}
|
@ -1,14 +1,12 @@
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AlertManagerChannelConfig {
|
||||
pub global_configs: AlertManagerChannelGlobalConfigs,
|
||||
pub route: AlertManagerChannelRoute,
|
||||
pub receiver: AlertManagerChannelReceiver,
|
||||
#[derive(Serialize)]
|
||||
pub struct AlertReceiverRoute {
|
||||
pub receiver: String,
|
||||
pub matchers: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub r#continue: bool,
|
||||
}
|
||||
pub struct AlertChannelReceiver {
|
||||
pub name: String,
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AlertManagerChannelGlobalConfigs {}
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AlertManagerChannelReceiver {}
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AlertManagerChannelRoute {}
|
||||
|
@ -1,8 +1,2 @@
|
||||
pub mod alert_channel;
|
||||
pub mod alert_receiver;
|
||||
pub mod alert_rule;
|
||||
pub mod kube_prometheus;
|
||||
pub mod monitoring_alerting;
|
||||
pub mod prometheus;
|
||||
pub mod scrape_target;
|
||||
pub mod alert_score;
|
||||
|
@ -1,115 +0,0 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use log::debug;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
data::{Id, Version},
|
||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||
inventory::Inventory,
|
||||
score::Score,
|
||||
topology::Topology,
|
||||
};
|
||||
|
||||
use super::{alert_receiver::AlertReceiver, prometheus::Installable};
|
||||
use super::alert_rule::AlertRule;
|
||||
use super::scrape_target::ScrapeTarget;
|
||||
|
||||
#[async_trait]
|
||||
pub trait MonitoringSystem: std::fmt::Debug + Clone + Serialize + 'static + Send + Sync {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MonitoringAlertingScore<M: MonitoringSystem> {
|
||||
pub alert_receivers: Vec<Box<dyn AlertReceiver<M = M>>>,
|
||||
pub alert_rules: Vec<Box<dyn AlertRule<M = M>>>,
|
||||
pub scrape_targets: Vec<Box<dyn ScrapeTarget<M = M>>>,
|
||||
}
|
||||
|
||||
impl<M: MonitoringSystem> Clone for Box<dyn AlertReceiver<M = M>> {
|
||||
fn clone(&self) -> Self {
|
||||
self.clone_box()
|
||||
}
|
||||
}
|
||||
impl<M: MonitoringSystem> Clone for Box<dyn AlertRule<M = M>> {
|
||||
fn clone(&self) -> Self {
|
||||
self.clone_box()
|
||||
}
|
||||
}
|
||||
impl<M: MonitoringSystem> Clone for Box<dyn ScrapeTarget<M = M>> {
|
||||
fn clone(&self) -> Self {
|
||||
self.clone_box()
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: MonitoringSystem> Serialize for MonitoringAlertingScore<M> {
|
||||
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Topology, M: MonitoringSystem + Serialize + Installable> Score<T>
|
||||
for MonitoringAlertingScore<M>
|
||||
{
|
||||
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
||||
Box::new(MonitoringAlertingInterpret {
|
||||
score: Arc::new(self.clone()),
|
||||
})
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
"MonitoringAlertingScore".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct MonitoringAlertingInterpret<M: MonitoringSystem> {
|
||||
score: Arc<MonitoringAlertingScore<M>>,
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[async_trait]
|
||||
impl<M: MonitoringSystem + Installable, T: Topology> Interpret<T>
|
||||
for MonitoringAlertingInterpret<M>
|
||||
{
|
||||
async fn execute(
|
||||
&self,
|
||||
_inventory: &Inventory,
|
||||
_topology: &T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
debug!("score {:#?}", self.score);
|
||||
todo!("Figure out a clean way to have things come together here :
|
||||
We want Prometheus to be bound like this :
|
||||
|
||||
DiscordWebhook (AlertReceiver<Sender = Prometheus>)
|
||||
|
|
||||
Prometheus (AlertSender + Scraper + Installable<T: HelmCommand>)
|
||||
^
|
||||
MonitoringScore {{ alert_rules, alert_receivers, scrape_endpoints }}
|
||||
(Interpret<T: Topology + Installer
|
||||
|
||||
")
|
||||
}
|
||||
|
||||
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!()
|
||||
}
|
||||
}
|
||||
|
@ -1,112 +0,0 @@
|
||||
use async_trait::async_trait;
|
||||
use serde::Serialize;
|
||||
use serde_value::Value;
|
||||
|
||||
use crate::{
|
||||
data::{Id, Version},
|
||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||
inventory::Inventory,
|
||||
topology::{K8sAnywhereTopology, Topology},
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
|
||||
use super::monitoring_alerting::MonitoringSystem;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct Prometheus {}
|
||||
|
||||
impl Prometheus {
|
||||
pub fn configure_receiver(&self, receiver: Box<&dyn PrometheusReceiver>) -> Result<(), String> {
|
||||
let _receiver_config = receiver.get_prometheus_config();
|
||||
todo!()
|
||||
}
|
||||
pub fn configure_rule(&self, _rule: Box<&dyn PrometheusRule>) {
|
||||
todo!()
|
||||
}
|
||||
pub fn configure_scrape_target(&self, _target: Box<&dyn PrometheusScrapeTarget>) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl MonitoringSystem for Prometheus {}
|
||||
|
||||
pub trait PrometheusCapability {
|
||||
fn install_alert_receivers(&self, receivers: Vec<Box<dyn PrometheusReceiver>>);
|
||||
fn install_alert_rules(&self, rules: Vec<Box<dyn PrometheusRule>>);
|
||||
fn install_scrape_targets(&self, receivers: Vec<Box<dyn PrometheusScrapeTarget>>);
|
||||
}
|
||||
|
||||
pub trait PrometheusReceiver {
|
||||
fn get_prometheus_config(&self) -> PrometheusReceiverConfig;
|
||||
}
|
||||
|
||||
pub struct PrometheusReceiverConfig {
|
||||
config: Value, // either a serde Value or a more specific type that understands prometheus
|
||||
// config
|
||||
}
|
||||
|
||||
pub trait PrometheusRule {
|
||||
fn get_prometheus_config(&self) -> PrometheusRuleConfig;
|
||||
}
|
||||
|
||||
pub struct PrometheusRuleConfig {
|
||||
pub definition: String, // Not a string but an actual prometheus rule config
|
||||
}
|
||||
|
||||
pub trait PrometheusScrapeTarget {
|
||||
fn get_prometheus_config(&self) -> PrometheusScrapeTargetConfig;
|
||||
}
|
||||
|
||||
pub struct PrometheusScrapeTargetConfig {
|
||||
pub definition: String, // Not a string but an actual prometheus scraping config
|
||||
}
|
||||
|
||||
pub struct PrometheusMonitoringScore {
|
||||
alert_receivers: Vec<Box<PrometheusReceiverConfig>>,
|
||||
alert_rules: Vec<Box<PrometheusRuleConfig>>,
|
||||
scrape_targets: Vec<Box<PrometheusScrapeTargetConfig>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PrometheusMonitoringInterpret {}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: Topology + PrometheusCapability> Interpret<T> for PrometheusMonitoringInterpret {
|
||||
async fn execute(
|
||||
&self,
|
||||
_inventory: &Inventory,
|
||||
_topology: &T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
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!()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait Installable {
|
||||
async fn install(&self) -> Result<Outcome, InterpretError>;
|
||||
type Installer;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Installable for Prometheus {
|
||||
type Installer = K8sAnywhereTopology;
|
||||
async fn install(&self) -> Result<Outcome, InterpretError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use dyn_clone::DynClone;
|
||||
|
||||
use super::monitoring_alerting::MonitoringSystem;
|
||||
|
||||
|
||||
pub trait ScrapeTarget: Debug + Send + Sync + DynClone {
|
||||
type M: MonitoringSystem;
|
||||
|
||||
fn install(&self, sender: &Self::M);
|
||||
fn clone_box(&self) -> Box<dyn ScrapeTarget<M = Self::M>>;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user