Skip to main content

HealthCheckConfig

Struct HealthCheckConfig 

Source
pub struct HealthCheckConfig {
    pub enabled: bool,
    pub server_bind_address: Option<SocketAddr>,
    pub cache_ttl: Duration,
    pub min_connections: Option<usize>,
    pub max_memory_mb: Option<usize>,
    pub max_time_drift_ms: Option<i64>,
    pub max_pending_events: Option<usize>,
}
Expand description

Comprehensive health check configuration for NodeConfig.

This configuration enables and configures the health check system for a node. When set in NodeConfig, the node will automatically initialize health checks and optionally start an HTTP server to expose health endpoints.

§Health Check System

The health check system provides:

  • Built-in checks for connections, memory, time drift, and state convergence
  • Configurable thresholds for each check
  • HTTP endpoints for Kubernetes probes and load balancers
  • Result caching to minimize overhead

§HTTP Endpoints

When server_bind_address is set, the following endpoints are exposed:

  • GET /health - Overall health status (200 OK if healthy/degraded, 503 if unhealthy)
  • GET /ready - Readiness probe (200 OK if healthy/degraded, 503 if unhealthy)
  • GET /live - Liveness probe (200 OK if healthy/degraded, 503 if unhealthy)

§Example

use elara_runtime::health::HealthCheckConfig;
use elara_runtime::node::NodeConfig;
use std::time::Duration;

let health_config = HealthCheckConfig {
    enabled: true,
    server_bind_address: Some("0.0.0.0:8080".parse().unwrap()),
    cache_ttl: Duration::from_secs(30),
    min_connections: Some(3),
    max_memory_mb: Some(1800),
    max_time_drift_ms: Some(100),
    max_pending_events: Some(1000),
};

let node_config = NodeConfig {
    health_checks: Some(health_config),
    ..Default::default()
};

§Production Recommendations

§Small Deployment (10 nodes)

use elara_runtime::health::HealthCheckConfig;
use std::time::Duration;

let config = HealthCheckConfig {
    enabled: true,
    server_bind_address: Some("0.0.0.0:8080".parse().unwrap()),
    cache_ttl: Duration::from_secs(30),
    min_connections: Some(2),
    max_memory_mb: Some(1000),
    max_time_drift_ms: Some(100),
    max_pending_events: Some(500),
};

§Medium Deployment (100 nodes)

use elara_runtime::health::HealthCheckConfig;
use std::time::Duration;

let config = HealthCheckConfig {
    enabled: true,
    server_bind_address: Some("0.0.0.0:8080".parse().unwrap()),
    cache_ttl: Duration::from_secs(30),
    min_connections: Some(5),
    max_memory_mb: Some(2000),
    max_time_drift_ms: Some(100),
    max_pending_events: Some(1000),
};

§Large Deployment (1000 nodes)

use elara_runtime::health::HealthCheckConfig;
use std::time::Duration;

let config = HealthCheckConfig {
    enabled: true,
    server_bind_address: Some("0.0.0.0:8080".parse().unwrap()),
    cache_ttl: Duration::from_secs(30),
    min_connections: Some(10),
    max_memory_mb: Some(4000),
    max_time_drift_ms: Some(100),
    max_pending_events: Some(2000),
};

Fields§

§enabled: bool

Enable or disable health checks.

When false, no health checks are performed and no HTTP server is started. This allows health checks to be completely disabled in environments where they are not needed.

Default: true

§server_bind_address: Option<SocketAddr>

Optional bind address for the health check HTTP server.

When Some, an HTTP server is started on this address to expose health check endpoints (/health, /ready, /live). When None, health checks are still performed but no HTTP server is started (useful for programmatic health checking without exposing endpoints).

Format: "host:port" (e.g., "0.0.0.0:8080", "127.0.0.1:8080")

Default: Some("0.0.0.0:8080")

§cache_ttl: Duration

Cache TTL for health check results.

