Browse Source

detections window begin

pull/63/head
Alexey Velikiy 2 years ago
parent
commit
0761e4d9b2
  1. 4
      server/src/services/analytic_service/analytic_unit/anomaly_analytic_unit.rs
  2. 4
      server/src/services/analytic_service/analytic_unit/pattern_analytic_unit.rs
  3. 3
      server/src/services/analytic_service/analytic_unit/threshold_analytic_unit.rs
  4. 1
      server/src/services/analytic_service/analytic_unit/types.rs
  5. 8
      server/src/services/analytic_service/detection_runner.rs

4
server/src/services/analytic_service/analytic_unit/anomaly_analytic_unit.rs

@ -164,6 +164,10 @@ impl AnalyticUnit for AnomalyAnalyticUnit {
fn get_id(&self) -> String {
return self.id.to_owned();
}
fn get_detection_window(&self) -> u64 {
// TODO: return window based on real petterns info
return DETECTION_STEP;
}
fn set_config(&mut self, config: AnalyticUnitConfig) {
if let AnalyticUnitConfig::Anomaly(cfg) = config {
self.config = cfg;

4
server/src/services/analytic_service/analytic_unit/pattern_analytic_unit.rs

@ -219,6 +219,10 @@ impl AnalyticUnit for PatternAnalyticUnit {
fn get_id(&self) -> String {
return self.id.to_owned();
}
fn get_detection_window(&self) -> u64 {
// TODO: return window based on real petterns info
return DETECTION_STEP;
}
fn set_config(&mut self, config: AnalyticUnitConfig) {
if let AnalyticUnitConfig::Pattern(cfg) = config {
self.config = cfg;

3
server/src/services/analytic_service/analytic_unit/threshold_analytic_unit.rs

@ -25,6 +25,9 @@ impl AnalyticUnit for ThresholdAnalyticUnit {
fn get_id(&self) -> String {
return self.id.to_owned();
}
fn get_detection_window(&self) -> u64 {
return DETECTION_STEP;
}
async fn learn(
&mut self,
_ms: MetricService,

1
server/src/services/analytic_service/analytic_unit/types.rs

@ -131,6 +131,7 @@ pub enum LearningResult {
#[async_trait]
pub trait AnalyticUnit {
fn get_id(&self) -> String;
fn get_detection_window(&self) -> u64;
async fn learn(
&mut self,
ms: MetricService,

8
server/src/services/analytic_service/detection_runner.rs

@ -1,10 +1,14 @@
use chrono::{Utc, DateTime};
use tokio::sync::{mpsc, RwLock};
use tokio::sync::{mpsc};
use super::types::{AnalyticServiceMessage, AnalyticUnitRF, DetectionRunnerConfig, ResponseType};
use tokio::time::{sleep, Duration};
const DETECTION_STEP: u64 = 10;
pub struct DetectionRunner {
tx: mpsc::Sender<AnalyticServiceMessage>,
config: DetectionRunnerConfig,
@ -41,7 +45,6 @@ impl DetectionRunner {
// TODO: run detection "from" for big timespan
// TODO: parse detections to webhooks
// TODO: define window for detection
// TODO: save last detection
// TODO: handle case when detection is in the end and continues after "now"
match tx
@ -60,6 +63,7 @@ impl DetectionRunner {
let to = now.timestamp() as u64;
// TODO: run detection periodically
sleep(Duration::from_secs(cfg.interval)).await;
// TODO: update from / to based on detection step
match tx.send(AnalyticServiceMessage::Response(Ok(
ResponseType::DetectionRunnerUpdate(au.as_ref().read().await.get_id(), to)
))).await {

Loading…
Cancel
Save