Compare commits
	
		
			2 Commits
		
	
	
		
			6c145f1100
			...
			2f8e150f41
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 2f8e150f41 | |||
| a6bcaade46 | 
| @ -1,3 +1,4 @@ | |||||||
|  | pub mod monitoring_alerting; | ||||||
| mod ha_cluster; | mod ha_cluster; | ||||||
| mod host_binding; | mod host_binding; | ||||||
| mod http; | mod http; | ||||||
|  | |||||||
| @ -1,4 +1,3 @@ | |||||||
| 
 |  | ||||||
| use std::str::FromStr; | use std::str::FromStr; | ||||||
| 
 | 
 | ||||||
| use non_blank_string_rs::NonBlankString; | use non_blank_string_rs::NonBlankString; | ||||||
| @ -9,9 +8,10 @@ use crate::modules::helm::chart::HelmChartScore; | |||||||
| pub fn kube_prometheus_score(ns: &str) -> HelmChartScore { | pub fn kube_prometheus_score(ns: &str) -> HelmChartScore { | ||||||
|     HelmChartScore { |     HelmChartScore { | ||||||
|         namespace: Some(NonBlankString::from_str(ns).unwrap()), |         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( |         chart_name: NonBlankString::from_str( | ||||||
|         todo!() //use kube prometheus chart which includes grafana, prometheus, alert
 |             "https://prometheus-community.github.io/helm-charts" | ||||||
|  |          //use kube prometheus chart which includes grafana, prometheus, alert
 | ||||||
|          //manager, etc
 |          //manager, etc
 | ||||||
|             ) |             ) | ||||||
|         .unwrap(), |         .unwrap(), | ||||||
| @ -1,3 +1,3 @@ | |||||||
| mod monitoring_alerting; | pub mod monitoring_alerting; | ||||||
| mod resources; | mod kube_prometheus; | ||||||
| pub use monitoring_alerting::*; | 
 | ||||||
|  | |||||||
| @ -1,21 +1,118 @@ | |||||||
|  | use async_trait::async_trait; | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| use crate::{ | 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 { | 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 { | impl<T: Topology> Score<T> for MonitoringAlertingStackScore { | ||||||
| 
 |  | ||||||
|     fn create_interpret(&self) -> Box<dyn Interpret<T>> { |     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 { |     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!() |         todo!() | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1 +0,0 @@ | |||||||
| mod kube_prometheus; |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user