fix(consul): Fix health checks for gRPC services in Docker

- Add gRPC health check support to Consul registry
  - Services are gRPC-only, not HTTP
  - Consul was trying HTTP health checks which failed
  - Now uses gRPC health checks via grpc.health.v1.Health service

- Update HealthCheckConfig to support both HTTP and gRPC
  - Add GRPC field for gRPC service name
  - Add UseGRPC flag to choose health check type
  - Default to gRPC for services (use_grpc: true in config)

- Fix service address registration in Docker
  - Services now register with Docker service name (e.g., auth-service)
  - Allows Consul to reach services via Docker network DNS
  - Falls back to localhost for local development

- Update default.yaml to enable gRPC health checks
  - Set use_grpc: true
  - Set grpc: grpc.health.v1.Health

This fixes services being deregistered from Consul due to failed
HTTP health checks. Services will now pass gRPC health checks.
This commit is contained in:
2025-11-06 21:17:33 +01:00
parent 54e1866997
commit b02c1d44c8
7 changed files with 58 additions and 8 deletions

View File

@@ -218,8 +218,14 @@ func ProvideServiceRegistry() fx.Option {
healthCheckDeregisterAfter = 30 * time.Second
}
healthCheckHTTP := cfg.GetString("registry.consul.health_check.http")
if healthCheckHTTP == "" {
healthCheckHTTP = "/healthz"
healthCheckGRPC := cfg.GetString("registry.consul.health_check.grpc")
useGRPC := cfg.GetBool("registry.consul.health_check.use_grpc")
// Default to gRPC if not explicitly set (services are gRPC by default)
if !cfg.IsSet("registry.consul.health_check.use_grpc") {
useGRPC = true
}
if healthCheckGRPC == "" {
healthCheckGRPC = "grpc.health.v1.Health"
}
consulCfg.HealthCheck = consul.HealthCheckConfig{
@@ -227,6 +233,8 @@ func ProvideServiceRegistry() fx.Option {
Timeout: healthCheckTimeout,
DeregisterAfter: healthCheckDeregisterAfter,
HTTP: healthCheckHTTP,
GRPC: healthCheckGRPC,
UseGRPC: useGRPC,
}
return consul.NewRegistry(consulCfg)