Skip to content

Commit

Permalink
feat: support grpc health checking protocol
Browse files Browse the repository at this point in the history
Signed-off-by: iGxnon <[email protected]>
  • Loading branch information
iGxnon authored and Phoenix500526 committed Jul 19, 2023
1 parent 2850e4f commit f48464e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions xline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ tokio = { version = "0.2", package = "madsim-tokio", features = [
] }
tokio-stream = { git = "https://github.com/madsim-rs/tokio.git", rev = "ab251ad" }
tonic = { version = "0.2", package = "madsim-tonic" }
tonic-health = "0.8.0"
tracing = "0.1.37"
tracing-opentelemetry = "0.18.0"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
Expand Down
13 changes: 12 additions & 1 deletion xline/src/server/xline_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use jsonwebtoken::{DecodingKey, EncodingKey};
use tokio::net::TcpListener;
use tokio_stream::wrappers::TcpListenerStream;
use tonic::transport::Server;
use tonic_health::ServingStatus;
use utils::config::{ClientTimeout, CurpConfig, ServerTimeout, StorageConfig};

use super::{
Expand Down Expand Up @@ -85,7 +86,7 @@ impl XlineServer {
client_timeout,
storage_cfg: storage_config,
server_timeout,
shutdown_trigger: Arc::new(event_listener::Event::new()),
shutdown_trigger: Arc::new(Event::new()),
}
}

Expand Down Expand Up @@ -195,6 +196,10 @@ impl XlineServer {
maintenance_server,
curp_server,
) = self.init_servers(persistent, key_pair).await?;
let (mut reporter, health_server) = tonic_health::server::health_reporter();
reporter
.set_service_status("", ServingStatus::Serving)
.await;
Ok(Server::builder()
.add_service(RpcLockServer::new(lock_server))
.add_service(RpcKvServer::new(kv_server))
Expand All @@ -203,6 +208,7 @@ impl XlineServer {
.add_service(RpcWatchServer::new(watch_server))
.add_service(RpcMaintenanceServer::new(maintenance_server))
.add_service(ProtocolServer::new(curp_server))
.add_service(health_server)
.serve(addr)
.await?)
}
Expand Down Expand Up @@ -232,6 +238,10 @@ impl XlineServer {
maintenance_server,
curp_server,
) = self.init_servers(persistent, key_pair).await?;
let (mut reporter, health_server) = tonic_health::server::health_reporter();
reporter
.set_service_status("", ServingStatus::Serving)
.await;
Ok(Server::builder()
.add_service(RpcLockServer::new(lock_server))
.add_service(RpcKvServer::new(kv_server))
Expand All @@ -240,6 +250,7 @@ impl XlineServer {
.add_service(RpcWatchServer::new(watch_server))
.add_service(RpcMaintenanceServer::new(maintenance_server))
.add_service(ProtocolServer::new(curp_server))
.add_service(health_server)
.serve_with_incoming_shutdown(TcpListenerStream::new(xline_listener), signal)
.await?)
}
Expand Down

0 comments on commit f48464e

Please sign in to comment.