pub struct HealthRecord { /* private fields */ }Expand description
Per-endpoint health and breaker state. Every field is an atomic so the
record can be updated through a shared &self on the dial path without a
lock, which is what lets EndpointList::iter hand out &Endpoint while a
call in flight records its outcome.
Implementations§
Source§impl HealthRecord
impl HealthRecord
pub const fn new() -> HealthRecord
pub fn state(&self) -> BreakerState
pub fn consec_fail(&self) -> u32
pub fn total_calls(&self) -> u64
pub fn total_fail(&self) -> u64
Sourcepub fn error_rate(&self) -> f64
pub fn error_rate(&self) -> f64
Process-lifetime error rate, total_fail / total_calls. It is a lifetime
figure and never decays, so a long-lived agent’s value lags a recent
recovery; a windowed rate is the collector’s job, derived from the
scraped counters rather than kept here.
pub fn ewma_latency_ms(&self) -> u64
pub fn last_err_kind(&self) -> ErrKind
pub fn last_ok_ms_ago(&self) -> Option<u64>
pub fn opened_ms_ago(&self) -> Option<u64>
Sourcepub fn cooldown(&self, cfg: &BreakerConfig) -> Duration
pub fn cooldown(&self, cfg: &BreakerConfig) -> Duration
The current cooldown for this endpoint: the initial cooldown doubled once
per consecutive open, capped at cooldown_max. A repeatedly failing
endpoint is therefore probed less and less often, while one that closes
again resets to the initial cooldown.
Sourcepub fn available(&self, cfg: &BreakerConfig) -> bool
pub fn available(&self, cfg: &BreakerConfig) -> bool
True if this endpoint is currently usable, i.e. not OPEN and still
cooling. Called by attempt_order(). This is not a pure read: an
endpoint whose cooldown has elapsed is promoted to HALF-OPEN here, so the
next call probes it. Use is_up where a side-effect-free
answer is required.
Sourcepub fn is_up(&self) -> bool
pub fn is_up(&self) -> bool
True if the breaker is not OPEN, i.e. the endpoint is in rotation. This
is the meaning of the agentd_intel_endpoint_up gauge. Unlike
available it is a pure read and never promotes a
cooled-down breaker, so observing an endpoint cannot change its state.
Sourcepub fn record_success(&self, latency: Duration) -> Option<BreakerTransition>
pub fn record_success(&self, latency: Duration) -> Option<BreakerTransition>
Record a successful round-trip: reset the consecutive-failure run,
re-close the breaker, and fold the latency into the EWMA (alpha = 1/8).
Returns the breaker transition if one happened, which the caller emits as
an event and reflects in the served resource body; None means the
breaker was already CLOSED and nothing is worth reporting.
Sourcepub fn record_failure(
&self,
kind: ErrKind,
cfg: &BreakerConfig,
) -> Option<BreakerTransition>
pub fn record_failure( &self, kind: ErrKind, cfg: &BreakerConfig, ) -> Option<BreakerTransition>
Record a failover-class failure: bump the consecutive-failure run, stamp the error kind, and open the breaker if the run crossed the threshold or a HALF-OPEN probe failed. Only failover-class failures belong here — an auth or bad-request error is identical on every endpoint, so counting it would open breakers across a perfectly healthy list. Returns the breaker transition if one happened, for the caller to emit.