fix: modified discordwebhookreceiver to use a generic initialize_alert_receiver function from k8sanywhere topology
This commit is contained in:
parent
dda8e29843
commit
b5b77cf1ac
@ -5,6 +5,7 @@ use inquire::Confirm;
|
|||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use tokio::sync::{Mutex, OnceCell};
|
use tokio::sync::{Mutex, OnceCell};
|
||||||
|
|
||||||
|
use crate::score::Score;
|
||||||
use crate::{
|
use crate::{
|
||||||
executors::ExecutorError,
|
executors::ExecutorError,
|
||||||
interpret::{InterpretError, Outcome},
|
interpret::{InterpretError, Outcome},
|
||||||
@ -17,7 +18,7 @@ use crate::{
|
|||||||
use super::{
|
use super::{
|
||||||
HelmCommand, K8sclient, Topology,
|
HelmCommand, K8sclient, Topology,
|
||||||
k8s::K8sClient,
|
k8s::K8sClient,
|
||||||
oberservability::monitoring::AlertReceiver,
|
oberservability::monitoring::{AlertReceiver, AlertReceiverProvision},
|
||||||
tenant::{
|
tenant::{
|
||||||
ResourceLimits, TenantConfig, TenantManager, TenantNetworkPolicy, k8s::K8sTenantManager,
|
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> {
|
fn is_helm_available(&self) -> Result<(), String> {
|
||||||
let version_result = Command::new("helm")
|
let version_result = Command::new("helm")
|
||||||
.arg("version")
|
.arg("version")
|
||||||
|
@ -7,10 +7,12 @@ use std::fmt::Debug;
|
|||||||
use crate::interpret::InterpretError;
|
use crate::interpret::InterpretError;
|
||||||
|
|
||||||
use crate::inventory::Inventory;
|
use crate::inventory::Inventory;
|
||||||
|
use crate::score::Score;
|
||||||
|
use crate::topology::HelmCommand;
|
||||||
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
|
||||||
/// from various telemetry sources
|
/// from various telemetry sources such as Prometheus or Datadog
|
||||||
/// A `Monitor` abstracts the logic required to scrape, aggregate, and structure
|
/// A `Monitor` abstracts the logic required to scrape, aggregate, and structure
|
||||||
/// monitoring data, enabling consistent processing regardless of the underlying data source.
|
/// monitoring data, enabling consistent processing regardless of the underlying data source.
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@ -44,3 +46,10 @@ pub struct AlertReceiver {
|
|||||||
pub receiver_id: String,
|
pub receiver_id: String,
|
||||||
pub receiver_installed: bool,
|
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;
|
||||||
|
}
|
||||||
|
@ -6,13 +6,12 @@ use tokio::sync::OnceCell;
|
|||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
data::{Id, Version},
|
interpret::{Interpret, InterpretError, Outcome},
|
||||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
score::Score,
|
score::Score,
|
||||||
topology::{
|
topology::{
|
||||||
HelmCommand, K8sAnywhereTopology, Topology,
|
HelmCommand, K8sAnywhereTopology, Topology,
|
||||||
oberservability::monitoring::{AlertReceiver, EnsureAlertReceiver},
|
oberservability::monitoring::{AlertReceiverProvision, EnsureAlertReceiver},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -36,6 +35,18 @@ impl<T: Topology + DiscordWebhookReceiver> EnsureAlertReceiver<T> for DiscordWeb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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]
|
#[async_trait]
|
||||||
pub trait DiscordWebhookReceiver {
|
pub trait DiscordWebhookReceiver {
|
||||||
async fn ensure_discord_webhook_receiver(
|
async fn ensure_discord_webhook_receiver(
|
||||||
@ -71,9 +82,7 @@ impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let final_state = cell
|
let final_state = cell
|
||||||
.get_or_try_init(|| async {
|
.get_or_try_init(|| async { self.initialize_alert_receiver(&config, inventory).await })
|
||||||
initialize_discord_webhook_receiver(config.clone(), inventory, self).await
|
|
||||||
})
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Outcome::success(format!(
|
Ok(Outcome::success(format!(
|
||||||
@ -90,28 +99,6 @@ impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn initialize_discord_webhook_receiver(
|
|
||||||
conf: DiscordWebhookConfig,
|
|
||||||
inventory: &Inventory,
|
|
||||||
topology: &K8sAnywhereTopology,
|
|
||||||
) -> Result<AlertReceiver, InterpretError> {
|
|
||||||
println!(
|
|
||||||
"Attempting to initialize Discord adapter for: {}",
|
|
||||||
conf.name
|
|
||||||
);
|
|
||||||
let score = DiscordWebhookReceiverScore {
|
|
||||||
config: conf.clone(),
|
|
||||||
};
|
|
||||||
let interpret = score.create_interpret();
|
|
||||||
|
|
||||||
interpret.execute(&inventory, topology).await?;
|
|
||||||
|
|
||||||
Ok(AlertReceiver {
|
|
||||||
receiver_id: conf.name,
|
|
||||||
receiver_installed: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait AlertManagerConfig<T> {
|
pub trait AlertManagerConfig<T> {
|
||||||
fn get_alert_manager_config(&self) -> Result<Value, InterpretError>;
|
fn get_alert_manager_config(&self) -> Result<Value, InterpretError>;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user