monitoring-alerting #30

Merged
wjro merged 12 commits from monitoring-alerting into master 2025-05-06 17:50:57 +00:00
5 changed files with 79 additions and 35 deletions
Showing only changes of commit 2f8e150f41 - Show all commits

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;

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,58 +1,103 @@
use async_trait::async_trait;
use serde::Serialize;
use crate::{
interpret::Interpret,
maestro::Maestro,
data::{Id, Version},
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
inventory::Inventory,
maestro::{self, Maestro},
modules::helm::chart::HelmChartScore,
score::Score,
topology::{K8sclient, Topology},
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>>>,
Outdated
Review

Why does the MonitoringAlertingStackScore need a Vec<Box<dyn Score<MonitoringAlertingTopology>>>? It seems like it's never used for anything.

A score's variables should be what is needed to set it up, i.e. any values, rules, etc you want to pass in for the interpret to use to spin up the score

Why does the `MonitoringAlertingStackScore` need a `Vec<Box<dyn Score<MonitoringAlertingTopology>>>`? It seems like it's never used for anything. A score's variables should be what is needed to set it up, i.e. any values, rules, etc you want to pass in for the interpret to use to spin up the score
}
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>> {
Box::new(MonitoringAlertingStackInterpret {
score: self.clone(),
score: MonitoringAlertingStackScore {
monitoring_stack: self.monitoring_stack.iter().map(|s| s.clone_box()).collect(),
},
})
}
fn name(&self) -> String {
format!(
"{} {} MonitoringAlertingStackScore",
self.monitoring.chart_name, self.monitoring.release_name
)
format!("MonitoringAlertingStackScore")
}
}
#[derive(Debug, Serialize)]
#[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 {
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
inventory: &'life1 Inventory,
topology: &'life2 T,
) -> ::core::pin::Pin<
Box<
dyn ::core::future::Future<Output = Result<Outcome, InterpretError>>
+ ::core::marker::Send
+ 'async_trait,
>,
>
where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
{
todo!()
async fn execute(
&self,
_inventory: &Inventory,
_topology: &T,
) -> Result<Outcome, InterpretError> {
self.build_monitoring_stack(self.score.clone()).await
}
fn get_name(&self) -> InterpretName {

View File

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