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:
+30
-2
@@ -3,8 +3,8 @@ use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use buffa::{EnumValue, MessageField};
|
||||
use proto::proto::control::{TerminalInfo, TerminalInfos, TerminalRuntimeInfo};
|
||||
use proto::proto::grpc::health::v1::health_check_response::ServingStatus;
|
||||
use proto::control::{TerminalInfo, TerminalInfos, TerminalRuntimeInfo};
|
||||
use proto::rpc::health::{HealthReporter, ServingStatus};
|
||||
use tokio::sync::{Mutex, Notify, watch};
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -23,6 +23,7 @@ struct Inner {
|
||||
data_path: PathBuf,
|
||||
snapshots: watch::Sender<TerminalInfos>,
|
||||
shutdown: watch::Sender<bool>,
|
||||
health: HealthReporter,
|
||||
probe_requested: Notify,
|
||||
}
|
||||
|
||||
@@ -46,6 +47,13 @@ impl RegistryService {
|
||||
let revisions = snapshot.infos.keys().map(|id| (id.clone(), 0)).collect();
|
||||
let (snapshots, _) = watch::channel(snapshot.clone());
|
||||
let (shutdown, _) = watch::channel(false);
|
||||
let health = HealthReporter::new();
|
||||
health
|
||||
.set_statuses(&[
|
||||
("", ServingStatus::NOT_SERVING),
|
||||
("control.Center", ServingStatus::NOT_SERVING),
|
||||
])
|
||||
.expect("valid initial health statuses");
|
||||
Ok(Self {
|
||||
inner: Arc::new(Inner {
|
||||
directory: Mutex::new(Directory {
|
||||
@@ -56,6 +64,7 @@ impl RegistryService {
|
||||
data_path,
|
||||
snapshots,
|
||||
shutdown,
|
||||
health,
|
||||
probe_requested: Notify::new(),
|
||||
}),
|
||||
})
|
||||
@@ -71,9 +80,28 @@ impl RegistryService {
|
||||
|
||||
pub async fn shutdown(&self) {
|
||||
let _directory = self.inner.directory.lock().await;
|
||||
self.publish_readiness(ServingStatus::NOT_SERVING);
|
||||
self.inner.shutdown.send_replace(true);
|
||||
}
|
||||
|
||||
pub(crate) fn health_reporter(&self) -> &HealthReporter {
|
||||
&self.inner.health
|
||||
}
|
||||
|
||||
pub(crate) async fn set_ready(&self) -> Result<(), RegistryError> {
|
||||
let _directory = self.inner.directory.lock().await;
|
||||
self.ensure_running()?;
|
||||
self.publish_readiness(ServingStatus::SERVING);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn publish_readiness(&self, status: ServingStatus) {
|
||||
self.inner
|
||||
.health
|
||||
.set_statuses(&[("", status), ("control.Center", status)])
|
||||
.expect("readiness maps to valid health statuses");
|
||||
}
|
||||
|
||||
pub async fn register(&self, info: TerminalInfo) -> Result<String, RegistryError> {
|
||||
let info = normalize_info(info)?;
|
||||
let service = self.clone();
|
||||
|
||||
Reference in New Issue
Block a user