feat(health): Add tonic-health server impl

This commit adds a new crate `tonic-health` which implements the
[standard GRPC Health Checking][checking] protocol.

Currently there is only a server implementation, though others have
alluded in the discussion in #135 that client implementations exist
which could also be imported as necessary.

A example server has also been added - once the client work is done a
client for this should be added also.

[checking]: https://github.com/grpc/grpc/blob/master/doc/health-checking.md

Fixes #135.
This commit is contained in:
James Nugent
2020-03-30 09:33:02 -05:00
committed by GitHub
parent 25569e007b
commit da92dbf8aa
10 changed files with 478 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
use std::fmt::{Display, Formatter};
mod proto {
tonic::include_proto!("grpc.health.v1");
}
pub mod server;
/// An enumeration of values representing gRPC service health.
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum ServingStatus {
Unknown,
Serving,
NotServing,
}
impl Display for ServingStatus {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ServingStatus::Unknown => f.write_str("Unknown"),
ServingStatus::Serving => f.write_str("Serving"),
ServingStatus::NotServing => f.write_str("NotServing"),
}
}
}
impl From<ServingStatus> for proto::health_check_response::ServingStatus {
fn from(s: ServingStatus) -> Self {
match s {
ServingStatus::Unknown => proto::health_check_response::ServingStatus::Unknown,
ServingStatus::Serving => proto::health_check_response::ServingStatus::Serving,
ServingStatus::NotServing => proto::health_check_response::ServingStatus::NotServing,
}
}
}