diff options
| author | mo khan <mo@mokhan.ca> | 2025-06-18 17:50:51 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-06-18 17:50:51 -0600 |
| commit | 1e9a769e5e4af4684967473f0844f66c3958432c (patch) | |
| tree | 6b4f315cc17f1a7469888fd2bff9a4dba12d2088 | |
| parent | fabafd3c434532935fa74fe8a75c09b9bbfb51e9 (diff) | |
feat: register the health check service and the reflection service
| -rw-r--r-- | Cargo.lock | 37 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | mise.toml | 1 | ||||
| -rw-r--r-- | src/main.rs | 12 |
5 files changed, 55 insertions, 1 deletions
@@ -47,6 +47,8 @@ dependencies = [ "envoy-types", "tokio", "tonic", + "tonic-health", + "tonic-reflection", ] [[package]] @@ -482,6 +484,15 @@ dependencies = [ ] [[package]] +name = "prost-types" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52c2c1bf36ddb1a1c396b3601a3cec27c2462e45f07c386894ec3ccf5332bd16" +dependencies = [ + "prost", +] + +[[package]] name = "quote" version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -597,6 +608,7 @@ dependencies = [ "futures-core", "pin-project-lite", "tokio", + "tokio-util", ] [[package]] @@ -642,6 +654,31 @@ dependencies = [ ] [[package]] +name = "tonic-health" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb87334d340313fefa513b6e60794d44a86d5f039b523229c99c323e4e19ca4b" +dependencies = [ + "prost", + "tokio", + "tokio-stream", + "tonic", +] + +[[package]] +name = "tonic-reflection" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9687bd5bfeafebdded2356950f278bba8226f0b32109537c4253406e09aafe1" +dependencies = [ + "prost", + "prost-types", + "tokio", + "tokio-stream", + "tonic", +] + +[[package]] name = "tower" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -7,3 +7,5 @@ edition = "2024" envoy-types = "0.6.0" tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } tonic = "*" +tonic-health = "0.13.1" +tonic-reflection = "0.13.1" @@ -15,3 +15,7 @@ build-image: .PHONY: run-image run-image: build-image @docker run --rm -p 50051:50051 -it $(IMAGE_TAG) + +.PHONY: health-check +health-check: + @grpcurl -plaintext localhost:50051 grpc.health.v1.Health/Check @@ -1,5 +1,6 @@ [tools] cargo = "latest" +grpcurl = "latest" make = "latest" rust = "stable" yamlfmt = "latest" diff --git a/src/main.rs b/src/main.rs index f84dc08e..5af58aa0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,9 +34,19 @@ impl Authorization for PolicyServer { #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let addr = "[::1]:50051".parse()?; - + let (health_reporter, health_service) = tonic_health::server::health_reporter(); + health_reporter + .set_serving::<AuthorizationServer<PolicyServer>>() + .await; + + let reflection_service = tonic_reflection::server::Builder::configure() + .register_encoded_file_descriptor_set(tonic_health::pb::FILE_DESCRIPTOR_SET) + .build_v1() + .unwrap(); Server::builder() + .add_service(health_service) .add_service(AuthorizationServer::new(PolicyServer::default())) + .add_service(reflection_service) .serve(addr) .await?; |
