pub struct FieldObserver { /* private fields */ }Expand description
Capped, opt-in field-name counter shared across producers (the daemon’s event task, the eval streaming loop) and consumers (the daemon’s HTTP handlers, the eval report writer).
Implementations§
Source§impl FieldObserver
impl FieldObserver
Sourcepub fn new(max_keys: usize) -> FieldObserver
pub fn new(max_keys: usize) -> FieldObserver
Create a new observer with the given upper bound on distinct keys.
A max_keys of 0 is allowed and disables tracking entirely; every
observed field counts as overflow. Callers wanting “no cap” should
pick a large finite number (e.g. usize::MAX / 2).
Sourcepub fn observe<E>(&self, event: &E)
pub fn observe<E>(&self, event: &E)
Walk the event’s field keys and update the per-field counters.
Insertion of a new key is skipped once the observer is at capacity;
already-tracked keys keep counting. The method takes &self, so
the observer can be shared behind an Arc without locking from
the caller’s side.
Sourcepub fn snapshot(&self) -> FieldObservation
pub fn snapshot(&self) -> FieldObservation
Snapshot the current counts. Entries are sorted by descending count, then by ascending name for deterministic output.
Cheap relative to the cardinality of the observer: each entry
only refcount-clones the Arc<str> key rather than copying the
key bytes, so a 10 000-key snapshot costs ~10 000 atomic
increments plus one Vec allocation, not 10 000 String
allocations.
Sourcepub fn reset(&self) -> (usize, u64)
pub fn reset(&self) -> (usize, u64)
Reset every counter and the overflow tally. Returns the previous
(unique_keys, events_observed) pair so the API endpoint can
report what was cleared.
Sourcepub fn events_observed(&self) -> u64
pub fn events_observed(&self) -> u64
Total events observed since the observer was created or last reset.
Sourcepub fn lifetime_events_observed(&self) -> u64
pub fn lifetime_events_observed(&self) -> u64
Lifetime total of events observed since the observer was constructed, ignoring resets. Monotonic; suitable for driving Prometheus counters.
Sourcepub fn unique_keys(&self) -> usize
pub fn unique_keys(&self) -> usize
Distinct keys currently tracked (does not include overflow drops).
Sourcepub fn overflow_dropped(&self) -> u64
pub fn overflow_dropped(&self) -> u64
Insert attempts dropped because the observer was at capacity since the last reset.
Sourcepub fn lifetime_overflow_dropped(&self) -> u64
pub fn lifetime_overflow_dropped(&self) -> u64
Lifetime total of insert attempts dropped because the observer was at capacity, ignoring resets. Monotonic.
Auto Trait Implementations§
impl !Freeze for FieldObserver
impl RefUnwindSafe for FieldObserver
impl Send for FieldObserver
impl Sync for FieldObserver
impl Unpin for FieldObserver
impl UnsafeUnpin for FieldObserver
impl UnwindSafe for FieldObserver
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