refactor(client): centralize managed target accounting

Target-local accounting was spread across the managed driver: the event
counter increments were inline in publish_client_events, the authoritative
packets_sent was copied from the client at fifteen separate call sites, and
ManagedTargetOutcome was constructed twice from the same six fields.

TargetCounters::observe now owns the per-event accounting,
TargetRuntime::sync_packets_sent/record_packets_sent own the authoritative
sent count, and TargetRuntime::outcome owns outcome construction, replacing
the free target_outcome function and the inline copy in finish_target. No
counter is touched outside TargetRuntime any more.

The replies_received semantics are unchanged and now documented on both the
private counter and the public outcome field: on-time unique echo replies
only, with late unique replies counted by late. observe matches ClientEvent
exhaustively, so a new event variant must be classified deliberately.
This commit is contained in:
Nils Andreas Svee committed 2026-08-15 01:36:04 +07:00
1 parent 90c04b6569
commit 5506220f67
3 files changed
+209 -71

No files matched your search

+12
View File
@@ -198,16 +198,28 @@ pub enum ManagedEndReason {
}
/// Durable outcome for one target generation.
///
/// These counters are durable: unlike [`ManagedEvent`], which is a lossy
/// presentation stream, they account for everything the target observed.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ManagedTargetOutcome {
pub target: TargetInstance,
pub server_addr: Arc<str>,
pub remote: Option<SocketAddr>,
pub end_reason: ManagedTargetEndReason,
/// Probes the underlying client reported as sent.
pub packets_sent: u64,
/// On-time unique echo replies.
///
/// A unique reply that arrived after its probe timed out is counted by
/// `late` instead, so this is the count of replies that arrived in time.
pub replies_received: u64,
/// Replies for a sequence that had already been answered.
pub duplicates: u64,
/// Replies that arrived after their probe timed out, whether or not the
/// client could still match them to retained send state.
pub late: u64,
/// Warning events observed for this target.
pub warning_events: u64,
pub cleanup_failure: Option<ManagedTargetFailure>,
}