laminar_connectors/
metrics.rs1#[derive(Debug, Clone, Default)]
3pub struct ConnectorMetrics {
4 pub records_total: u64,
6
7 pub bytes_total: u64,
9
10 pub errors_total: u64,
12
13 pub lag: u64,
15
16 pub custom: Vec<(String, f64)>,
18}
19
20impl ConnectorMetrics {
21 #[must_use]
23 pub fn new() -> Self {
24 Self::default()
25 }
26
27 pub fn add_custom(&mut self, name: impl Into<String>, value: f64) {
29 self.custom.push((name.into(), value));
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn test_connector_metrics() {
39 let mut metrics = ConnectorMetrics::new();
40 metrics.records_total = 1000;
41 metrics.bytes_total = 50_000;
42 metrics.add_custom("kafka.lag", 42.0);
43
44 assert_eq!(metrics.records_total, 1000);
45 assert_eq!(metrics.custom.len(), 1);
46 assert_eq!(metrics.custom[0].0, "kafka.lag");
47 }
48}