Compare commits

...

2 Commits

5 changed files with 110 additions and 13 deletions

View File

@ -1,3 +1,4 @@
pub mod monitoring_alerting;
mod ha_cluster;
mod host_binding;
mod http;

View File

@ -1,4 +1,3 @@
use std::str::FromStr;
use non_blank_string_rs::NonBlankString;
@ -9,10 +8,11 @@ use crate::modules::helm::chart::HelmChartScore;
pub fn kube_prometheus_score(ns: &str) -> HelmChartScore {
HelmChartScore {
namespace: Some(NonBlankString::from_str(ns).unwrap()),
release_name: NonBlankString::from_str("es").unwrap(),
release_name: NonBlankString::from_str("kube-prometheus").unwrap(),
chart_name: NonBlankString::from_str(
todo!() //use kube prometheus chart which includes grafana, prometheus, alert
//manager, etc
"https://prometheus-community.github.io/helm-charts"
//use kube prometheus chart which includes grafana, prometheus, alert
//manager, etc
)
.unwrap(),
chart_version: None,

View File

@ -1,3 +1,3 @@
mod monitoring_alerting;
mod resources;
pub use monitoring_alerting::*;
pub mod monitoring_alerting;
mod kube_prometheus;

View File

@ -1,21 +1,118 @@
use async_trait::async_trait;
use serde::Serialize;
use crate::{
interpret::Interpret, maestro::Maestro, modules::helm::chart::HelmChartScore, score::Score, topology::{K8sclient, Topology}
data::{Id, Version},
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
inventory::Inventory,
maestro::{self, Maestro},
modules::helm::chart::HelmChartScore,
score::{CloneBoxScore, Score},
topology::{K8sclient, Topology, monitoring_alerting::MonitoringAlertingTopology},
};
#[derive(Debug, Clone, Serialize)]
use super::kube_prometheus::kube_prometheus_score;
#[derive(Debug)]
pub struct MonitoringAlertingStackScore {
monitoring: HelmChartScore,
pub monitoring_stack: Vec<Box<dyn Score<MonitoringAlertingTopology>>>,
}
impl Default for MonitoringAlertingStackScore {
fn default() -> Self {
let ns = "monitoring";
Self {
monitoring_stack: vec![
Box::new(kube_prometheus_score(ns)) as Box<dyn Score<MonitoringAlertingTopology>>,
],
}
}
}
impl Clone for MonitoringAlertingStackScore {
fn clone(&self) -> Self {
Self {
monitoring_stack: self.monitoring_stack.iter().map(|s| s.clone_box()).collect(),
}
}
}
impl Serialize for MonitoringAlertingStackScore {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
use serde::ser::SerializeStruct;
let mut s = serializer.serialize_struct("MonitoringAlertingStackScore", 1)?;
let monitoring_values: Vec<_> = self.monitoring_stack.iter().map(|m| m.serialize()).collect();
s.serialize_field("monitoring", &monitoring_values)?;
s.end()
}
}
impl<T: Topology> Score<T> for MonitoringAlertingStackScore {
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
todo!()
Box::new(MonitoringAlertingStackInterpret {
score: MonitoringAlertingStackScore {
monitoring_stack: self.monitoring_stack.iter().map(|s| s.clone_box()).collect(),
},
})
}
fn name(&self) -> String {
format!("MonitoringAlertingStackScore")
}
}
#[derive(Debug)]
struct MonitoringAlertingStackInterpret {
pub score: MonitoringAlertingStackScore,
}
impl MonitoringAlertingStackInterpret {
pub async fn build_monitoring_stack(
&self,
monitoring_stack: MonitoringAlertingStackScore,
) -> Result<Outcome, InterpretError> {
let inventory = Inventory::autoload();
let topology = MonitoringAlertingTopology::new();
let mut maestro = match Maestro::initialize(inventory, topology).await {
Ok(m) => m,
Err(e) => {
println!("failed to initialize Maestro: {}", e);
std::process::exit(1);
}
};
maestro.register_all(monitoring_stack.monitoring_stack);
Ok(Outcome::success(format!(
"installed kube-prometheus monitoring and alerting stack"
)))
}
}
#[async_trait]
impl<T: Topology> Interpret<T> for MonitoringAlertingStackInterpret {
async fn execute(
&self,
_inventory: &Inventory,
_topology: &T,
) -> Result<Outcome, InterpretError> {
self.build_monitoring_stack(self.score.clone()).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!()
}
}

View File

@ -1 +0,0 @@
mod kube_prometheus;