Skip to main content

metrics_procession/
event.rs

1use serde::{Deserialize, Serialize};
2
3/// A single metrics event represented in the most compact form
4#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
5pub struct Event {
6    /// The type and value of this event
7    pub entry: Entry,
8    /// The number of milliseconds since the owning [`crate::chunk::Chunk`]'s `reference_time`
9    pub ms: u16,
10    /// The label identifier from the owning [`crate::Procession`]'s [`crate::label_set::LabelSet`]
11    pub label: u16,
12}
13
14/// A raw metrics event representing the type and value of what was emitted by the instrumentation
15#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
16pub enum Entry {
17    /// A gauge event
18    Gauge { value: f32, op: Op },
19    /// A counter event
20    Counter { value: u32, op: Op },
21    /// A histogram event
22    Histogram { value: f32 },
23}
24
25/// An [`Entry`]'s operation, used for handling the `increment` and `set` methods
26/// of [`metrics::CounterFn`] and [`metrics::GaugeFn`] or the `decrement` method of a gauge
27#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
28pub enum Op {
29    Add,
30    Sub,
31    Set,
32}