pub struct ProviderHealthMonitor { /* private fields */ }Expand description
A thread-safe, cloneable monitor that tracks per-provider health.
All public methods are async and acquire an internal RwLock for the
minimum duration necessary.
§Clone semantics
Cloning shares the same underlying Arc-wrapped state, so all clones
observe the same data.
Implementations§
Source§impl ProviderHealthMonitor
impl ProviderHealthMonitor
Sourcepub fn new(window_size: usize) -> Self
pub fn new(window_size: usize) -> Self
Create a new monitor with the given rolling-window size.
window_size is the maximum number of samples (requests) retained per
provider when computing percentiles and error rate. Older samples are
evicted when the window is full (FIFO). A minimum of 1 is enforced.
§Panics
Never panics.
Sourcepub async fn record(&self, provider_id: &str, latency_ms: u64, success: bool)
pub async fn record(&self, provider_id: &str, latency_ms: u64, success: bool)
Record the outcome of a single completed request for provider_id.
latency_ms— round-trip time in milliseconds. Ignored (not added to the latency window) whensuccessisfalse.success—truefor a 2xx response,falsefor any error.
§Panics
Never panics.
Sourcepub async fn get_health(&self, provider_id: &str) -> Option<ProviderHealth>
pub async fn get_health(&self, provider_id: &str) -> Option<ProviderHealth>
Return a ProviderHealth snapshot for provider_id, or None if no
data has been recorded for that provider yet.
§Panics
Never panics.
Sourcepub async fn ranked_providers(&self) -> Vec<ProviderHealth>
pub async fn ranked_providers(&self) -> Vec<ProviderHealth>
Sourcepub async fn best_provider<'a>(
&self,
candidates: &'a [String],
) -> Option<&'a String>
pub async fn best_provider<'a>( &self, candidates: &'a [String], ) -> Option<&'a String>
Return the healthiest provider from the given candidates list.
Returns None if candidates is empty or none of the candidates have
recorded data.
§Panics
Never panics.
Sourcepub async fn is_usable(&self, provider_id: &str) -> bool
pub async fn is_usable(&self, provider_id: &str) -> bool
Returns true if provider_id has a health score above the “healthy”
threshold (> 0.5) and is not in a hard-failure state.
Providers with no recorded data are considered usable (optimistic default) so new providers are tried immediately.
§Panics
Never panics.
Trait Implementations§
Source§impl Clone for ProviderHealthMonitor
impl Clone for ProviderHealthMonitor
Source§fn clone(&self) -> ProviderHealthMonitor
fn clone(&self) -> ProviderHealthMonitor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ProviderHealthMonitor
impl !UnwindSafe for ProviderHealthMonitor
impl Freeze for ProviderHealthMonitor
impl Send for ProviderHealthMonitor
impl Sync for ProviderHealthMonitor
impl Unpin for ProviderHealthMonitor
impl UnsafeUnpin for ProviderHealthMonitor
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request