Skip to main content

kmp_adapter_embedded/adapter/telemetry/
quality_telemetry_retention.rs

1use kmp_domain::PortError;
2
3/// Bounded-journal policy for local quality observations.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub struct QualityTelemetryRetention {
6    max_observations: u64,
7}
8
9impl QualityTelemetryRetention {
10    pub fn new(max_observations: u64) -> Result<Self, PortError> {
11        if max_observations == 0 {
12            return Err(PortError::Unavailable(
13                "quality telemetry retention must keep at least one observation".to_string(),
14            ));
15        }
16        Ok(Self { max_observations })
17    }
18
19    pub fn max_observations(&self) -> u64 {
20        self.max_observations
21    }
22
23    pub fn excess(&self, total: u64) -> u64 {
24        total.saturating_sub(self.max_observations)
25    }
26}
27
28impl Default for QualityTelemetryRetention {
29    fn default() -> Self {
30        Self {
31            max_observations: 100_000,
32        }
33    }
34}