Skip to main content

FieldObserver

Struct FieldObserver 

Source
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

Source

pub fn new(max_keys: usize) -> Self

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).

Source

pub fn observe<E: Event + ?Sized>(&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.

Source

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.

Source

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.

Source

pub fn events_observed(&self) -> u64

Total events observed since the observer was created or last reset.

Source

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.

Source

pub fn unique_keys(&self) -> usize

Distinct keys currently tracked (does not include overflow drops).

Source

pub fn overflow_dropped(&self) -> u64

Insert attempts dropped because the observer was at capacity since the last reset.

Source

pub fn lifetime_overflow_dropped(&self) -> u64

Lifetime total of insert attempts dropped because the observer was at capacity, ignoring resets. Monotonic.

Source

pub fn max_keys(&self) -> usize

Configured per-observer ceiling for distinct keys.

Auto Trait Implementations§

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, 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.