relay_event_schema/protocol/
metrics_summary.rs1use relay_protocol::{Annotated, Array, Empty, FromValue, IntoValue, Object};
2
3use crate::processor::ProcessValue;
4
5pub type MetricSummaryMapping = Object<Array<MetricSummary>>;
6
7#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
9pub struct MetricsSummary(pub MetricSummaryMapping);
10
11impl MetricsSummary {
12 pub fn update_value<F: FnOnce(MetricSummaryMapping) -> MetricSummaryMapping>(&mut self, f: F) {
14 self.0 = f(std::mem::take(&mut self.0));
15 }
16}
17
18#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
23pub struct MetricSummary {
24 pub min: Annotated<f64>,
26
27 pub max: Annotated<f64>,
29
30 pub sum: Annotated<f64>,
32
33 pub count: Annotated<u64>,
35
36 pub tags: Annotated<Object<String>>,
38}
39
40impl MetricSummary {
41 pub fn merge(&mut self, other: MetricSummary) {
43 self.min.merge(other.min, |l, r| *l = l.min(r));
44 self.max.merge(other.max, |l, r| *l = l.max(r));
45 self.sum.merge(other.sum, |l, r| *l += r);
46 self.count.merge(other.count, |l, r| *l += r);
47 }
48}