refactor(stats): make late-reply sampling explicit
The TUI suppressed late-reply timing by rebuilding the event with sent_at, rtt, server_timing, one_way and received_stats erased. That leaked stats policy into event construction and, as a side effect, reclassified a matched late reply as an untracked late reply. StatsConfig now carries an explicit LateReplyMode. Measure keeps today's behavior for every existing caller. CountOnly keeps the reply a late unique reply and keeps packet, byte and late counters updating, while suppressing timing, one-way, server-processing and IPDV contributions and reporting contributed_sample == false. Cumulative and rolling snapshots share the policy. Genuinely untracked late replies stay untracked in both modes. The TUI selects CountOnly and passes the original event straight to the collector.
This commit is contained in:
1 parent
90c04b6569
commit
e0dec9ac5f
5 files changed
+223
-49
No files matched your search
@@ -5,8 +5,8 @@ use crate::loss::loss_stats;
|
||||
use crate::normalization::{ReplySample, StatsEvent};
|
||||
use crate::time_stats::TimeMetric;
|
||||
use crate::{
|
||||
EventCounts, EventStatsUpdate, IpdvPairUpdate, IpdvStats, OneWayDelayStats, PacketCounts,
|
||||
RttStats, SampleMode, ServerProcessingStats, Snapshot,
|
||||
EventCounts, EventStatsUpdate, IpdvPairUpdate, IpdvStats, LateReplyMode, OneWayDelayStats,
|
||||
PacketCounts, RttStats, SampleMode, ServerProcessingStats, Snapshot,
|
||||
};
|
||||
|
||||
const CONTINUOUS_SEQUENCE_LIMIT: usize = 4096;
|
||||
@@ -27,10 +27,11 @@ pub(crate) struct CoreStats {
|
||||
receive_delay: TimeMetric,
|
||||
server_processing: TimeMetric,
|
||||
ipdv_tracker: IpdvTracker,
|
||||
late_replies: LateReplyMode,
|
||||
}
|
||||
|
||||
impl CoreStats {
|
||||
pub(crate) fn new(sample_mode: SampleMode) -> Self {
|
||||
pub(crate) fn new(sample_mode: SampleMode, late_replies: LateReplyMode) -> Self {
|
||||
let sequence_limit = if sample_mode == SampleMode::Exact {
|
||||
None
|
||||
} else {
|
||||
@@ -52,6 +53,7 @@ impl CoreStats {
|
||||
receive_delay: TimeMetric::new(sample_mode == SampleMode::Exact),
|
||||
server_processing: TimeMetric::new(false),
|
||||
ipdv_tracker: IpdvTracker::new(sequence_limit),
|
||||
late_replies,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,12 +99,19 @@ impl CoreStats {
|
||||
}
|
||||
|
||||
fn apply_unique_reply(&mut self, is_late: bool, sample: ReplySample) -> EventStatsUpdate {
|
||||
self.account_unique_reply(is_late, &sample);
|
||||
|
||||
// A matched late reply is always a late unique reply. Whether it is
|
||||
// also allowed to measure is the configured policy, not a property of
|
||||
// the event.
|
||||
if is_late && self.late_replies == LateReplyMode::CountOnly {
|
||||
return EventStatsUpdate::default();
|
||||
}
|
||||
|
||||
let mut update = EventStatsUpdate {
|
||||
contributed_sample: true,
|
||||
..EventStatsUpdate::default()
|
||||
};
|
||||
|
||||
self.account_unique_reply(is_late, &sample);
|
||||
self.record_reply_metrics(&sample);
|
||||
update.ipdv_pairs = self.apply_ipdv_sample(sample.ipdv);
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ pub struct StatsConfig {
|
||||
pub rolling_count: Option<usize>,
|
||||
/// Time span of recent normalized events retained for time-based rolling snapshots.
|
||||
pub rolling_time: Option<Duration>,
|
||||
/// Whether matched late replies contribute measurements.
|
||||
pub late_replies: LateReplyMode,
|
||||
}
|
||||
|
||||
impl StatsConfig {
|
||||
@@ -49,6 +51,7 @@ impl StatsConfig {
|
||||
samples: SampleMode::Exact,
|
||||
rolling_count: None,
|
||||
rolling_time: None,
|
||||
late_replies: LateReplyMode::Measure,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,10 +65,34 @@ impl StatsConfig {
|
||||
samples: SampleMode::RunningOnly,
|
||||
rolling_count: None,
|
||||
rolling_time: None,
|
||||
late_replies: LateReplyMode::Measure,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
/// Whether a matched late reply contributes measurements.
|
||||
///
|
||||
/// This is a measurement policy, not a classification. A late reply that the
|
||||
/// client matched to retained send state is a late unique reply in both modes,
|
||||
/// and a late reply that could not be matched remains an untracked late reply
|
||||
/// in both modes. Only what a matched late reply is allowed to measure differs,
|
||||
/// so a caller that treats late replies as diagnostics does not have to degrade
|
||||
/// the event itself to suppress its timing contribution.
|
||||
pub enum LateReplyMode {
|
||||
/// Matched late replies contribute timing, one-way, server-processing, and
|
||||
/// IPDV measurements like any other unique reply.
|
||||
#[default]
|
||||
Measure,
|
||||
/// Matched late replies are counted but measure nothing.
|
||||
///
|
||||
/// Packet, byte, late, and server-reported receive counters still update,
|
||||
/// so the reply stays visible as a late unique reply. Timing metrics,
|
||||
/// one-way and server-processing measurements, and IPDV do not update, and
|
||||
/// [`EventStatsUpdate::contributed_sample`] is `false`.
|
||||
CountOnly,
|
||||
}
|
||||
|
||||
impl Default for StatsConfig {
|
||||
fn default() -> Self {
|
||||
Self::finite()
|
||||
@@ -95,7 +122,7 @@ impl StatsCollector {
|
||||
/// Creates a collector with the supplied configuration.
|
||||
pub fn new(config: StatsConfig) -> Self {
|
||||
Self {
|
||||
cumulative: CoreStats::new(config.samples),
|
||||
cumulative: CoreStats::new(config.samples, config.late_replies),
|
||||
rolling: RollingEvents::new(config),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use std::{collections::VecDeque, time::Duration};
|
||||
|
||||
use crate::{core::CoreStats, normalization::StatsEvent, SampleMode, Snapshot, StatsConfig};
|
||||
use crate::{
|
||||
core::CoreStats, normalization::StatsEvent, LateReplyMode, SampleMode, Snapshot, StatsConfig,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) struct RollingEvents {
|
||||
@@ -8,6 +10,7 @@ pub(crate) struct RollingEvents {
|
||||
time_limit: Option<Duration>,
|
||||
count_events: Option<VecDeque<StatsEvent>>,
|
||||
time_events: Option<VecDeque<StatsEvent>>,
|
||||
late_replies: LateReplyMode,
|
||||
}
|
||||
|
||||
impl RollingEvents {
|
||||
@@ -17,6 +20,7 @@ impl RollingEvents {
|
||||
time_limit: config.rolling_time,
|
||||
count_events: config.rolling_count.map(|_| VecDeque::new()),
|
||||
time_events: config.rolling_time.map(|_| VecDeque::new()),
|
||||
late_replies: config.late_replies,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,16 +44,22 @@ impl RollingEvents {
|
||||
}
|
||||
|
||||
pub(crate) fn count_snapshot(&self) -> Option<Snapshot> {
|
||||
self.count_events.as_ref().map(snapshot_window)
|
||||
self.count_events
|
||||
.as_ref()
|
||||
.map(|events| snapshot_window(events, self.late_replies))
|
||||
}
|
||||
|
||||
pub(crate) fn time_snapshot(&self) -> Option<Snapshot> {
|
||||
self.time_events.as_ref().map(snapshot_window)
|
||||
self.time_events
|
||||
.as_ref()
|
||||
.map(|events| snapshot_window(events, self.late_replies))
|
||||
}
|
||||
}
|
||||
|
||||
fn snapshot_window(events: &VecDeque<StatsEvent>) -> Snapshot {
|
||||
let mut core = CoreStats::new(SampleMode::RunningOnly);
|
||||
/// Recompute a window snapshot under the same normalized semantics as the
|
||||
/// cumulative collector, including its late-reply measurement policy.
|
||||
fn snapshot_window(events: &VecDeque<StatsEvent>, late_replies: LateReplyMode) -> Snapshot {
|
||||
let mut core = CoreStats::new(SampleMode::RunningOnly, late_replies);
|
||||
for event in events {
|
||||
core.apply(event.clone());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user