summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-06-18 17:50:51 -0600
committermo khan <mo@mokhan.ca>2025-06-18 17:50:51 -0600
commit1e9a769e5e4af4684967473f0844f66c3958432c (patch)
tree6b4f315cc17f1a7469888fd2bff9a4dba12d2088
parentfabafd3c434532935fa74fe8a75c09b9bbfb51e9 (diff)
feat: register the health check service and the reflection service
-rw-r--r--Cargo.lock37
-rw-r--r--Cargo.toml2
-rw-r--r--Makefile4
-rw-r--r--mise.toml1
-rw-r--r--src/main.rs12
5 files changed, 55 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 9f9300df..cfb0a9d7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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"
diff --git a/Cargo.toml b/Cargo.toml
index 5d71a4ae..fc79f61b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"
diff --git a/Makefile b/Makefile
index ab0140fe..62138427 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/mise.toml b/mise.toml
index 87a29b17..c466bc2b 100644
--- a/mise.toml
+++ b/mise.toml
@@ -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?;