diff --git a/ha-gateway/cmd/gateway/main.go b/ha-gateway/cmd/gateway/main.go index 01c9de8..a9d9ecb 100644 --- a/ha-gateway/cmd/gateway/main.go +++ b/ha-gateway/cmd/gateway/main.go @@ -12,6 +12,8 @@ import ( "github.com/joho/godotenv" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "google.golang.org/grpc" + "google.golang.org/grpc/health" + grpc_health_v1 "google.golang.org/grpc/health/grpc_health_v1" "google.golang.org/grpc/peer" "google.golang.org/grpc/reflection" @@ -79,12 +81,15 @@ func main() { grpc.ChainUnaryInterceptor(loggingUnaryInterceptor), grpc.ChainStreamInterceptor(loggingStreamInterceptor), ) + healthSrv := health.NewServer() + healthSrv.SetServingStatus("", grpc_health_v1.HealthCheckResponse_SERVING) // 7. Register services. hav1.RegisterEntityServiceServer(srv, grpcadapter.NewEntityGRPC(entityApp)) hav1.RegisterLightServiceServer(srv, grpcadapter.NewLightGRPC(lightApp)) hav1.RegisterSwitchServiceServer(srv, grpcadapter.NewSwitchGRPC(switchApp)) hav1.RegisterEventServiceServer(srv, &grpcadapter.EventGRPC{}) + grpc_health_v1.RegisterHealthServer(srv, healthSrv) reflection.Register(srv) // 8. Start listener. @@ -107,6 +112,7 @@ func main() { slog.Info("shutting down") // 11. Graceful stop, then flush telemetry. + healthSrv.SetServingStatus("", grpc_health_v1.HealthCheckResponse_NOT_SERVING) srv.GracefulStop() shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)