diff --git a/server/src/config.rs b/server/src/config.rs index f7110ae..3ff9744 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -2,7 +2,7 @@ use subbeat::types::{DatasourceConfig, InfluxConfig, PrometheusConfig}; #[derive(Clone)] pub struct WebhookAlertingConfig { - endpoint: String, + pub endpoint: String, } #[derive(Clone)] @@ -12,8 +12,8 @@ pub enum AlertingType { #[derive(Clone)] pub struct AlertingConfig { - alerting_type: AlertingType, - interval: u64, // interval in seconds + pub alerting_type: AlertingType, + pub interval: u64, // interval in seconds } #[derive(Clone)] diff --git a/server/src/services/analytic_service/analytic_service.rs b/server/src/services/analytic_service/analytic_service.rs index d657b82..963e8e7 100644 --- a/server/src/services/analytic_service/analytic_service.rs +++ b/server/src/services/analytic_service/analytic_service.rs @@ -8,7 +8,7 @@ use super::{ types::{AnalyticServiceMessage, LearningStatus, RequestType, ResponseType}, }; -use crate::config::AlertingConfig; +use crate::config::{AlertingConfig, AlertingType}; use crate::services::analytic_service::analytic_unit::resolve; use crate::services::{ metric_service::MetricService, @@ -102,6 +102,28 @@ impl AnalyticService { } fn run_detection_runner(&mut self) { + // TODO: handle case or make it impossible to run_detection_runner second time + + if self.analytic_unit.is_none() { + return; + } + + if self.analytic_unit_learning_status != LearningStatus::Ready { + // TODO: add to waiter + return; + } + + let AlertingType::Webhook(acfg) = self.alerting.as_ref().unwrap().alerting_type.clone(); + let drcfg = DetectionRunnerConfig { + endpoint: acfg.endpoint.clone(), + interval: self.alerting.as_ref().unwrap().interval + }; + + let dr = DetectionRunner::new(drcfg, self.analytic_unit.as_ref().unwrap().clone()); + self.detection_runner = Some(dr); + // dr.run(); + + // TODO: create DetectionRunnerConfig from alerting // TODO: rerun detection runner on analytic unit change // if self.runner_handler.is_some() { diff --git a/server/src/services/analytic_service/detection_runner.rs b/server/src/services/analytic_service/detection_runner.rs index 7df983d..a25801d 100644 --- a/server/src/services/analytic_service/detection_runner.rs +++ b/server/src/services/analytic_service/detection_runner.rs @@ -40,8 +40,6 @@ impl DetectionRunner { loop { // TODO: run detection periodically - // TODO: use interval - // TODO: sell to config sleep(Duration::from_secs(cfg.interval)).await; } } diff --git a/server/src/services/analytic_service/types.rs b/server/src/services/analytic_service/types.rs index 7c3c7a9..2b702a9 100644 --- a/server/src/services/analytic_service/types.rs +++ b/server/src/services/analytic_service/types.rs @@ -96,7 +96,7 @@ pub enum LearningWaiter { pub struct DetectionRunnerConfig { // pub sender: mpsc::Sender>>, pub endpoint: String, - pub from: u64, + // pub from: u64, pub interval: u64 }