pub struct Aggregator { /* private fields */ }Implementations§
Source§impl Aggregator
impl Aggregator
pub fn new(prefix: String) -> Aggregator
pub fn set_up_prefix(&mut self, prefix: String)
pub fn set_up_remote(&mut self, socket: UdpSocket, addr: SocketAddr)
pub fn set_up_origin(&mut self, origin: String)
pub fn set_up_tagged_metrics(&mut self, tagged: bool)
Sourcepub fn set_up_detail(&mut self, detail: MetricDetailLevel)
pub fn set_up_detail(&mut self, detail: MetricDetailLevel)
Set the static cardinality floor (MetricsConfig.detail from the TOML
configuration). Live leases applied via Self::lease_apply can
elevate the effective level at runtime; the configured floor is the
lower bound the worker falls back to when no lease is active.
See MetricDetailLevel and [filter_labels_for_detail] for the
per-level filtering rules.
Sourcepub fn detail_configured(&self) -> MetricDetailLevel
pub fn detail_configured(&self) -> MetricDetailLevel
Returns the static (configured) cardinality floor. Independent of runtime leases.
Sourcepub fn detail_effective(&self) -> MetricDetailLevel
pub fn detail_effective(&self) -> MetricDetailLevel
Returns the cardinality level actually applied to emissions. Equal to
max(configured, max(active leases)).
Sourcepub fn lease_apply(
&mut self,
client_id: String,
level: MetricDetailLevel,
ttl: Duration,
binding: PeerBinding,
) -> LeaseApplyOutcome
pub fn lease_apply( &mut self, client_id: String, level: MetricDetailLevel, ttl: Duration, binding: PeerBinding, ) -> LeaseApplyOutcome
Apply or renew a runtime cardinality lease for client_id. If a lease
for the same client already exists it is REPLACED (used for renewals).
ttl values above LEASE_TTL_MAX are rejected with
LeaseApplyOutcome::TtlOutOfRange (NOT clamped); callers must
handle that arm or pre-validate the TTL. On success the call returns
(previous_effective, new_effective) so callers can decide whether
to emit a MetricDetailChanged audit event.
The proto contract on SetMetricDetail.ttl_seconds is that the worker
rejects out-of-range values with a FAILURE response — that
enforcement lives at the dispatch site in lib/src/server.rs::notify.
lease_apply itself returns LeaseApplyOutcome::TtlOutOfRange
when called with ttl > LEASE_TTL_MAX so callers that bypass the
dispatch site (proto fuzzing, future internal use) see a loud
rejection instead of silently capped semantics. Same shape for
over-long client_id and a full lease table — see
LeaseApplyOutcome for the failure arms.
Sourcepub fn lease_clear(
&mut self,
client_id: &str,
presented: PeerBinding,
) -> LeaseClearOutcome
pub fn lease_clear( &mut self, client_id: &str, presented: PeerBinding, ) -> LeaseClearOutcome
Explicitly release a lease keyed by client_id. The clear is
authorised against the apply-time PeerBinding when one was
recorded — see LeaseClearOutcome for the three result states.
A clear request with presented = PeerBinding::default() matches
only leases whose apply-time binding was also unknown, preserving
compat with pre-binding callers and platforms without
SO_PEERCRED.
Sourcepub fn lease_count(&self) -> u32
pub fn lease_count(&self) -> u32
Returns the number of active (non-expired-as-of-last-tick) leases.
Surfaced in WorkerMetricDetailStatus so the TUI can show
“another client is still leasing this level”.
Sourcepub fn lease_tick(&mut self, now: Instant) -> Option<MetricDetailLevel>
pub fn lease_tick(&mut self, now: Instant) -> Option<MetricDetailLevel>
Polled lease-expiry janitor. Called from the worker’s notify loop
(and from periodic timers); cheap when nothing has expired. Returns
Some(previous_effective) when at least one lease expired AND that
expiry actually moved the effective level (so the caller can emit a
MetricDetailChanged audit event), or None for the no-change path.
now is parameterised so unit tests can advance the clock
deterministically without sleeping.
Sourcepub fn lease_tick_due(&self, now: Instant) -> bool
pub fn lease_tick_due(&self, now: Instant) -> bool
True when at least [LEASE_TICK_INTERVAL] has passed since the last
lease_tick. Use to gate the polled janitor at the top of notify
without paying a HashMap walk on every event-loop iteration.
pub fn socket(&self) -> Option<&UdpSocket>
pub fn socket_mut(&mut self) -> Option<&mut UdpSocket>
pub fn count_add(&mut self, key: &'static str, count_value: i64)
pub fn set_gauge(&mut self, key: &'static str, gauge_value: usize)
pub fn gauge_add(&mut self, key: &'static str, gauge_value: i64)
pub fn writable(&mut self)
pub fn send_data(&mut self)
pub fn dump_local_proxy_metrics(&mut self) -> BTreeMap<String, FilteredMetrics>
pub fn query( &mut self, q: &QueryMetricsOptions, ) -> Result<ResponseContent, MetricError>
pub fn clear_local(&mut self)
pub fn configure(&mut self, config: &MetricsConfiguration)
Sourcepub fn remove_cluster(&mut self, cluster_id: &str)
pub fn remove_cluster(&mut self, cluster_id: &str)
Drop all metric storage for a cluster across BOTH drains and arm
the per-drain tombstone so subsequent emissions for the cluster are
dropped on the floor instead of resurrecting the row via
entry().or_default(). Called from the worker IPC dispatch on
[RequestType::RemoveCluster]. Network-side draining the queued
MetricLines produces immediate silence on the wire (any unsent
statsd interval for the cluster is discarded).
Worker-event-loop only — METRICS is a thread_local!, and the
mutable borrow taken here must not be re-entered from a session-
bound code path. Calling this from a metrics emission site would
deadlock the thread-local on borrow_mut.
Sourcepub fn add_cluster(&mut self, cluster_id: &str)
pub fn add_cluster(&mut self, cluster_id: &str)
Re-arm a previously-removed cluster id across BOTH drains. Called
from the worker IPC dispatch on [RequestType::AddCluster].
Idempotent on ids that were never removed. Without this hook a
cluster removed then re-added would stay tombstoned forever and
every fresh metric emission would be dropped.
Sourcepub fn remove_backend(&mut self, cluster_id: &str, backend_id: &str)
pub fn remove_backend(&mut self, cluster_id: &str, backend_id: &str)
Drop all metric storage for one backend across BOTH drains. Called
from the worker IPC dispatch on [RequestType::RemoveBackend].
Does NOT tombstone the cluster (only remove_cluster does).