Skip to content

Add support for gRPC health checks - #1054

Merged
ryanjbaxter merged 3 commits into
spring-cloud:mainfrom
officialasishkumar:feat/625-grpc-health-check
Nov 24, 2026
Merged

ryanjbaxter merged 3 commits into
spring-cloud:mainfrom
officialasishkumar:feat/625-grpc-health-check

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Problem

Services that run a gRPC server can only be registered with an HTTP or TTL check, so Consul never health checks their gRPC endpoint. NewService.Check already has the GRPC and GRPCUseTLS fields, but nothing sets them.

Solution

Three new discovery properties register a Consul gRPC check in place of the HTTP check:

Property Description
spring.cloud.consul.discovery.health-check-grpc-port Port of the gRPC server. Setting it turns on the gRPC check.
spring.cloud.consul.discovery.health-check-grpc-service Optional service to check with the gRPC health checking protocol. If it is not set, the whole server is checked.
spring.cloud.consul.discovery.health-check-grpc-use-tls Whether Consul connects over TLS. Defaults to false.
spring:
  cloud:
    consul:
      discovery:
        health-check-grpc-port: 9090
        health-check-grpc-service: my.package.MyService
  • The check targets the discovery hostname. IPv6 addresses are wrapped in brackets so Consul can parse host:port.
  • health-check-interval, health-check-timeout, health-check-critical-timeout and health-check-tls-skip-verify also apply to the gRPC check. Headers are not sent because they only apply to HTTP checks.
  • A TTL check still wins when heartbeat.enabled=true, because the heartbeat only updates TTL checks.
  • A separate management service keeps its HTTP check of the actuator health endpoint.
  • The new ConsulAutoRegistration.createGrpcCheck sits next to createCheck.

The discovery docs have a new "gRPC Health Check" section, and the properties are listed in the appendix.

Testing

  • ConsulAutoRegistrationGrpcHealthCheckTests (new) runs against the Consul Testcontainer. It checks the registered check (target, TLS, interval, timeout, critical timeout, TLS skip verify, and no HTTP check or headers) and that Consul has the service check.
  • ConsulAutoRegistrationGrpcCheckTests (new) covers:
    • checking the whole server by default
    • checking a named service
    • IPv6 bracketing
    • rejecting an invalid port
    • TTL precedence
    • register-health-check=false
    • the management service keeping its HTTP check
  • I also tested against a real Consul 1.22 agent and a gRPC server running the standard grpc.health.v1.Health service, using a temporary test that is not part of this PR:
    • A service registered with health-check-grpc-service set to a SERVING service turned passing with output gRPC check host.docker.internal:34499/my.package.MyService: success.
    • For a NOT_SERVING service, the agent showed a grpc check, critical, with output serving status: NOT_SERVING.
  • The discovery test suite passes (160 tests, 1 skipped).
  • Checkstyle and spring-javaformat:validate pass.

Fixes #625

Services that expose a gRPC server could only be registered with an HTTP
or TTL check, so their gRPC endpoint was never health checked by Consul.

Add three discovery properties to register a Consul gRPC check instead
of the HTTP check:

- spring.cloud.consul.discovery.health-check-grpc-port enables the check
  and sets the port of the gRPC server. The check targets the discovery
  hostname, with IPv6 addresses enclosed in brackets.
- spring.cloud.consul.discovery.health-check-grpc-service optionally
  names the service to check with the gRPC health checking protocol.
  The whole server is checked otherwise.
- spring.cloud.consul.discovery.health-check-grpc-use-tls makes Consul
  connect to the gRPC server over TLS.

The existing interval, timeout, critical timeout and TLS skip verify
properties apply to the gRPC check too. A TTL check still takes
precedence, since the heartbeat only updates TTL checks, and a separate
management service keeps its HTTP check of the health endpoint.

Fixes spring-cloudgh-625

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
check.setGrpcUseTLS(properties.isHealthCheckGrpcUseTls());
check.setInterval(properties.getHealthCheckInterval());
check.setTimeout(properties.getHealthCheckTimeout());
check.setTlsSkipVerify(properties.getHealthCheckTlsSkipVerify());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tlsSkipVerify is passed through even with use-tls=false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, tlsSkipVerify is now only set on the gRPC check when use-tls is true (7d21b6a).

Comment thread docs/modules/ROOT/pages/discovery.adoc Outdated
----

Set `spring.cloud.consul.discovery.health-check-grpc-use-tls` to `true` if the gRPC server uses TLS.
The `health-check-interval`, `health-check-timeout`, `health-check-critical-timeout` and `health-check-tls-skip-verify` properties apply to the gRPC check as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you say which HTTP-specific properties don't apply?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the docs: health-check-path, health-check-url, health-check-headers and the scheme are ignored by the gRPC check, and tls-skip-verify only applies with use-tls.

Document which HTTP specific properties the gRPC check ignores.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
@ryanjbaxter
ryanjbaxter merged commit be073e1 into spring-cloud:main Nov 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for health check with gRPC

3 participants