pub struct RiskState { /* private fields */ }Expand description
The in-memory accumulator, owned single-threaded by the sink task (shared
behind an RwLock so GET /api/v1/risk can read it).
Implementations§
Source§impl RiskState
impl RiskState
Sourcepub fn total_entries(&self) -> usize
pub fn total_entries(&self) -> usize
Total retained contributions across all entities (for the state gauge).
Sourcepub fn record(
&mut self,
cfg: &IncidentConfig,
entity_type: &str,
entity_value: &str,
contribution: Contribution,
now: i64,
) -> RecordOutcome
pub fn record( &mut self, cfg: &IncidentConfig, entity_type: &str, entity_value: &str, contribution: Contribution, now: i64, ) -> RecordOutcome
Record a contribution for an entity, returning an incident when a threshold is crossed outside the cooldown.
Sourcepub fn tick(&mut self, cfg: &IncidentConfig, now: i64) -> usize
pub fn tick(&mut self, cfg: &IncidentConfig, now: i64) -> usize
Prune entities whose windows have fully aged out at now, returning the
number removed (for eviction accounting).
Sourcepub fn snapshot(&self) -> RiskStateSnapshot
pub fn snapshot(&self) -> RiskStateSnapshot
Capture the accumulator into a versioned persistence snapshot.
Sourcepub fn restore(
&mut self,
snap: RiskStateSnapshot,
window_secs: i64,
max_open_entities: usize,
now: i64,
) -> bool
pub fn restore( &mut self, snap: RiskStateSnapshot, window_secs: i64, max_open_entities: usize, now: i64, ) -> bool
Restore a snapshot, dropping contributions already past the window at
now, skipping entities left empty, and honoring max_open_entities so a
restore cannot load more entities than the live cap allows. Returns
false on a version mismatch (the caller starts fresh).
Sourcepub fn views(&self, cfg: &IncidentConfig, now: i64) -> Vec<RiskEntityView>
pub fn views(&self, cfg: &IncidentConfig, now: i64) -> Vec<RiskEntityView>
A read-only view of every open entity at now, for the admin API.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RiskState
impl RefUnwindSafe for RiskState
impl Send for RiskState
impl Sync for RiskState
impl Unpin for RiskState
impl UnsafeUnpin for RiskState
impl UnwindSafe for RiskState
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt for T
Source§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind referenceSource§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable referenceSource§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointerSource§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointerSource§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
Source§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
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