opentelemetry_spanprocessor_any/sdk/export/metrics/aggregation.rs
1//! Metrics SDK Aggregator export API
2use crate::metrics::{Number, Result};
3use std::time::SystemTime;
4
5/// Sum returns an aggregated sum.
6pub trait Sum {
7 /// The sum of the currently aggregated metrics
8 fn sum(&self) -> Result<Number>;
9}
10
11/// Count returns the number of values that were aggregated.
12pub trait Count {
13 /// The count of the currently aggregated metrics
14 fn count(&self) -> Result<u64>;
15}
16
17/// Min returns the minimum value over the set of values that were aggregated.
18pub trait Min {
19 /// The min of the currently aggregated metrics
20 fn min(&self) -> Result<Number>;
21}
22
23/// Max returns the maximum value over the set of values that were aggregated.
24pub trait Max {
25 /// The max of the currently aggregated metrics
26 fn max(&self) -> Result<Number>;
27}
28
29/// LastValue returns the latest value that was aggregated.
30pub trait LastValue {
31 /// The last value of the currently aggregated metrics
32 fn last_value(&self) -> Result<(Number, SystemTime)>;
33}
34
35/// Points return the raw set of values that were aggregated.
36pub trait Points {
37 /// The raw set of points currently aggregated
38 fn points(&self) -> Result<Vec<Number>>;
39}
40
41/// Buckets represent histogram buckets boundaries and counts.
42///
43/// For a Histogram with N defined boundaries, e.g, [x, y, z].
44/// There are N+1 counts: [-inf, x), [x, y), [y, z), [z, +inf]
45#[derive(Debug)]
46pub struct Buckets {
47 /// Boundaries are floating point numbers, even when
48 /// aggregating integers.
49 boundaries: Vec<f64>,
50
51 /// Counts are floating point numbers to account for
52 /// the possibility of sampling which allows for
53 /// non-integer count values.
54 counts: Vec<f64>,
55}
56
57impl Buckets {
58 /// Create new buckets
59 pub fn new(boundaries: Vec<f64>, counts: Vec<f64>) -> Self {
60 Buckets { boundaries, counts }
61 }
62
63 /// Boundaries of the histogram buckets
64 pub fn boundaries(&self) -> &Vec<f64> {
65 &self.boundaries
66 }
67
68 /// Counts of the histogram buckets
69 pub fn counts(&self) -> &Vec<f64> {
70 &self.counts
71 }
72}
73
74/// Histogram returns the count of events in pre-determined buckets.
75pub trait Histogram: Sum + Count {
76 /// Buckets for this histogram.
77 fn histogram(&self) -> Result<Buckets>;
78}
79
80/// MinMaxSumCount supports the Min, Max, Sum, and Count interfaces.
81pub trait MinMaxSumCount: Min + Max + Sum + Count {}