Browse Source

patch config continue

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
0c6d0328a3
  1. 7
      server/src/api/analytics.rs
  2. 5
      server/src/services/analytic_service/analytic_client.rs
  3. 11
      server/src/services/analytic_service/analytic_service.rs
  4. 9
      server/src/services/analytic_service/analytic_unit/types.rs
  5. 4
      server/src/services/analytic_service/types.rs

7
server/src/api/analytics.rs

@ -78,6 +78,7 @@ pub mod filters {
mod handlers {
use hastic::services::analytic_service::analytic_unit::types::PatchConfig;
use serde_json::Value;
use super::models::{Client, ListOptions, Status};
@ -117,10 +118,10 @@ mod handlers {
}
}
pub async fn patch_config(client: Client, obj: Value) -> Result<impl warp::Reply, warp::Rejection> {
pub async fn patch_config(client: Client, patch: PatchConfig) -> Result<impl warp::Reply, warp::Rejection> {
// println!("{:?}", obj);
match client.get_config().await {
println!("{:?}", patch);
match client.patch_config(patch).await {
Ok(cf) => Ok(API::json(&cf)),
Err(e) => {
println!("{:?}", e);

5
server/src/services/analytic_service/analytic_client.rs

@ -5,6 +5,7 @@ use tokio::sync::oneshot;
use crate::services::segments_service::Segment;
use super::analytic_unit::types::AnalyticUnitConfig;
use super::analytic_unit::types::PatchConfig;
use super::types::DetectionTask;
use super::types::LearningStatus;
use super::types::LearningTrain;
@ -44,9 +45,9 @@ impl AnalyticClient {
Ok(r)
}
pub async fn patch_config(&self, patch_obj: Value) -> anyhow::Result<()> {
pub async fn patch_config(&self, patch: PatchConfig) -> anyhow::Result<()> {
let (tx, rx) = oneshot::channel();
let req = AnalyticServiceMessage::Request(RequestType::PatchConfig(patch_obj, tx));
let req = AnalyticServiceMessage::Request(RequestType::PatchConfig(patch, tx));
self.tx.send(req).await?;
rx.await?;
Ok(())

11
server/src/services/analytic_service/analytic_service.rs

@ -1,6 +1,6 @@
use std::sync::Arc;
use super::analytic_unit::types::{AnalyticUnitConfig, PatternConfig};
use super::analytic_unit::types::{AnalyticUnitConfig, PatternConfig, PatchConfig};
use super::types::{self, DetectionRunnerConfig, LearningTrain};
use super::{
analytic_client::AnalyticClient,
@ -19,10 +19,13 @@ use crate::services::analytic_service::analytic_unit::types::{AnalyticUnit, Lear
use anyhow;
use serde_json::Value;
use tokio::sync::{mpsc, oneshot, RwLock};
use chrono::Utc;
// TODO: now it's basically single analytic unit, service will operate on many AU
pub struct AnalyticService {
metric_service: MetricService,
@ -172,6 +175,7 @@ impl AnalyticService {
RequestType::PatchConfig(patch_obj, tx) => {
// TODO: path config
// TODO: run learning if config type changed
self.patch_config(patch_obj);
tx.send(()).unwrap();
}
};
@ -215,6 +219,11 @@ impl AnalyticService {
}
}
fn patch_config(&mut self, mut patch: PatchConfig) {
// let r = patch.take();
println!("{:?}", patch);
}
pub async fn serve(&mut self) {
// TODO: remove this hack
self.consume_request(RequestType::RunLearning);

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

@ -6,6 +6,8 @@ use crate::services::{
analytic_service::types, metric_service::MetricService, segments_service::SegmentsService,
};
use super::threshold_analytic_unit::ThresholdAnalyticUnit;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PatternConfig {
pub correlation_score: f32,
@ -44,3 +46,10 @@ pub trait AnalyticUnit {
to: u64,
) -> anyhow::Result<Vec<(u64, u64)>>;
}
#[derive(Deserialize, Serialize, Debug)]
pub enum PatchConfig {
Pattern(bool),
Threshold(bool),
Anomaly(bool)
}

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

@ -7,6 +7,8 @@ use super::analytic_unit::{
types::AnalyticUnitConfig,
};
use super::analytic_unit::types::{PatchConfig};
use anyhow::Result;
use serde::Serialize;
use serde_json::Value;
@ -74,7 +76,7 @@ pub enum RequestType {
RunDetection(DetectionTask),
GetStatus(oneshot::Sender<LearningStatus>),
// TODO: make type of Value
PatchConfig(Value, oneshot::Sender<()>),
PatchConfig(PatchConfig, oneshot::Sender<()>),
GetConfig(oneshot::Sender<AnalyticUnitConfig>),
// GetLearningTrain(oneshot::Sender<LearningTrain>),
}

Loading…
Cancel
Save