pub struct HealthMonitorBuilder<T: HealthReportSender> { /* private fields */ }Expand description
Builder for creating a HealthMonitor instance.
Allows configuring optional parameters with sensible defaults. Required
parameters must be set before calling [build()].
§Examples
use std::convert::Infallible;
use tokio::sync::broadcast;
use bloop_server_framework::health_monitor::{
HealthMonitorBuilder,
HealthReport,
HealthReportSender
};
struct DummySender;
impl HealthReportSender for DummySender {
type Error = Infallible;
async fn send(
&mut self,
report: &HealthReport,
silent: bool
) -> Result<(), Self::Error> {
Ok(())
}
}
let (_, event_rx) = broadcast::channel(512);
let monitor = HealthMonitorBuilder::new()
.sender(DummySender)
.event_rx(event_rx)
.max_client_events(100)
.build()
.expect("failed to build HealthMonitor");Implementations§
Source§impl<T: HealthReportSender> HealthMonitorBuilder<T>
impl<T: HealthReportSender> HealthMonitorBuilder<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new HealthMonitorBuilder with default configuration values.
You must provide at least a sender and an event receiver before calling
[build()].
Sourcepub fn sender(self, sender: T) -> Self
pub fn sender(self, sender: T) -> Self
Sets the report sender implementation.
This is a required field. The sender is used to transmit health reports during monitoring.
Sourcepub fn event_rx(self, event_rx: Receiver<Event>) -> Self
pub fn event_rx(self, event_rx: Receiver<Event>) -> Self
Sets the event receiver used to receive client health-related events.
This is a required field. The monitor listens to this channel for incoming events.
Sourcepub fn client_ids(self, client_ids: HashSet<String>) -> Self
pub fn client_ids(self, client_ids: HashSet<String>) -> Self
Sets the initial list of known client IDs to track in the health report.
Defaults to an empty set if not provided.
Sourcepub fn max_client_events(self, max_client_events: usize) -> Self
pub fn max_client_events(self, max_client_events: usize) -> Self
Sets the maximum number of recent events to store per client.
Defaults to 50. Events beyond this limit are discarded (oldest first).
Sourcepub fn connection_loss_limit(self, connection_loss_limit: usize) -> Self
pub fn connection_loss_limit(self, connection_loss_limit: usize) -> Self
Sets the number of recent ConnectionLoss events required to consider a
client unstable.
Defaults to 3.
Sourcepub fn check_interval(self, check_interval: Duration) -> Self
pub fn check_interval(self, check_interval: Duration) -> Self
Sets how frequently the system checks for health status updates.
Defaults to 30 seconds.
Sourcepub fn reminder_interval(self, reminder_interval: Duration) -> Self
pub fn reminder_interval(self, reminder_interval: Duration) -> Self
Sets the interval for sending health reminders if unhealthy clients are still present.
Defaults to 30 minutes.
Sourcepub fn offline_grace_period(self, offline_grace_period: Duration) -> Self
pub fn offline_grace_period(self, offline_grace_period: Duration) -> Self
Sets the grace period after the last connection loss before a client is considered offline.
Defaults to 2 minutes.
Sourcepub fn connection_loss_window(self, connection_loss_window: Duration) -> Self
pub fn connection_loss_window(self, connection_loss_window: Duration) -> Self
Sets the window of time used to count recent connection loss events.
Defaults to 10 minutes.
Sourcepub fn recovery_grace_period(self, recovery_grace_period: Duration) -> Self
pub fn recovery_grace_period(self, recovery_grace_period: Duration) -> Self
Sets the duration a client must remain stable before being promoted to healthy.
Defaults to 20 minutes.
Sourcepub fn build(self) -> Result<HealthMonitor<T>, BuilderError>
pub fn build(self) -> Result<HealthMonitor<T>, BuilderError>
Builds a HealthMonitor instance using the configured values.
Returns an error if required fields like the sender or event receiver are missing.
Trait Implementations§
Source§impl<T: Debug + HealthReportSender> Debug for HealthMonitorBuilder<T>
impl<T: Debug + HealthReportSender> Debug for HealthMonitorBuilder<T>
Source§impl<T: Default + HealthReportSender> Default for HealthMonitorBuilder<T>
impl<T: Default + HealthReportSender> Default for HealthMonitorBuilder<T>
Source§fn default() -> HealthMonitorBuilder<T>
fn default() -> HealthMonitorBuilder<T>
Auto Trait Implementations§
impl<T> Freeze for HealthMonitorBuilder<T>where
T: Freeze,
impl<T> RefUnwindSafe for HealthMonitorBuilder<T>where
T: RefUnwindSafe,
impl<T> Send for HealthMonitorBuilder<T>where
T: Send,
impl<T> Sync for HealthMonitorBuilder<T>where
T: Sync,
impl<T> Unpin for HealthMonitorBuilder<T>where
T: Unpin,
impl<T> UnsafeUnpin for HealthMonitorBuilder<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for HealthMonitorBuilder<T>where
T: UnwindSafe,
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
Source§impl<T> Erasable for T
impl<T> Erasable for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more