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>
impl<Id: Eq + Hash + Clone> HealthTracker<Id>
Sourcepub fn new(policy: impl HealthPolicy + 'static) -> Self
pub fn new(policy: impl HealthPolicy + 'static) -> Self
Creates a new tracker with the given HealthPolicy.
Sourcepub fn report_success(&self, id: &Id)
pub fn report_success(&self, id: &Id)
Record a successful request to the node identified by id.
Sourcepub fn report_failure(&self, id: &Id)
pub fn report_failure(&self, id: &Id)
Record a failed request to the node identified by id.
Sourcepub fn report_outcome(&self, id: &Id, outcome: &Outcome)
pub fn report_outcome(&self, id: &Id, outcome: &Outcome)
Report a classified request outcome. See Outcome for details.
Sourcepub fn status(&self, id: &Id) -> HealthStatus
pub fn status(&self, id: &Id) -> HealthStatus
Returns the current HealthStatus (defaults to Healthy for unknown nodes).
Sourcepub fn should_probe(&self, id: &Id) -> bool
pub fn should_probe(&self, id: &Id) -> bool
Whether the node should receive a probe request (delegates to the policy).
Sourcepub fn get_health(&self, id: &Id) -> NodeHealth
pub fn get_health(&self, id: &Id) -> NodeHealth
Returns a snapshot of the full NodeHealth for the given node.
Trait Implementations§
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>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more