From b2c3330a1d6d5dbe94875743bfd428d36785454e Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Thu, 4 Jun 2026 00:00:00 +0000 Subject: [PATCH 1/4] feat(load/peak_ewma): RttEstimate is `pub` Signed-off-by: katelyn martin --- tower/src/load/peak_ewma.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tower/src/load/peak_ewma.rs b/tower/src/load/peak_ewma.rs index b70d4b6b4..51d00aca5 100644 --- a/tower/src/load/peak_ewma.rs +++ b/tower/src/load/peak_ewma.rs @@ -79,7 +79,7 @@ pub struct Handle { /// Holds the current RTT estimate and the last time this value was updated. #[derive(Debug)] -struct RttEstimate { +pub struct RttEstimate { update_at: Instant, rtt_ns: f64, } From fa0b1228561c08d502101f1fe1454dee3a7ad8b9 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Thu, 4 Jun 2026 00:00:00 +0000 Subject: [PATCH 2/4] feat(load/peak_ewma): RttEstimate is Clone Signed-off-by: katelyn martin --- tower/src/load/peak_ewma.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tower/src/load/peak_ewma.rs b/tower/src/load/peak_ewma.rs index 51d00aca5..a367e0569 100644 --- a/tower/src/load/peak_ewma.rs +++ b/tower/src/load/peak_ewma.rs @@ -78,7 +78,7 @@ pub struct Handle { } /// Holds the current RTT estimate and the last time this value was updated. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct RttEstimate { update_at: Instant, rtt_ns: f64, From 3015e8c1cb825508e61f01e7fb3dedc821034c18 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Thu, 4 Jun 2026 00:00:00 +0000 Subject: [PATCH 3/4] feat(load/peak_ewma): add PeakEwma::rtt_estimate accessor this commit introduces a method to allow the current round-trip time (RTT) estimate of a `PeakEwma` service to be accessed. Signed-off-by: katelyn martin --- tower/src/load/peak_ewma.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tower/src/load/peak_ewma.rs b/tower/src/load/peak_ewma.rs index a367e0569..9ea3d14ba 100644 --- a/tower/src/load/peak_ewma.rs +++ b/tower/src/load/peak_ewma.rs @@ -107,6 +107,18 @@ impl PeakEwma { rtt_estimate: self.rtt_estimate.clone(), } } + + /// Returns the current [`RttEstimate`] of the service. + /// + /// # Panics + /// + /// This value is stored in a mutex. If the mutex has become poisoned, this will panic. + pub fn rtt_estimate(&self) -> RttEstimate { + self.rtt_estimate + .lock() + .expect("mutex should not be poisoned") + .clone() + } } impl Service for PeakEwma From 708248a86a9ce8d25ed70c22cc19f47c14e9db52 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Thu, 4 Jun 2026 00:00:00 +0000 Subject: [PATCH 4/4] feat(load/peak_ewma): add RttEstimate::{updated_at, rtt_ns} Signed-off-by: katelyn martin --- tower/src/load/peak_ewma.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tower/src/load/peak_ewma.rs b/tower/src/load/peak_ewma.rs index 9ea3d14ba..2017f9c4f 100644 --- a/tower/src/load/peak_ewma.rs +++ b/tower/src/load/peak_ewma.rs @@ -228,6 +228,16 @@ where // ===== impl RttEstimate ===== impl RttEstimate { + /// Returns the [`Instant`] that this estimate was last updated. + pub fn updated_at(&self) -> Instant { + self.update_at + } + + /// Returns the round-trip time estimate, in nanoseconds. + pub fn rtt_ns(&self) -> f64 { + self.rtt_ns + } + fn new(rtt_ns: f64) -> Self { debug_assert!(0.0 < rtt_ns, "rtt must be positive"); Self {