Browse Source

alerting++

anomly-detector-configurable-iteration-steps-#35
Alexey Velikiy 2 years ago
parent
commit
1bc3ce2037
  1. 6
      server/src/config.rs
  2. 24
      server/src/services/analytic_service/analytic_service.rs
  3. 2
      server/src/services/analytic_service/detection_runner.rs
  4. 2
      server/src/services/analytic_service/types.rs

6
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)]

24
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() {

2
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;
}
}

2
server/src/services/analytic_service/types.rs

@ -96,7 +96,7 @@ pub enum LearningWaiter {
pub struct DetectionRunnerConfig {
// pub sender: mpsc::Sender<Result<Vec<Segment>>>,
pub endpoint: String,
pub from: u64,
// pub from: u64,
pub interval: u64
}

Loading…
Cancel
Save