Hastic standalone https://hastic.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 lines
1.4 KiB

use subbeat::metric::{Metric, MetricResult};
pub struct MetricService {
datasource: Box<dyn Metric + Sync + Send>,
}
impl Clone for MetricService {
fn clone(&self) -> Self {
return MetricService {
datasource: self.datasource.boxed_clone(),
};
}
}
impl MetricService {
pub fn new(ds_config: &subbeat::types::DatasourceConfig) -> MetricService {
MetricService {
datasource: subbeat::datasources::resolve(ds_config),
}
}
pub async fn query(&self, from: u64, to: u64, step: u64) -> anyhow::Result<MetricResult> {
let mut mr = self.datasource.query(from, to, step).await?;
// let keys: Vec<_> = mr.data.keys().into_iter().collect();
if mr.data.keys().len() > 0 {
// TODO: it's a hack, should replace all metrics
let key = mr.data.keys().nth(0).unwrap().clone();
let ts = mr.data.get_mut(&key).unwrap();
// TODO: make interpolate_nans_and_gaps_with_zeros configurable
*ts = subbeat::utils::interpolate_nans_and_gaps_with_zeros(&ts, from, to, step);
// mr.data.insert(*k, ts_interpolated);
}
return Ok(mr);
}
// TODO: it a hack for DetectionRunner: it should vary for different analytic units
// and it's config
pub fn get_detection_step(&self) -> u64 {
return 10;
}
}