make it compile, need to think about Installer/Installable concept a bit more
This commit is contained in:
parent
a41230ac7b
commit
3c20574e6f
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1161,6 +1161,7 @@ dependencies = [
|
||||
"harmony",
|
||||
"harmony_cli",
|
||||
"tokio",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -4,13 +4,17 @@ use crate::{
|
||||
data::{Id, Version},
|
||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||
inventory::Inventory,
|
||||
topology::{Topology, installable::Installable},
|
||||
modules::monitoring::kube_prometheus::prometheus::Installer,
|
||||
topology::{HelmCommand, Topology, installable::Installable},
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
pub trait AlertSender: Send + Sync + std::fmt::Debug + Installable {
|
||||
fn name(&self) -> String;
|
||||
async fn install(&self) -> Result<Outcome, InterpretError>;
|
||||
async fn install<T: Topology + HelmCommand>(
|
||||
&self,
|
||||
topology: T,
|
||||
) -> Result<Outcome, InterpretError>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -1,10 +1,16 @@
|
||||
use super::config::KubePrometheusConfig;
|
||||
use non_blank_string_rs::NonBlankString;
|
||||
use std::str::FromStr;
|
||||
use std::{
|
||||
str::FromStr,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use crate::modules::helm::chart::HelmChartScore;
|
||||
|
||||
pub fn kube_prometheus_helm_chart_score(config: KubePrometheusConfig) -> HelmChartScore {
|
||||
pub fn kube_prometheus_helm_chart_score(
|
||||
config: Arc<Mutex<KubePrometheusConfig>>,
|
||||
) -> HelmChartScore {
|
||||
let config = config.lock().unwrap();
|
||||
//TODO this should be make into a rule with default formatting that can be easily passed as a vec
|
||||
//to the overrides or something leaving the user to deal with formatting here seems bad
|
||||
let default_rules = config.default_rules.to_string();
|
||||
@ -60,14 +66,14 @@ additionalPrometheusRulesMap:
|
||||
- alert: 'PVC Fill Over 95 Percent In 2 Days'
|
||||
expr: |
|
||||
(
|
||||
kubelet_volume_stats_used_bytes
|
||||
/
|
||||
kubelet_volume_stats_used_bytes
|
||||
/
|
||||
kubelet_volume_stats_capacity_bytes
|
||||
) > 0.95
|
||||
AND
|
||||
predict_linear(kubelet_volume_stats_used_bytes[2d], 2 * 24 * 60 * 60)
|
||||
/
|
||||
kubelet_volume_stats_capacity_bytes
|
||||
/
|
||||
kubelet_volume_stats_capacity_bytes
|
||||
> 0.95
|
||||
for: 1m
|
||||
labels:
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::sync::Mutex;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
@ -18,11 +18,11 @@ pub struct HelmPrometheusAlertingScore {
|
||||
pub receivers: Vec<Box<dyn AlertReceiver<Prometheus>>>,
|
||||
}
|
||||
|
||||
impl<T: Topology + HelmCommand + Installable> Score<T> for HelmPrometheusAlertingScore {
|
||||
impl<T: Topology + HelmCommand> Score<T> for HelmPrometheusAlertingScore {
|
||||
fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
|
||||
Box::new(AlertingInterpret {
|
||||
sender: Prometheus {
|
||||
config: Mutex::new(KubePrometheusConfig::new()),
|
||||
config: Arc::new(Mutex::new(KubePrometheusConfig::new())),
|
||||
},
|
||||
receivers: self.receivers.clone(),
|
||||
})
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::sync::Mutex;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use log::debug;
|
||||
@ -25,8 +25,11 @@ impl AlertSender for Prometheus {
|
||||
fn name(&self) -> String {
|
||||
"HelmKubePrometheus".to_string()
|
||||
}
|
||||
async fn install(&self) -> Result<Outcome, InterpretError> {
|
||||
self.install_prometheus();
|
||||
async fn install<T: Topology + HelmCommand + Send + Sync>(
|
||||
&self,
|
||||
topology: T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
let _ = self.install_prometheus(topology).await;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@ -45,21 +48,24 @@ impl Installable for Prometheus {
|
||||
// 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]
|
||||
trait Installer {
|
||||
async fn install(&self, sender: Box<&dyn Installable>) -> Result<(), InterpretError>;
|
||||
pub trait Installer {
|
||||
async fn install<I: Installable + Send + Sync>(&self, sender: I) -> Result<(), InterpretError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Installer for K8sAnywhereTopology {
|
||||
async fn install(&self, installable: Box<&dyn Installable>) -> Result<(), InterpretError> {
|
||||
installable.install().await?;
|
||||
async fn install<I: Installable + Send + Sync>(
|
||||
&self,
|
||||
installable: I,
|
||||
) -> Result<(), InterpretError> {
|
||||
installable.ensure_installed().await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Prometheus {
|
||||
pub config: Mutex<KubePrometheusConfig>,
|
||||
pub config: Arc<Mutex<KubePrometheusConfig>>,
|
||||
}
|
||||
|
||||
impl Prometheus {
|
||||
@ -83,10 +89,13 @@ impl Prometheus {
|
||||
)))
|
||||
}
|
||||
|
||||
pub async fn install_prometheus(&self) -> Result<Outcome, InterpretError> {
|
||||
kube_prometheus_helm_chart_score(self.config.lock().unwrap().clone())
|
||||
pub async fn install_prometheus<T: Topology + HelmCommand + Send + Sync>(
|
||||
&self,
|
||||
topology: T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
kube_prometheus_helm_chart_score(self.config.clone())
|
||||
.create_interpret()
|
||||
.execute()
|
||||
.execute(&Inventory::autoload(), &topology)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user