Skip to main content

cu29_runtime/monitoring/
logstream.rs

1//! Read-only handles for statically wired sender workers. No stream protocol dependency.
2use compact_str::CompactString;
3use cu29_clock::{CuDuration, CuTime};
4use std::sync::Arc;
5
6#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
7pub enum LogStreamFeedbackState {
8    #[default]
9    Waiting,
10    Active,
11    Stale,
12}
13
14#[derive(Clone, Copy, Debug, Default)]
15pub struct LogStreamFeedbackStats {
16    pub state: LogStreamFeedbackState,
17    pub age: Option<CuDuration>,
18    pub failed: bool,
19    pub reports: u64,
20    pub rejected_reports: u64,
21    pub invalid_reports: u64,
22    pub rates_available: bool,
23    pub source_metrics_available: bool,
24    pub bytes_per_second: u64,
25    pub packets_per_second: u64,
26    pub finalized_symbols: u64,
27    pub loss_basis_points: u16,
28    pub recovery_basis_points: u16,
29    pub buffered_records: u32,
30    pub record_capacity: u32,
31    pub latest_copperlist: Option<u64>,
32    pub effective_repair_every_source_symbols: u16,
33    pub invalid_packets: u64,
34    pub duplicate_packets: u64,
35    pub expired_records: u64,
36}
37
38#[derive(Clone, Copy, Debug, Default)]
39pub struct LogStreamStats {
40    pub sampled_at: CuTime,
41    pub packets_sent: u64,
42    pub bytes_sent: u64,
43    pub queue_drops: u64,
44    pub expired_packets: u64,
45    pub transport_drops: u64,
46    pub inbox_drops: u64,
47    pub shutdown_drops: u64,
48    pub recovery_rounds: u64,
49    pub recovery_superseded: u64,
50    pub queue_peak: usize,
51    pub stopped: bool,
52    pub failed: bool,
53    pub feedback: Option<LogStreamFeedbackStats>,
54}
55
56/// Queried only by the monitor's presentation thread, never by task execution.
57pub trait LogStreamStatsSource: core::fmt::Debug + Send + Sync {
58    fn snapshot(&self) -> LogStreamStats;
59}
60
61/// Identity and immutable policy are bound once during generated app construction.
62#[derive(Clone, Debug)]
63pub struct LogStreamMonitor {
64    pub destination: CompactString,
65    pub bitrate_bps: u64,
66    pub baseline_repair_every_source_symbols: usize,
67    source: Arc<dyn LogStreamStatsSource>,
68}
69impl LogStreamMonitor {
70    pub fn new(
71        destination: &str,
72        bitrate_bps: u64,
73        baseline: usize,
74        source: impl LogStreamStatsSource + 'static,
75    ) -> Self {
76        Self {
77            destination: destination.into(),
78            bitrate_bps,
79            baseline_repair_every_source_symbols: baseline,
80            source: Arc::new(source),
81        }
82    }
83    pub fn snapshot(&self) -> LogStreamStats {
84        self.source.snapshot()
85    }
86}