Module health_check

Module health_check 

Source
Expand description

Copyright © 2025-2026 Wenze Wei. All Rights Reserved.

This file is part of DMSC. The DMSC project belongs to the Dunimd Team.

Licensed under the Apache License, Version 2.0 (the “License”); You may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

§Health Check Module

This module provides health checking functionality for the DMSC service mesh. It allows monitoring the health of services using various protocols and provides comprehensive health status information.

§Key Components

  • DMSCHealthCheckConfig: Configuration for health checks
  • DMSCHealthCheckResult: Result of a health check
  • DMSCHealthCheckType: Supported health check types
  • DMSCHealthCheckProvider: Trait for implementing health check providers
  • DMSCHttpHealthCheckProvider: HTTP health check implementation
  • DMSCTcpHealthCheckProvider: TCP health check implementation
  • DMSCHealthChecker: Main health checking service
  • DMSCHealthStatus: Health status enum
  • DMSCHealthSummary: Summary of health check results

§Design Principles

  1. Protocol Agnostic: Supports multiple health check protocols (HTTP, TCP, gRPC, custom)
  2. Async-First: All health check operations are asynchronous
  3. Extensible: Easy to implement new health check providers
  4. Configurable: Highly configurable health check parameters
  5. Real-time Monitoring: Background tasks for continuous health monitoring
  6. Comprehensive Results: Detailed health check results with response times and error messages
  7. Health Summary: Aggregated health status with success rates and average response times
  8. Thread-safe: Uses Arc and RwLock for safe concurrent access
  9. Graceful Shutdown: Proper cleanup of background tasks
  10. Error Handling: Comprehensive error handling with DMSCResult

§Usage

use dmsc::prelude::*;
use std::time::Duration;
 
async fn example() -> DMSCResult<()> {
    // Create a health checker with 30-second intervals
    let health_checker = DMSCHealthChecker::new(Duration::from_secs(30));
     
    // Register a health check for a service
    let config = DMSCHealthCheckConfig {
        endpoint: "/health".to_string(),
        method: "GET".to_string(),
        timeout: Duration::from_secs(5),
        expected_status_code: 200,
        expected_response_body: None,
        headers: HashMap::new(),
    };
     
    health_checker.register_health_check(
        "example-service",
        "http://localhost:8080",
        DMSCHealthCheckType::Http,
        config
    ).await?;
     
    // Start background health checks
    health_checker.start_health_check("example-service", "http://localhost:8080").await?;
     
    // Get health summary
    let summary = health_checker.get_service_health_summary("example-service").await?;
    println!("Service health: {:?}", summary.overall_status);
    println!("Success rate: {:.2}%", summary.success_rate);
     
    Ok(())
}

Structs§

DMSCGrpcHealthCheckProvider
gRPC health check provider.
DMSCHealthCheckConfig
Configuration for health checks.
DMSCHealthCheckResult
Result of a health check operation.
DMSCHealthChecker
Main health checker service.
DMSCHealthSummary
Summary of health check results.
DMSCHttpHealthCheckProvider
HTTP health check provider.
DMSCTcpHealthCheckProvider
TCP health check provider.

Enums§

DMSCHealthCheckType
Types of health checks supported.
DMSCHealthStatus
Health status enum.

Traits§

DMSCHealthCheckProvider
Trait for implementing health check providers.