fix:binding with the ensure_ready impementation of K8sAnywhe
This commit is contained in:
parent
cd40660350
commit
ea4709a409
@ -1,10 +1,12 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use dyn_clone::DynClone;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use crate::interpret::InterpretError;
|
use crate::interpret::InterpretError;
|
||||||
|
|
||||||
|
use crate::inventory::Inventory;
|
||||||
use crate::{interpret::Outcome, topology::Topology};
|
use crate::{interpret::Outcome, topology::Topology};
|
||||||
|
|
||||||
/// Represents an entity responsible for collecting and organizing observability data
|
/// Represents an entity responsible for collecting and organizing observability data
|
||||||
@ -26,6 +28,13 @@ pub trait Monitor<T: Topology>: Debug + Send + Sync {
|
|||||||
) -> Result<Outcome, InterpretError>;
|
) -> 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)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct AlertReceiver {
|
pub struct AlertReceiver {
|
||||||
pub receiver_id: String,
|
pub receiver_id: String,
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use super::discord_alert_manager::discord_alert_manager_score;
|
use super::discord_alert_manager::discord_alert_manager_score;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@ -13,7 +11,7 @@ use crate::{
|
|||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
score::Score,
|
score::Score,
|
||||||
topology::{
|
topology::{
|
||||||
HelmCommand, K8sAnywhereTopology, Topology, oberservability::monitoring::AlertReceiver,
|
oberservability::monitoring::{AlertReceiver, EnsureAlertReceiver}, HelmCommand, K8sAnywhereTopology, Topology
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,10 +22,18 @@ pub struct DiscordWebhookConfig {
|
|||||||
pub send_resolved_notifications: bool,
|
pub send_resolved_notifications: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait DiscordWebhookReceiver {
|
pub trait DiscordWebhookReceiver {
|
||||||
async fn deploy_discord_webhook_receiver(
|
async fn ensure_discord_webhook_receiver(
|
||||||
&self,
|
&self,
|
||||||
|
inventory: &Inventory,
|
||||||
config: DiscordWebhookConfig,
|
config: DiscordWebhookConfig,
|
||||||
) -> Result<Outcome, InterpretError>;
|
) -> Result<Outcome, InterpretError>;
|
||||||
fn delete_discord_webhook_receiver(
|
fn delete_discord_webhook_receiver(
|
||||||
@ -36,21 +42,11 @@ pub trait DiscordWebhookReceiver {
|
|||||||
) -> Result<Outcome, InterpretError>;
|
) -> 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]
|
#[async_trait]
|
||||||
impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
||||||
async fn deploy_discord_webhook_receiver(
|
async fn ensure_discord_webhook_receiver(
|
||||||
&self,
|
&self,
|
||||||
|
inventory: &Inventory,
|
||||||
config: DiscordWebhookConfig,
|
config: DiscordWebhookConfig,
|
||||||
) -> Result<Outcome, InterpretError> {
|
) -> Result<Outcome, InterpretError> {
|
||||||
let receiver_key = config.name.clone();
|
let receiver_key = config.name.clone();
|
||||||
@ -69,7 +65,7 @@ impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
|||||||
|
|
||||||
let final_state = cell
|
let final_state = cell
|
||||||
.get_or_try_init(|| async {
|
.get_or_try_init(|| async {
|
||||||
initialize_discord_webhook_receiver(config.clone(), self).await
|
initialize_discord_webhook_receiver(config.clone(), inventory, self).await
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -89,6 +85,7 @@ impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
|||||||
|
|
||||||
async fn initialize_discord_webhook_receiver(
|
async fn initialize_discord_webhook_receiver(
|
||||||
conf: DiscordWebhookConfig,
|
conf: DiscordWebhookConfig,
|
||||||
|
inventory: &Inventory,
|
||||||
topology: &K8sAnywhereTopology,
|
topology: &K8sAnywhereTopology,
|
||||||
) -> Result<AlertReceiver, InterpretError> {
|
) -> Result<AlertReceiver, InterpretError> {
|
||||||
println!(
|
println!(
|
||||||
@ -98,7 +95,6 @@ async fn initialize_discord_webhook_receiver(
|
|||||||
let score = DiscordWebhookReceiverScore {
|
let score = DiscordWebhookReceiverScore {
|
||||||
config: conf.clone(),
|
config: conf.clone(),
|
||||||
};
|
};
|
||||||
let inventory = Inventory::autoload();
|
|
||||||
let interpret = score.create_interpret();
|
let interpret = score.create_interpret();
|
||||||
|
|
||||||
interpret.execute(&inventory, topology).await?;
|
interpret.execute(&inventory, topology).await?;
|
||||||
@ -108,6 +104,18 @@ async fn initialize_discord_webhook_receiver(
|
|||||||
receiver_installed: true,
|
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)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
struct DiscordWebhookReceiverScore {
|
struct DiscordWebhookReceiverScore {
|
||||||
config: DiscordWebhookConfig,
|
config: DiscordWebhookConfig,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user