forked from NationTech/harmony
feat: depoloys cluster monitoring stack from monitoring score on k8sanywhere topology
This commit is contained in:
parent
238d1f85e2
commit
613def5e0b
12
examples/monitoring/Cargo.toml
Normal file
12
examples/monitoring/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "webhook_sender"
|
||||
edition = "2024"
|
||||
version.workspace = true
|
||||
readme.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
harmony = { version = "0.1.0", path = "../../harmony" }
|
||||
harmony_cli = { version = "0.1.0", path = "../../harmony_cli" }
|
||||
tokio.workspace = true
|
||||
url.workspace = true
|
||||
23
examples/monitoring/src/main.rs
Normal file
23
examples/monitoring/src/main.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use harmony::{
|
||||
inventory::Inventory,
|
||||
maestro::Maestro,
|
||||
modules::monitoring::monitoring_alerting::MonitoringAlertingScore,
|
||||
topology::{K8sAnywhereTopology, oberservability::K8sMonitorConfig},
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
|
||||
Inventory::autoload(),
|
||||
K8sAnywhereTopology::new(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let monitoring = MonitoringAlertingScore {
|
||||
alert_channel_configs: None,
|
||||
};
|
||||
|
||||
maestro.register_all(vec![Box::new(monitoring)]);
|
||||
harmony_cli::init(maestro, None).await.unwrap();
|
||||
}
|
||||
@ -10,7 +10,10 @@ use crate::{
|
||||
interpret::{InterpretError, Outcome},
|
||||
inventory::Inventory,
|
||||
maestro::Maestro,
|
||||
modules::{k3d::K3DInstallationScore, monitoring::kube_prometheus::kube_prometheus_helm_chart_score::kube_prometheus_helm_chart_score},
|
||||
modules::{
|
||||
k3d::K3DInstallationScore,
|
||||
monitoring::kube_prometheus::kube_prometheus_helm_chart_score::kube_prometheus_helm_chart_score,
|
||||
},
|
||||
topology::LocalhostTopology,
|
||||
};
|
||||
|
||||
@ -193,9 +196,7 @@ impl K8sAnywhereTopology {
|
||||
|
||||
self.k8s_monitor
|
||||
.get_or_try_init(async || -> Result<K8sMonitor, String> {
|
||||
let config = K8sMonitorConfig {
|
||||
chart: kube_prometheus_helm_chart_score(),
|
||||
};
|
||||
let config = K8sMonitorConfig::cluster_monitor();
|
||||
Ok(K8sMonitor { config })
|
||||
})
|
||||
.await
|
||||
@ -302,12 +303,14 @@ impl TenantManager for K8sAnywhereTopology {
|
||||
}
|
||||
#[async_trait]
|
||||
impl Monitor for K8sAnywhereTopology {
|
||||
async fn provision_monitor(
|
||||
async fn provision_monitor<T: Topology + HelmCommand>(
|
||||
&self,
|
||||
inventory: &Inventory,
|
||||
topology: &T,
|
||||
alert_receivers: Option<Vec<Box<dyn AlertChannelConfig>>>,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
self.get_k8s_monitor()?
|
||||
.provision_monitor(alert_receivers)
|
||||
.provision_monitor(inventory, topology, alert_receivers)
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
@ -3,14 +3,13 @@ use std::sync::Arc;
|
||||
use async_trait::async_trait;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::score::Score;
|
||||
|
||||
use crate::topology::HelmCommand;
|
||||
use crate::{
|
||||
interpret::{InterpretError, Outcome},
|
||||
inventory::Inventory,
|
||||
modules::{helm::chart::HelmChartInterpret, monitoring::kube_prometheus::{
|
||||
config::KubePrometheusConfig,
|
||||
kube_prometheus_helm_chart_score::kube_prometheus_helm_chart_score,
|
||||
}},
|
||||
topology::{K8sAnywhereTopology, Topology},
|
||||
topology::Topology,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@ -25,19 +24,23 @@ pub struct K8sMonitor {
|
||||
|
||||
#[async_trait]
|
||||
impl Monitor for K8sMonitor {
|
||||
async fn provision_monitor(
|
||||
async fn provision_monitor<T: Topology + HelmCommand>(
|
||||
&self,
|
||||
alert_receivers: Option<Vec<Box<dyn AlertChannelConfig>>>,
|
||||
inventory: &Inventory,
|
||||
topology: &T,
|
||||
alert_channels: Option<Vec<Box<dyn AlertChannelConfig>>>,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
if let Some(receivers) = alert_receivers {
|
||||
let alert_channels = self.build_alert_channels(receivers).await?;
|
||||
if let Some(channels) = alert_channels {
|
||||
let alert_channels = self.build_alert_channels(channels).await?;
|
||||
for channel in alert_channels {
|
||||
channel.register_alert_channel().await?;
|
||||
}
|
||||
}
|
||||
let chart = self.config.chart.clone();
|
||||
//
|
||||
chart.create_interpret();
|
||||
chart
|
||||
.create_interpret()
|
||||
.execute(inventory, topology)
|
||||
.await?;
|
||||
Ok(Outcome::success("installed monitor".to_string()))
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,23 @@
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::modules::helm::chart::HelmChartScore;
|
||||
use crate::modules::{
|
||||
helm::chart::HelmChartScore,
|
||||
monitoring::kube_prometheus::kube_prometheus_helm_chart_score::kube_prometheus_helm_chart_score,
|
||||
};
|
||||
|
||||
pub mod monitoring;
|
||||
pub mod k8s;
|
||||
pub mod monitoring;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct K8sMonitorConfig {
|
||||
//probably need to do something better here
|
||||
pub chart: HelmChartScore,
|
||||
}
|
||||
|
||||
impl K8sMonitorConfig {
|
||||
pub fn cluster_monitor() -> Self {
|
||||
Self {
|
||||
chart: kube_prometheus_helm_chart_score(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
use async_trait::async_trait;
|
||||
use dyn_clone::DynClone;
|
||||
use serde::Serialize;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::executors::ExecutorError;
|
||||
use crate::interpret::InterpretError;
|
||||
|
||||
use crate::inventory::Inventory;
|
||||
use crate::topology::HelmCommand;
|
||||
use crate::{interpret::Outcome, topology::Topology};
|
||||
|
||||
/// Represents an entity responsible for collecting and organizing observability data
|
||||
@ -16,8 +15,10 @@ use crate::{interpret::Outcome, topology::Topology};
|
||||
/// monitoring data, enabling consistent processing regardless of the underlying data source.
|
||||
#[async_trait]
|
||||
pub trait Monitor {
|
||||
async fn provision_monitor(
|
||||
async fn provision_monitor<T: Topology + HelmCommand>(
|
||||
&self,
|
||||
inventory: &Inventory,
|
||||
topology: &T,
|
||||
alert_receivers: Option<Vec<Box<dyn AlertChannelConfig>>>,
|
||||
) -> Result<Outcome, InterpretError>;
|
||||
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
use url::Url;
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DiscordWebhookAlertChannel {
|
||||
pub webhook_url: Url,
|
||||
|
||||
@ -220,8 +220,6 @@ prometheus:
|
||||
// alertmanager_config
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//fn discord_alert_builder(release_name: &String) -> (String, String) {
|
||||
// let discord_receiver_name = format!("Discord-{}", release_name);
|
||||
// let receiver = format!(
|
||||
|
||||
@ -77,11 +77,9 @@
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
//#[async_trait]
|
||||
//pub trait PrometheusAlertChannel {
|
||||
// fn get_alert_channel_global_settings(&self) -> Option<AlertManagerChannelGlobalConfigs>;
|
||||
// fn get_alert_channel_route(&self) -> AlertManagerChannelRoute;
|
||||
// fn get_alert_channel_receiver(&self) -> AlertManagerChannelReceiver;
|
||||
//}
|
||||
|
||||
|
||||
@ -1,11 +1,16 @@
|
||||
use async_trait::async_trait;
|
||||
use serde::{Serialize, Serializer, ser::SerializeStruct};
|
||||
use std::{fmt::Debug, sync::Arc};
|
||||
|
||||
use crate::{data::{Id, Version}, interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, inventory::Inventory, score::Score, topology::{
|
||||
oberservability::monitoring::{AlertChannelConfig, Monitor},HelmCommand, Topology
|
||||
}};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
data::{Id, Version},
|
||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||
inventory::Inventory,
|
||||
score::Score,
|
||||
topology::{
|
||||
HelmCommand, Topology,
|
||||
oberservability::monitoring::{AlertChannelConfig, Monitor},
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct MonitoringAlertingScore {
|
||||
@ -37,7 +42,13 @@ impl<T: Topology + HelmCommand + Monitor> Interpret<T> for MonitoringAlertingInt
|
||||
inventory: &Inventory,
|
||||
topology: &T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
topology.provision_monitor(self.score.alert_channel_configs.clone()).await
|
||||
topology
|
||||
.provision_monitor(
|
||||
inventory,
|
||||
topology,
|
||||
self.score.alert_channel_configs.clone(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
fn get_name(&self) -> InterpretName {
|
||||
@ -56,5 +67,3 @@ impl<T: Topology + HelmCommand + Monitor> Interpret<T> for MonitoringAlertingInt
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user