Skip to main content

laminar_connectors/
metrics.rs

1/// Metrics snapshot returned from a connector's `metrics()` method.
2#[derive(Debug, Clone, Default)]
3pub struct ConnectorMetrics {
4    /// Total number of records processed.
5    pub records_total: u64,
6
7    /// Total bytes processed.
8    pub bytes_total: u64,
9
10    /// Number of errors encountered.
11    pub errors_total: u64,
12
13    /// Current lag (records behind for sources, pending for sinks).
14    pub lag: u64,
15
16    /// Additional connector-specific metrics.
17    pub custom: Vec<(String, f64)>,
18}
19
20impl ConnectorMetrics {
21    /// Creates empty metrics.
22    #[must_use]
23    pub fn new() -> Self {
24        Self::default()
25    }
26
27    /// Adds a custom metric.
28    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}