Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tonic-health/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ pub struct HealthReporter {
}

impl HealthReporter {
fn new() -> Self {
/// Create a new HealthReporter with an initial service (named ""), corresponding to overall server health
pub fn new() -> Self {
// According to the gRPC Health Check specification, the empty service "" corresponds to the overall server health
let server_status = ("".to_string(), watch::channel(ServingStatus::Serving));

Expand Down Expand Up @@ -97,6 +98,12 @@ impl HealthReporter {
}
}

impl Default for HealthReporter {
fn default() -> Self {
Self::new()
}
}

/// A service providing implementations of gRPC health checking protocol.
#[derive(Debug)]
pub struct HealthService {
Expand All @@ -108,6 +115,11 @@ impl HealthService {
HealthService { statuses: services }
}

/// Create a HealthService, carrying across the statuses from an existing HealthReporter
pub fn from_health_reporter(health_reporter: HealthReporter) -> Self {
Self::new(health_reporter.statuses)
}

async fn service_health(&self, service_name: &str) -> Option<ServingStatus> {
let reader = self.statuses.read().await;
reader.get(service_name).map(|p| *p.1.borrow())
Expand Down