pub struct CircuitStats { /* private fields */ }Expand description
Circuit breaker statistics for tracking state transitions.
Maintains a rolling window of successes and failures to determine when the circuit should open, close, or enter half-open state.
Implementations§
Source§impl CircuitStats
impl CircuitStats
Sourcepub fn state(&self) -> CircuitState
pub fn state(&self) -> CircuitState
Get the current circuit state.
Sourcepub fn last_state_change(&self) -> u64
pub fn last_state_change(&self) -> u64
Get the timestamp of the last state change.
Sourcepub fn consecutive_failures(&self) -> u32
pub fn consecutive_failures(&self) -> u32
Get the consecutive failure count.
Sourcepub fn error_rate(&self) -> f64
pub fn error_rate(&self) -> f64
Get the error rate in the current window (0.0-1.0).
Sourcepub fn record_success(&mut self)
pub fn record_success(&mut self)
Record a successful operation.
In closed state: resets consecutive failures, increments window successes. In half-open state: increments consecutive successes.
Sourcepub fn record_failure(&mut self)
pub fn record_failure(&mut self)
Record a failed operation.
Increments consecutive failures and window failures. In half-open state, resets consecutive successes.
Sourcepub fn should_open(&self, config: &CircuitBreakerConfig) -> bool
pub fn should_open(&self, config: &CircuitBreakerConfig) -> bool
Check if the circuit should open based on config thresholds.
Returns true if:
- Consecutive failures exceed threshold, OR
- Error rate exceeds threshold (with minimum sample size)
Sourcepub fn should_half_open(&self, config: &CircuitBreakerConfig) -> bool
pub fn should_half_open(&self, config: &CircuitBreakerConfig) -> bool
Check if the circuit should transition to half-open.
Returns true if the circuit is open and the cooldown period has elapsed.
Sourcepub fn should_close(&self, config: &CircuitBreakerConfig) -> bool
pub fn should_close(&self, config: &CircuitBreakerConfig) -> bool
Check if the circuit should close.
Returns true if in half-open state and consecutive successes meet or exceed the success threshold.
Sourcepub fn can_probe(&self, config: &CircuitBreakerConfig) -> bool
pub fn can_probe(&self, config: &CircuitBreakerConfig) -> bool
Check if a probe request can be made in half-open state.
Returns true if active probes are below the maximum allowed.
Sourcepub fn start_probe(&mut self, config: &CircuitBreakerConfig) -> bool
pub fn start_probe(&mut self, config: &CircuitBreakerConfig) -> bool
Start a probe request in half-open state.
Returns true if the probe was started, false if already at max probes.
Sourcepub fn reset_window(&mut self)
pub fn reset_window(&mut self)
Reset the rolling window counters.
Called periodically to ensure the window reflects recent activity.
Sourcepub fn recent_results(&self) -> &[bool]
pub fn recent_results(&self) -> &[bool]
Get recent health check results for history visualization.
Returns a slice of recent results (true=success, false=failure), with the most recent result at the end.
Sourcepub fn recovery_remaining_secs(
&self,
config: &CircuitBreakerConfig,
) -> Option<u64>
pub fn recovery_remaining_secs( &self, config: &CircuitBreakerConfig, ) -> Option<u64>
Calculate seconds remaining until circuit auto-transitions to half-open.
Returns None if circuit is not open or cooldown has already elapsed.
Trait Implementations§
Source§impl Clone for CircuitStats
impl Clone for CircuitStats
Source§fn clone(&self) -> CircuitStats
fn clone(&self) -> CircuitStats
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more