Skip to main content

HealthTracker

Struct HealthTracker 

Source
pub struct HealthTracker<Id: Eq + Hash + Clone> { /* private fields */ }
Expand description

Tracks health state for a set of nodes identified by Id.

Thread-safe — all methods take &self and synchronise internally via RwLock.

§Examples

use loadwise::{HealthTracker, HealthStatus, ConsecutiveFailurePolicy};

let tracker = HealthTracker::new(ConsecutiveFailurePolicy::default());

// Unknown nodes are considered healthy.
assert_eq!(tracker.status(&"node-1"), HealthStatus::Healthy);

// Three consecutive failures → Unhealthy (default threshold = 3).
tracker.report_failure(&"node-1");
tracker.report_failure(&"node-1");
tracker.report_failure(&"node-1");
assert_eq!(tracker.status(&"node-1"), HealthStatus::Unhealthy);

// One success → Recovering.
tracker.report_success(&"node-1");
assert_eq!(tracker.status(&"node-1"), HealthStatus::Recovering);

// Second success → Healthy again (default recovery_successes = 2).
tracker.report_success(&"node-1");
assert_eq!(tracker.status(&"node-1"), HealthStatus::Healthy);

Implementations§

Source§

impl<Id: Eq + Hash + Clone> HealthTracker<Id>

Source

pub fn new(policy: impl HealthPolicy + 'static) -> Self

Creates a new tracker with the given HealthPolicy.

Source

pub fn report_success(&self, id: &Id)

Record a successful request to the node identified by id.

Source

pub fn report_failure(&self, id: &Id)

Record a failed request to the node identified by id.

Source

pub fn report_outcome(&self, id: &Id, outcome: &Outcome)

Report a classified request outcome. See Outcome for details.

Source

pub fn status(&self, id: &Id) -> HealthStatus

Returns the current HealthStatus (defaults to Healthy for unknown nodes).

Source

pub fn should_probe(&self, id: &Id) -> bool

Whether the node should receive a probe request (delegates to the policy).

Source

pub fn get_health(&self, id: &Id) -> NodeHealth

Returns a snapshot of the full NodeHealth for the given node.

Trait Implementations§

Source§

impl<Id: Eq + Hash + Clone> Debug for HealthTracker<Id>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Id> !Freeze for HealthTracker<Id>

§

impl<Id> !RefUnwindSafe for HealthTracker<Id>

§

impl<Id> Send for HealthTracker<Id>
where Id: Send,

§

impl<Id> Sync for HealthTracker<Id>
where Id: Send + Sync,

§

impl<Id> Unpin for HealthTracker<Id>
where Id: Unpin,

§

impl<Id> UnsafeUnpin for HealthTracker<Id>

§

impl<Id> !UnwindSafe for HealthTracker<Id>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V