Skip to content

Add property for the initial status of the health check - #1055

Open
officialasishkumar wants to merge 1 commit into
spring-cloud:mainfrom
officialasishkumar:feat/383-health-check-initial-status
Open

officialasishkumar wants to merge 1 commit into
spring-cloud:mainfrom
officialasishkumar:feat/383-health-check-initial-status

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Problem

Consul sets every newly registered check to critical until the first HTTP check runs or, for a TTL check, until the first heartbeat arrives. Tooling that reacts to critical services, such as the Consul watch in #383 that terminates EC2 instances, can act on an instance that has only just started. Consul lets you set a different initial status, and NewService.Check already has the Status field, but nothing sets it.

Solution

A new discovery property sets the initial status of the registered check:

Property Description
spring.cloud.consul.discovery.health-check-initial-status Initial status of the registered health check (passing, warning or critical). Consul sets new checks to critical when this is not set.
spring:
  cloud:
    consul:
      discovery:
        health-check-initial-status: warning
  • ConsulAutoRegistration.createCheck sets the status, so it applies to both HTTP and TTL checks, and to the check of a separately registered management service.
  • The property is bound to the existing Check.CheckStatus enum, so the generated configuration metadata gives IDEs the valid values. Consul rejects unknown as a check status, so createCheck fails with a message that names the property instead of letting the registration request fail.
  • Nothing changes when the property is not set.

The discovery docs have a new "Initial Health Check Status" section, and the property is listed in the appendix.

Testing

  • ConsulAutoRegistrationHealthCheckInitialStatusTests (new) registers a service against Consul and checks that Consul reports the configured status for the check. It uses a TTL check with the heartbeat auto-configuration excluded, so only the initial status can set the check's status and the test is deterministic.
  • ConsulAutoRegistrationInitialStatusCheckTests (new) covers:
    • no status when the property is not set
    • the status on an HTTP check
    • the status on a TTL check
    • rejecting unknown
  • Without the change in createCheck, three of the new tests fail.
  • The serviceregistry tests and ConsulDiscoveryPropertiesTests pass against a Consul 1.22 agent (78 tests, 1 skipped).
  • Checkstyle and spring-javaformat:validate pass.

Fixes #383

Consul sets every newly registered check to critical until the first HTTP
check runs or, for a TTL check, until the first heartbeat arrives. Tooling
that reacts to critical services, such as Consul watches that terminate
unhealthy instances, can therefore act on an instance that has only just
started.

Add spring.cloud.consul.discovery.health-check-initial-status, which sets
the Status of the HTTP or TTL check created by
ConsulAutoRegistration.createCheck, so it also applies to the check of a
separately registered management service. The property is bound to
Check.CheckStatus, so IDEs offer the valid values. Consul only accepts
passing, warning and critical, so unknown is rejected when the check is
created rather than failing the registration request.

Document the property in the discovery guide and the configuration
properties appendix.

Fixes spring-cloudgh-383

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>

This branch has not been deployed

No deployments
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.

Support for Consul initial status property

2 participants