use std::time::Duration;
use auto_impl::auto_impl;
use crate::stat_types::BoxHistogram;
use crate::stat_types::BoxLocalCounter;
use crate::stat_types::BoxLocalHistogram;
use crate::stat_types::BoxLocalTimeseries;
pub trait StatsManagerFactory {
fn create(&self) -> BoxStatsManager;
}
pub type BoxStatsManager = Box<dyn StatsManager + Send + Sync>;
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum AggregationType {
Sum,
Count,
Average,
Rate,
Percent,
}
pub struct BucketConfig {
pub width: u32,
pub min: u32,
pub max: u32,
}
#[auto_impl(Box)]
pub trait StatsManager {
fn aggregate(&self);
fn create_counter(&self, name: &str) -> BoxLocalCounter;
fn create_timeseries(
&self,
name: &str,
aggregation_types: &[AggregationType],
intervals: &[Duration],
) -> BoxLocalTimeseries;
fn create_histogram(
&self,
name: &str,
aggregation_types: &[AggregationType],
conf: BucketConfig,
percentiles: &[u8],
) -> BoxLocalHistogram;
fn create_quantile_stat(
&self,
name: &str,
aggregation_types: &[AggregationType],
percentiles: &[f32],
intervals: &[Duration],
) -> BoxHistogram;
}