Skip to main content

AnomalyMonitor

Struct AnomalyMonitor 

Source
pub struct AnomalyMonitor<K> { /* private fields */ }
Expand description

Composes one or more AnomalyRules into a single observer over a ProtocolEvent stream.

Owns a reusable scratch Vec<Anomaly<K>> so each call to observe / on_tick doesn’t re-allocate when rules emit nothing — the typical case.

Implementations§

Source§

impl<K> AnomalyMonitor<K>

Source

pub fn new() -> Self

Empty monitor — start adding rules via with_rule or add_rule.

Source

pub fn with_rule<R: AnomalyRule<K> + 'static>(self, rule: R) -> Self

Builder-style add — consumes and returns self.

Source

pub fn add_rule<R: AnomalyRule<K> + 'static>(&mut self, rule: R)

In-place add — for cases where the rule set is computed dynamically. The Box<dyn ..> allocation matches the static with_rule form.

Source

pub fn rule_count(&self) -> usize

Number of rules registered.

Source

pub fn rule_names(&self) -> impl Iterator<Item = &'static str> + '_

Rule names in insertion order — useful for logging / metrics setup.

Source

pub fn observe(&mut self, evt: &ProtocolEvent<K>) -> Vec<Anomaly<K>>

Push evt through every registered rule and return any resulting anomalies. The returned Vec is freshly allocated each call so the caller can keep it without fighting the borrow checker; the internal scratch buffer is left empty for the next call.

Source

pub fn on_tick(&mut self, now: Timestamp) -> Vec<Anomaly<K>>

Drive the time-bound part of every rule. Call once per sweep tick (the same cadence as your tokio::time::interval).

Trait Implementations§

Source§

impl<K> Debug for AnomalyMonitor<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K> Default for AnomalyMonitor<K>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K> !RefUnwindSafe for AnomalyMonitor<K>

§

impl<K> !Sync for AnomalyMonitor<K>

§

impl<K> !UnwindSafe for AnomalyMonitor<K>

§

impl<K> Freeze for AnomalyMonitor<K>

§

impl<K> Send for AnomalyMonitor<K>
where K: Send,

§

impl<K> Unpin for AnomalyMonitor<K>
where K: Unpin,

§

impl<K> UnsafeUnpin for AnomalyMonitor<K>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more