Compare commits
4 Commits
feat/kube-
...
feat/disco
| Author | SHA1 | Date | |
|---|---|---|---|
| b5b77cf1ac | |||
| dda8e29843 | |||
| b33650e9d5 | |||
| ea4709a409 |
@@ -5,6 +5,7 @@ use inquire::Confirm;
|
||||
use log::{info, warn};
|
||||
use tokio::sync::{Mutex, OnceCell};
|
||||
|
||||
use crate::score::Score;
|
||||
use crate::{
|
||||
executors::ExecutorError,
|
||||
interpret::{InterpretError, Outcome},
|
||||
@@ -17,7 +18,7 @@ use crate::{
|
||||
use super::{
|
||||
HelmCommand, K8sclient, Topology,
|
||||
k8s::K8sClient,
|
||||
oberservability::monitoring::AlertReceiver,
|
||||
oberservability::monitoring::{AlertReceiver, AlertReceiverProvision},
|
||||
tenant::{
|
||||
ResourceLimits, TenantConfig, TenantManager, TenantNetworkPolicy, k8s::K8sTenantManager,
|
||||
},
|
||||
@@ -67,6 +68,25 @@ impl K8sAnywhereTopology {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn initialize_alert_receiver<C>(
|
||||
&self,
|
||||
config: &C,
|
||||
inventory: &Inventory,
|
||||
) -> Result<AlertReceiver, InterpretError>
|
||||
where
|
||||
Self: Topology + HelmCommand,
|
||||
C: AlertReceiverProvision<Self> + Send + Sync,
|
||||
{
|
||||
let score = config.get_deployment_score();
|
||||
let interpret = score.create_interpret();
|
||||
interpret.execute(inventory, self).await?;
|
||||
|
||||
Ok(AlertReceiver {
|
||||
receiver_id: config.alert_receiver_id(),
|
||||
receiver_installed: true,
|
||||
})
|
||||
}
|
||||
|
||||
fn is_helm_available(&self) -> Result<(), String> {
|
||||
let version_result = Command::new("helm")
|
||||
.arg("version")
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
use async_trait::async_trait;
|
||||
use dyn_clone::DynClone;
|
||||
use serde::Serialize;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::interpret::InterpretError;
|
||||
|
||||
use crate::inventory::Inventory;
|
||||
use crate::score::Score;
|
||||
use crate::topology::HelmCommand;
|
||||
use crate::{interpret::Outcome, topology::Topology};
|
||||
|
||||
/// Represents an entity responsible for collecting and organizing observability data
|
||||
/// from various telemetry sources
|
||||
/// from various telemetry sources such as Prometheus or Datadog
|
||||
/// A `Monitor` abstracts the logic required to scrape, aggregate, and structure
|
||||
/// monitoring data, enabling consistent processing regardless of the underlying data source.
|
||||
#[async_trait]
|
||||
@@ -26,8 +30,26 @@ pub trait Monitor<T: Topology>: Debug + Send + Sync {
|
||||
) -> Result<Outcome, InterpretError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait EnsureAlertReceiver<T: Topology>: Debug + DynClone + Send + Sync {
|
||||
async fn ensure_alert_receiver(
|
||||
&self,
|
||||
inventory: Inventory,
|
||||
topology: &T,
|
||||
) -> Result<Outcome, InterpretError>;
|
||||
}
|
||||
|
||||
dyn_clone::clone_trait_object!(<T> EnsureAlertReceiver<T>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AlertReceiver {
|
||||
pub receiver_id: String,
|
||||
pub receiver_installed: bool,
|
||||
}
|
||||
|
||||
/// Provides the ability to turn an alert config into an executable score
|
||||
/// for the topology
|
||||
pub trait AlertReceiverProvision<T: Topology + HelmCommand> {
|
||||
fn get_deployment_score(&self) -> Box<dyn Score<T>>;
|
||||
fn alert_receiver_id(&self) -> String;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::discord_alert_manager::discord_alert_manager_score;
|
||||
use async_trait::async_trait;
|
||||
use serde::Serialize;
|
||||
@@ -8,12 +6,12 @@ use tokio::sync::OnceCell;
|
||||
use url::Url;
|
||||
|
||||
use crate::{
|
||||
data::{Id, Version},
|
||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||
interpret::{Interpret, InterpretError, Outcome},
|
||||
inventory::Inventory,
|
||||
score::Score,
|
||||
topology::{
|
||||
HelmCommand, K8sAnywhereTopology, Topology, oberservability::monitoring::AlertReceiver,
|
||||
HelmCommand, K8sAnywhereTopology, Topology,
|
||||
oberservability::monitoring::{AlertReceiverProvision, EnsureAlertReceiver},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -25,9 +23,35 @@ pub struct DiscordWebhookConfig {
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait DiscordWebhookReceiver {
|
||||
async fn deploy_discord_webhook_receiver(
|
||||
impl<T: Topology + DiscordWebhookReceiver> EnsureAlertReceiver<T> for DiscordWebhookConfig {
|
||||
async fn ensure_alert_receiver(
|
||||
&self,
|
||||
inventory: Inventory,
|
||||
topology: &T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
topology
|
||||
.ensure_discord_webhook_receiver(&inventory, self.clone())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Topology + HelmCommand> AlertReceiverProvision<T> for DiscordWebhookConfig {
|
||||
fn get_deployment_score(&self) -> Box<dyn Score<T>> {
|
||||
Box::new(DiscordWebhookReceiverScore {
|
||||
config: self.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
fn alert_receiver_id(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait DiscordWebhookReceiver {
|
||||
async fn ensure_discord_webhook_receiver(
|
||||
&self,
|
||||
inventory: &Inventory,
|
||||
config: DiscordWebhookConfig,
|
||||
) -> Result<Outcome, InterpretError>;
|
||||
fn delete_discord_webhook_receiver(
|
||||
@@ -36,21 +60,11 @@ pub trait DiscordWebhookReceiver {
|
||||
) -> Result<Outcome, InterpretError>;
|
||||
}
|
||||
|
||||
pub trait AlertManagerConfig<T> {
|
||||
fn get_alert_manager_config(&self) -> Result<Value, InterpretError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: DiscordWebhookReceiver> AlertManagerConfig<T> for DiscordWebhookConfig {
|
||||
fn get_alert_manager_config(&self) -> Result<Value, InterpretError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
||||
async fn deploy_discord_webhook_receiver(
|
||||
async fn ensure_discord_webhook_receiver(
|
||||
&self,
|
||||
inventory: &Inventory,
|
||||
config: DiscordWebhookConfig,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
let receiver_key = config.name.clone();
|
||||
@@ -68,9 +82,7 @@ impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
||||
}
|
||||
|
||||
let final_state = cell
|
||||
.get_or_try_init(|| async {
|
||||
initialize_discord_webhook_receiver(config.clone(), self).await
|
||||
})
|
||||
.get_or_try_init(|| async { self.initialize_alert_receiver(&config, inventory).await })
|
||||
.await?;
|
||||
|
||||
Ok(Outcome::success(format!(
|
||||
@@ -87,27 +99,17 @@ impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
||||
}
|
||||
}
|
||||
|
||||
async fn initialize_discord_webhook_receiver(
|
||||
conf: DiscordWebhookConfig,
|
||||
topology: &K8sAnywhereTopology,
|
||||
) -> Result<AlertReceiver, InterpretError> {
|
||||
println!(
|
||||
"Attempting to initialize Discord adapter for: {}",
|
||||
conf.name
|
||||
);
|
||||
let score = DiscordWebhookReceiverScore {
|
||||
config: conf.clone(),
|
||||
};
|
||||
let inventory = Inventory::autoload();
|
||||
let interpret = score.create_interpret();
|
||||
|
||||
interpret.execute(&inventory, topology).await?;
|
||||
|
||||
Ok(AlertReceiver {
|
||||
receiver_id: conf.name,
|
||||
receiver_installed: true,
|
||||
})
|
||||
pub trait AlertManagerConfig<T> {
|
||||
fn get_alert_manager_config(&self) -> Result<Value, InterpretError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: DiscordWebhookReceiver> AlertManagerConfig<T> for DiscordWebhookConfig {
|
||||
fn get_alert_manager_config(&self) -> Result<Value, InterpretError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
struct DiscordWebhookReceiverScore {
|
||||
config: DiscordWebhookConfig,
|
||||
@@ -115,50 +117,15 @@ struct DiscordWebhookReceiverScore {
|
||||
|
||||
impl<T: Topology + HelmCommand> Score<T> for DiscordWebhookReceiverScore {
|
||||
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
||||
Box::new(DiscordWebhookReceiverScoreInterpret {
|
||||
config: self.config.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
"DiscordWebhookReceiverScore".to_string()
|
||||
}
|
||||
}
|
||||
#[derive(Debug)]
|
||||
struct DiscordWebhookReceiverScoreInterpret {
|
||||
config: DiscordWebhookConfig,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: Topology + HelmCommand> Interpret<T> for DiscordWebhookReceiverScoreInterpret {
|
||||
async fn execute(
|
||||
&self,
|
||||
inventory: &Inventory,
|
||||
topology: &T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
discord_alert_manager_score(
|
||||
self.config.webhook_url.clone(),
|
||||
self.config.name.clone(),
|
||||
self.config.name.clone(),
|
||||
)
|
||||
.create_interpret()
|
||||
.execute(inventory, topology)
|
||||
.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!()
|
||||
fn name(&self) -> String {
|
||||
"DiscordWebhookReceiverScore".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user