pub struct TrafficShield { /* private fields */ }Expand description
The core resilience monitor that performs real-time diagnostics on Tokio latency and Database roundtrip speeds.
Implementations§
Source§impl TrafficShield
impl TrafficShield
Sourcepub fn new(config: TrafficShieldConfig) -> TrafficShield
pub fn new(config: TrafficShieldConfig) -> TrafficShield
Creates a new inactive TrafficShield.
Call TrafficShield::start from inside a Tokio runtime, attach the
shield to crate::Server, or use backpressure_middleware, which
starts it lazily on its first request. Keeping construction side-effect
free makes this API safe in synchronous setup code and tests.
Sourcepub fn start(&self) -> Result<(), TrafficShieldError>
pub fn start(&self) -> Result<(), TrafficShieldError>
Starts event-loop and optional database monitoring.
The operation is idempotent while running and returns a typed error when
called outside Tokio or after TrafficShield::shutdown. All monitor
tasks are cancelled on explicit shutdown or when the final shield clone
is dropped.
§Errors
Returns TrafficShieldError::RuntimeUnavailable without spawning when
no Tokio runtime is active, or TrafficShieldError::AlreadyShutDown
after the lifecycle has ended.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Stops all background monitors and prevents this shared shield lifecycle from being restarted. Calling this method more than once is harmless.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns whether monitor tasks have been started and not shut down.
Sourcepub fn event_loop_lag(&self) -> Duration
pub fn event_loop_lag(&self) -> Duration
Returns the most recently measured Tokio event-loop lag as a Duration.
Updated every 100ms by the background monitor task.
Sourcepub fn db_latency(&self) -> Duration
pub fn db_latency(&self) -> Duration
Returns the most recently measured database probe round-trip latency as a Duration.
Returns Duration::ZERO if enable_db_probe is false, the orm
feature is disabled, or the pool is uninitialized.
Sourcepub fn active_requests(&self) -> usize
pub fn active_requests(&self) -> usize
Returns the current count of in-flight HTTP requests being tracked by this shield.
Trait Implementations§
Source§impl Clone for TrafficShield
impl Clone for TrafficShield
Source§fn clone(&self) -> TrafficShield
fn clone(&self) -> TrafficShield
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TrafficShield
impl RefUnwindSafe for TrafficShield
impl Send for TrafficShield
impl Sync for TrafficShield
impl Unpin for TrafficShield
impl UnsafeUnpin for TrafficShield
impl UnwindSafe for TrafficShield
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more