Skip to main content

HealthRecord

Struct HealthRecord 

Source
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

Source

pub const fn new() -> HealthRecord

Source

pub fn state(&self) -> BreakerState

Source

pub fn consec_fail(&self) -> u32

Source

pub fn total_calls(&self) -> u64

Source

pub fn total_fail(&self) -> u64

Source

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.

Source

pub fn ewma_latency_ms(&self) -> u64

Source

pub fn last_err_kind(&self) -> ErrKind

Source

pub fn last_ok_ms_ago(&self) -> Option<u64>

Source

pub fn opened_ms_ago(&self) -> Option<u64>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for HealthRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HealthRecord

Source§

fn default() -> HealthRecord

Returns the “default value” for a type. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more