use super::*;
impl ObservabilityCoverage {
#[must_use]
pub fn reason_value(&self) -> Option<&str> {
let Self { reason, .. } = self;
reason.as_deref()
}
}
impl ObservabilityMetric {
#[must_use]
pub fn measured_common(
id: &str,
scope: &str,
unit: ObservabilityUnit,
window: &str,
statistic: ObservabilityStatistic,
value: f64,
) -> Self {
Self {
id: id.to_string(),
scope: scope.to_string(),
unit,
status: ObservabilityMetricStatus::Measured,
window: window.to_string(),
statistic,
value: Some(value),
baseline: None,
after_drain: None,
slope_per_cycle: None,
samples: None,
source: Some(OBS_SOURCE_EUV_PERF.to_string()),
clock: Some(OBS_CLOCK_MONOTONIC.to_string()),
sample_rate_hz: None,
reason: None,
evidence_refs: Vec::new(),
threshold: None,
}
}
#[must_use]
pub fn measured_leak(
id: &str,
scope: &str,
unit: ObservabilityUnit,
window: &str,
baseline: f64,
after_drain: f64,
slope_per_cycle: f64,
) -> Self {
Self {
id: id.to_string(),
scope: scope.to_string(),
unit,
status: ObservabilityMetricStatus::Measured,
window: window.to_string(),
statistic: ObservabilityStatistic::LiveCount,
value: None,
baseline: Some(baseline),
after_drain: Some(after_drain),
slope_per_cycle: Some(slope_per_cycle),
samples: None,
source: Some(OBS_SOURCE_REACTIVE_ARENA.to_string()),
clock: Some(OBS_CLOCK_MONOTONIC.to_string()),
sample_rate_hz: None,
reason: None,
evidence_refs: Vec::new(),
threshold: None,
}
}
#[must_use]
pub fn with_samples(mut self, samples: u64) -> Self {
let Self { samples: slot, .. } = &mut self;
*slot = Some(samples);
self
}
#[must_use]
pub fn with_threshold(mut self, threshold: ObservabilityThreshold) -> Self {
let Self {
threshold: slot, ..
} = &mut self;
*slot = Some(threshold);
self
}
#[must_use]
pub fn with_evidence_refs(mut self, refs: Vec<String>) -> Self {
let Self { evidence_refs, .. } = &mut self;
*evidence_refs = refs;
self
}
#[must_use]
pub fn scalar_value(&self) -> Option<f64> {
let Self { value, .. } = *self;
value
}
#[must_use]
pub fn baseline_value(&self) -> Option<f64> {
let Self { baseline, .. } = *self;
baseline
}
#[must_use]
pub fn after_drain_value(&self) -> Option<f64> {
let Self { after_drain, .. } = *self;
after_drain
}
#[must_use]
pub fn slope_per_cycle_value(&self) -> Option<f64> {
let Self {
slope_per_cycle, ..
} = *self;
slope_per_cycle
}
#[must_use]
pub fn has_any_numeric_value(&self) -> bool {
let Self {
value,
baseline,
after_drain,
slope_per_cycle,
..
} = *self;
value.is_some() || baseline.is_some() || after_drain.is_some() || slope_per_cycle.is_some()
}
}