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.0Unless 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
- Protocol Agnostic: Supports multiple health check protocols (HTTP, TCP, gRPC, custom)
- Async-First: All health check operations are asynchronous
- Extensible: Easy to implement new health check providers
- Configurable: Highly configurable health check parameters
- Real-time Monitoring: Background tasks for continuous health monitoring
- Comprehensive Results: Detailed health check results with response times and error messages
- Health Summary: Aggregated health status with success rates and average response times
- Thread-safe: Uses Arc and RwLock for safe concurrent access
- Graceful Shutdown: Proper cleanup of background tasks
- 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§
- DMSC
Grpc Health Check Provider - gRPC health check provider.
- DMSC
Health Check Config - Configuration for health checks.
- DMSC
Health Check Result - Result of a health check operation.
- DMSC
Health Checker - Main health checker service.
- DMSC
Health Summary - Summary of health check results.
- DMSC
Http Health Check Provider - HTTP health check provider.
- DMSC
TcpHealth Check Provider - TCP health check provider.
Enums§
- DMSC
Health Check Type - Types of health checks supported.
- DMSC
Health Status - Health status enum.
Traits§
- DMSC
Health Check Provider - Trait for implementing health check providers.