Health check results are cached for this duration to avoid excessive checking overhead. Subsequent health check requests within the TTL return cached results.

Recommended values:

  • High-frequency checks: 10-15 seconds
  • Normal checks: 30 seconds
  • Low-frequency checks: 60 seconds

Default: 30 seconds

§min_connections: Option<usize>

Minimum number of active connections for ConnectionHealthCheck.

When Some, a ConnectionHealthCheck is registered that monitors the number of active connections. The check returns Degraded if the connection count falls below this threshold.

When None, no connection health check is performed.

Recommended values:

  • Small deployment: 2-3
  • Medium deployment: 5-10
  • Large deployment: 10-20

Default: Some(3)

§max_memory_mb: Option<usize>

Maximum memory usage in megabytes for MemoryHealthCheck.

When Some, a MemoryHealthCheck is registered that monitors process memory usage. The check returns Unhealthy if memory usage exceeds this threshold.

When None, no memory health check is performed.

Recommended values:

  • Small deployment: 1000 MB (1 GB)
  • Medium deployment: 2000 MB (2 GB)
  • Large deployment: 4000 MB (4 GB)

Set this to 80-90% of your container memory limit to allow for graceful degradation before OOM kills.

Default: Some(1800) (1.8 GB)

§max_time_drift_ms: Option<i64>

Maximum time drift in milliseconds for TimeDriftCheck.

When Some, a TimeDriftCheck is registered that monitors time drift between the local node and network consensus time. The check returns Degraded if drift exceeds this threshold.

When None, no time drift check is performed.

Recommended value: 100 ms

Excessive time drift can cause synchronization issues and state divergence in distributed systems.

Default: Some(100)

§max_pending_events: Option<usize>

Maximum pending events for StateDivergenceCheck.

When Some, a StateDivergenceCheck is registered that monitors the state reconciliation engine. The check returns Degraded if the number of pending events exceeds this threshold.

When None, no state divergence check is performed.

Recommended values:

  • Small deployment: 500
  • Medium deployment: 1000
  • Large deployment: 2000

High pending event counts may indicate network partitions or reconciliation issues.

Default: Some(1000)

Implementations§

Source§

impl HealthCheckConfig

Source

pub fn disabled() -> Self

Creates a new HealthCheckConfig with all checks disabled.

This is useful when you want to selectively enable only specific checks.

§Example
use elara_runtime::health::HealthCheckConfig;

let mut config = HealthCheckConfig::disabled();
config.enabled = true;
config.max_memory_mb = Some(2000); // Only enable memory check
Source

pub fn small_deployment() -> Self

Creates a configuration for small deployments (10 nodes).

Recommended thresholds:

  • Min connections: 2
  • Max memory: 1000 MB
  • Max time drift: 100 ms
  • Max pending events: 500
Source

pub fn medium_deployment() -> Self

Creates a configuration for medium deployments (100 nodes).

Recommended thresholds:

  • Min connections: 5
  • Max memory: 2000 MB
  • Max time drift: 100 ms
  • Max pending events: 1000
Source

pub fn large_deployment() -> Self

Creates a configuration for large deployments (1000 nodes).

Recommended thresholds:

  • Min connections: 10
  • Max memory: 4000 MB
  • Max time drift: 100 ms
  • Max pending events: 2000
Source

pub fn validate(&self) -> Result<(), String>

Validates the configuration.

Returns Ok(()) if the configuration is valid, or an error message describing the validation failure.

§Validation Rules
  • cache_ttl must be at least 1 second
  • If min_connections is set, it must be > 0
  • If max_memory_mb is set, it must be > 0
  • If max_time_drift_ms is set, it must be > 0
  • If max_pending_events is set, it must be > 0

Trait Implementations§

Source§

impl Clone for HealthCheckConfig

Source§

fn clone(&self) -> HealthCheckConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HealthCheckConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for HealthCheckConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,