107 lines
3.1 KiB
Rust
107 lines
3.1 KiB
Rust
use std::sync::{Arc, Mutex};
|
|
|
|
use async_trait::async_trait;
|
|
use log::debug;
|
|
use serde_yaml::Value;
|
|
|
|
use crate::{
|
|
interpret::{InterpretError, Outcome},
|
|
inventory::Inventory,
|
|
score,
|
|
topology::{
|
|
HelmCommand, K8sAnywhereTopology, Topology, installable::Installable,
|
|
oberservability::monitoring::AlertSender,
|
|
},
|
|
};
|
|
|
|
use score::Score;
|
|
|
|
use super::{helm::{
|
|
config::KubePrometheusConfig, kube_prometheus_helm_chart::kube_prometheus_helm_chart_score,
|
|
}, types::AlertManagerChannelConfig};
|
|
|
|
#[async_trait]
|
|
impl AlertSender for Prometheus {
|
|
fn name(&self) -> String {
|
|
"HelmKubePrometheus".to_string()
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl<T: Topology + HelmCommand> Installable<T> for Prometheus {
|
|
async fn ensure_installed(&self, inventory: &Inventory, topology: &T) -> Result<(), InterpretError> {
|
|
//install_prometheus
|
|
self.install_prometheus(inventory, topology).await?;
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
// //before we talked about having a trait installable and a trait installer for the topology
|
|
// // i feel like that might still be necessary to meet the requirement of inventory and topology on
|
|
// // the score.create_interpret().execute(inventory, topology) method
|
|
// #[async_trait]
|
|
// pub trait Installer {
|
|
// async fn install(&self, inventory: &Inventory, sender: Box<dyn Installable>) -> Result<(), InterpretError>;
|
|
// }
|
|
//
|
|
// #[async_trait]
|
|
// impl Installer for K8sAnywhereTopology {
|
|
// async fn install(
|
|
// &self,
|
|
// inventory: &Inventory,
|
|
// installable: Box<dyn Installable<T>>,
|
|
// ) -> Result<(), InterpretError> {
|
|
// installable.ensure_installed(inventory, self).await?;
|
|
// Ok(())
|
|
// }
|
|
// }
|
|
|
|
#[derive(Debug)]
|
|
pub struct Prometheus {
|
|
pub config: Arc<Mutex<KubePrometheusConfig>>,
|
|
}
|
|
|
|
impl Prometheus {
|
|
pub async fn install_receiver(
|
|
&self,
|
|
prometheus_receiver: &dyn PrometheusReceiver,
|
|
) -> Result<Outcome, InterpretError> {
|
|
let prom_receiver = prometheus_receiver.configure_receiver().await;
|
|
debug!(
|
|
"adding alert receiver to prometheus config: {:#?}",
|
|
&prom_receiver
|
|
);
|
|
let mut config = self.config.lock().unwrap();
|
|
|
|
config.alert_receiver_configs.push(prom_receiver);
|
|
let prom_receiver_name = prometheus_receiver.name();
|
|
debug!("installed alert receiver {}", &prom_receiver_name);
|
|
Ok(Outcome::success(format!(
|
|
"Sucessfully installed receiver {}",
|
|
prom_receiver_name
|
|
)))
|
|
}
|
|
|
|
pub async fn install_prometheus<T: Topology + HelmCommand + Send + Sync>(
|
|
&self,
|
|
inventory: &Inventory,
|
|
topology: &T,
|
|
) -> Result<Outcome, InterpretError> {
|
|
kube_prometheus_helm_chart_score(self.config.clone())
|
|
.create_interpret()
|
|
.execute(inventory, topology)
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait PrometheusReceiver: Send + Sync + std::fmt::Debug {
|
|
fn name(&self) -> String;
|
|
async fn configure_receiver(&self) -> AlertManagerChannelConfig;
|
|
//this probably needs to be a type
|
|
//that
|
|
//represents
|
|
//a
|
|
//promtheusreceiver
|
|
}
|