[gRPC] Add standard gRPC health checking (grpc.health.v1) for Kubernetes native probes (#38016)

Signed-off-by: Honglin Cao <Caohonglin317@hotmail.com>
This commit is contained in:
Honglin Cao
2026-04-22 21:31:00 +00:00
committed by GitHub
parent 22fa63cfe8
commit 9c271f9403
4 changed files with 199 additions and 1 deletions
+11
View File
@@ -26,8 +26,10 @@ import time
try:
import grpc
from grpc_health.v1 import health_pb2_grpc
from grpc_reflection.v1alpha import reflection
from smg_grpc_proto import vllm_engine_pb2, vllm_engine_pb2_grpc
from smg_grpc_servicer.vllm.health_servicer import VllmHealthServicer
from smg_grpc_servicer.vllm.servicer import VllmEngineServicer
except ImportError as e:
raise ImportError(
@@ -98,9 +100,14 @@ async def serve_grpc(args: argparse.Namespace):
# Add servicer to server
vllm_engine_pb2_grpc.add_VllmEngineServicer_to_server(servicer, server)
# Add standard gRPC health service for Kubernetes probes
health_servicer = VllmHealthServicer(async_llm)
health_pb2_grpc.add_HealthServicer_to_server(health_servicer, server)
# Enable reflection for grpcurl and other tools
service_names = (
vllm_engine_pb2.DESCRIPTOR.services_by_name["VllmEngine"].full_name,
"grpc.health.v1.Health",
reflection.SERVICE_NAME,
)
reflection.enable_server_reflection(service_names, server)
@@ -147,6 +154,10 @@ async def serve_grpc(args: argparse.Namespace):
logger.info("Shutting down vLLM gRPC server...")
if stats_task is not None:
stats_task.cancel()
try:
health_servicer.set_not_serving()
except Exception: # broad: must not prevent server.stop() / shutdown()
logger.warning("Failed to set health status to NOT_SERVING", exc_info=True)
await server.stop(grace=5.0)
logger.info("gRPC server stopped")
async_llm.shutdown()