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) -> Self
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).
Sourcepub fn observe<E: Event + ?Sized>(&self, event: &E)
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.
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.