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