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 dyn_clone::DynClone;
|
||||
use serde::Serialize;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::interpret::InterpretError;
|
||||
|
||||
use crate::inventory::Inventory;
|
||||
use crate::{interpret::Outcome, topology::Topology};
|
||||
|
||||
/// 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>;
|
||||
}
|
||||
|
||||
#[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,
|
||||
|
@ -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;
|
||||
@ -13,7 +11,7 @@ use crate::{
|
||||
inventory::Inventory,
|
||||
score::Score,
|
||||
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,
|
||||
}
|
||||
|
||||
#[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]
|
||||
pub trait DiscordWebhookReceiver {
|
||||
async fn deploy_discord_webhook_receiver(
|
||||
async fn ensure_discord_webhook_receiver(
|
||||
&self,
|
||||
inventory: &Inventory,
|
||||
config: DiscordWebhookConfig,
|
||||
) -> Result<Outcome, InterpretError>;
|
||||
fn delete_discord_webhook_receiver(
|
||||
@ -36,21 +42,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();
|
||||
@ -69,7 +65,7 @@ impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
||||
|
||||
let final_state = cell
|
||||
.get_or_try_init(|| async {
|
||||
initialize_discord_webhook_receiver(config.clone(), self).await
|
||||
initialize_discord_webhook_receiver(config.clone(), inventory, self).await
|
||||
})
|
||||
.await?;
|
||||
|
||||
@ -89,6 +85,7 @@ impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
||||
|
||||
async fn initialize_discord_webhook_receiver(
|
||||
conf: DiscordWebhookConfig,
|
||||
inventory: &Inventory,
|
||||
topology: &K8sAnywhereTopology,
|
||||
) -> Result<AlertReceiver, InterpretError> {
|
||||
println!(
|
||||
@ -98,7 +95,6 @@ async fn initialize_discord_webhook_receiver(
|
||||
let score = DiscordWebhookReceiverScore {
|
||||
config: conf.clone(),
|
||||
};
|
||||
let inventory = Inventory::autoload();
|
||||
let interpret = score.create_interpret();
|
||||
|
||||
interpret.execute(&inventory, topology).await?;
|
||||
@ -108,6 +104,18 @@ async fn initialize_discord_webhook_receiver(
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user