1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crate::metrics::{Descriptor, InstrumentKind};
use crate::sdk::export::metrics::{Aggregator, AggregatorSelector};
use crate::sdk::metrics::aggregators;
use std::sync::Arc;
#[derive(Debug)]
pub enum Selector {
Sketch(aggregators::DdSketchConfig),
Inexpensive,
Exact,
Histogram(Vec<f64>),
}
impl AggregatorSelector for Selector {
fn aggregator_for(&self, descriptor: &Descriptor) -> Option<Arc<dyn Aggregator + Send + Sync>> {
match self {
Selector::Sketch(config) => match descriptor.instrument_kind() {
InstrumentKind::ValueObserver => Some(Arc::new(aggregators::last_value())),
InstrumentKind::ValueRecorder => Some(Arc::new(aggregators::ddsketch(
config,
descriptor.number_kind().clone(),
))),
_ => Some(Arc::new(aggregators::sum())),
},
Selector::Inexpensive => match descriptor.instrument_kind() {
InstrumentKind::ValueObserver => Some(Arc::new(aggregators::last_value())),
InstrumentKind::ValueRecorder => {
Some(Arc::new(aggregators::min_max_sum_count(descriptor)))
}
_ => Some(Arc::new(aggregators::sum())),
},
Selector::Exact => match descriptor.instrument_kind() {
InstrumentKind::ValueObserver => Some(Arc::new(aggregators::last_value())),
InstrumentKind::ValueRecorder => Some(Arc::new(aggregators::array())),
_ => Some(Arc::new(aggregators::sum())),
},
Selector::Histogram(boundaries) => match descriptor.instrument_kind() {
InstrumentKind::ValueObserver => Some(Arc::new(aggregators::last_value())),
InstrumentKind::ValueRecorder => {
Some(Arc::new(aggregators::histogram(descriptor, boundaries)))
}
_ => Some(Arc::new(aggregators::sum())),
},
}
}
}