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
use crate::flow::core::{Flow, TimedEvent};
use crate::io::provider::{StreamType, Timestamp};
use crate::range::Range;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GaugeState {
pub range: Range,
pub timestamp: Option<Timestamp>,
pub value: f64,
}
impl GaugeState {
pub fn new(range: Range) -> Self {
Self {
range,
timestamp: None,
value: 0.0,
}
}
pub fn last(&self) -> Option<TimedEvent<f64>> {
self.timestamp.map(|ts| TimedEvent {
timestamp: ts,
event: self.value,
})
}
}
impl Flow for GaugeState {
type Action = ();
type Event = GaugeEvent;
fn stream_type() -> StreamType {
StreamType::from("rillrate.data.gauge.v0")
}
fn apply(&mut self, event: TimedEvent<Self::Event>) {
match event.event {
GaugeEvent::Set(delta) => {
self.timestamp = Some(event.timestamp);
self.value = delta;
}
}
}
}
pub type GaugeDelta = Vec<TimedEvent<GaugeEvent>>;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum GaugeEvent {
Set(f64),
}