feat(rpc): implement health check service and error handling
- Added `RpcError` enum for comprehensive error handling in RPC operations. - Introduced `HealthReporter` and `HealthService` for managing service health statuses. - Implemented health check and watch functionality in the health service. - Created integration tests for health check service, covering various scenarios. - Added unit tests for client options validation and stream functionality. - Established logging infrastructure for terminal and registry components. - Implemented logging lifecycle management and conflict resolution in tests.
This commit is contained in:
@@ -5,14 +5,14 @@ use connectrpc::{
|
||||
ConnectError, RequestContext, Response, ServiceRequest, ServiceResult, ServiceStream,
|
||||
};
|
||||
use futures_util::stream;
|
||||
use proto::proto::control::TerminalInfo;
|
||||
use proto::proto::grpc::health::v1::{
|
||||
use proto::control::TerminalInfo;
|
||||
use proto::grpc::health::v1::{
|
||||
Health, HealthCheckRequest, HealthCheckResponse, health_check_response::ServingStatus,
|
||||
};
|
||||
use tokio::sync::{oneshot, watch};
|
||||
|
||||
use crate::RegistryService;
|
||||
use crate::health::{check, endpoint, monitor};
|
||||
use crate::health::{check, monitor};
|
||||
|
||||
struct FakeHealth(watch::Receiver<ServingStatus>);
|
||||
|
||||
@@ -39,7 +39,7 @@ impl Health for FakeHealth {
|
||||
}
|
||||
|
||||
async fn wait_status(
|
||||
receiver: &mut watch::Receiver<proto::proto::control::TerminalInfos>,
|
||||
receiver: &mut watch::Receiver<proto::control::TerminalInfos>,
|
||||
id: &str,
|
||||
status: ServingStatus,
|
||||
) {
|
||||
@@ -127,15 +127,22 @@ async fn timeout_covers_http2_connection_setup() {
|
||||
assert_eq!(status, ServingStatus::NOT_SERVING);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn endpoint_supports_ipv6_and_hostnames() {
|
||||
for host in ["::1", "[::1]", "localhost"] {
|
||||
let uri = endpoint(&TerminalInfo {
|
||||
terminal_host: host.into(),
|
||||
terminal_port: 1234,
|
||||
..Default::default()
|
||||
})
|
||||
#[tokio::test]
|
||||
async fn readiness_cannot_override_shutdown() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let service = RegistryService::open(directory.path().join("terminals.bin"))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(uri.port_u16(), Some(1234));
|
||||
assert_eq!(
|
||||
service.health_reporter().status(""),
|
||||
Some(ServingStatus::NOT_SERVING)
|
||||
);
|
||||
let _ = tokio::join!(service.shutdown(), service.set_ready());
|
||||
assert!(service.set_ready().await.is_err());
|
||||
for name in ["", "control.Center"] {
|
||||
assert_eq!(
|
||||
service.health_reporter().status(name),
|
||||
Some(ServingStatus::NOT_SERVING)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user