pub struct FlapDetector<T: PartialEq> { /* private fields */ }Expand description
Flapping detector: decaying-penalty counter (BGP-damping style) over an observed value.
record counts a transition whenever the value differs from the last observed one; the
penalty decays with half_life_us and crossing threshold means flapping.
Timestamps are raw microseconds (veilid-tools has no Timestamp type).
Implementations§
Source§impl<T: PartialEq> FlapDetector<T>
impl<T: PartialEq> FlapDetector<T>
Sourcepub fn new(threshold: f64, half_life_us: u64) -> Self
pub fn new(threshold: f64, half_life_us: u64) -> Self
Creates a detector that trips at threshold accumulated penalty, decaying by half every half_life_us.
Sourcepub fn new_secs(threshold: f64, half_life_secs: u64) -> Self
pub fn new_secs(threshold: f64, half_life_secs: u64) -> Self
Convenience: half-life in whole seconds.
Sourcepub fn record(&mut self, now_us: u64, value: T) -> Option<f64>
pub fn record(&mut self, now_us: u64, value: T) -> Option<f64>
Observe a value; counts a transition when it differs from the last. Returns Some(penalty)
only on the transition that tips into flapping (re-arms after decay).
Sourcepub fn record_event(&mut self, now_us: u64) -> Option<f64>
pub fn record_event(&mut self, now_us: u64) -> Option<f64>
Count a discrete flap event (e.g. a connection drop). Returns Some(penalty) only on the
event that tips into flapping (re-arms after decay).
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for FlapDetector<T>where
T: Freeze,
impl<T> RefUnwindSafe for FlapDetector<T>where
T: RefUnwindSafe,
impl<T> Send for FlapDetector<T>where
T: Send,
impl<T> Sync for FlapDetector<T>where
T: Sync,
impl<T> Unpin for FlapDetector<T>where
T: Unpin,
impl<T> UnsafeUnpin for FlapDetector<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for FlapDetector<T>where
T: UnwindSafe,
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,
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