1

According to section 3.2 of the Spring Cloud Consul manual:

An HTTP Check is created by default that Consul hits the /health endpoint every 10 seconds.

However, the log of my application reveals that this health check is missing. The property http should have a valid url and interval should have 10s, both are null:

Registering service with consul: NewService{id='test-service-local-8081', name='test-service', tags=[], address='localhost', port=8081, enableTagOverride=null, check=Check{script='null', interval='null', ttl='30s', http='null', tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status='null'}, checks=null}

Also, when I make my health endpoint return "status: down", consul still reports that my service is fine.

How do I add the HTTP check to /health on registration of the Spring Boot service with Consul?

I am using the following properties:

management:
  endpoints:
    web:
      base-path: /manage
spring:
  application:
    name: test-service
  cloud:
    consul:
      host: consul
      port: 8500
      discovery:
        healthCheckInterval: 10s
        healthCheckPath: "${management.endpoints.web.base-path}/health"
        heartbeat:
          enabled: true
        hostname: localhost

Edit: It turns out the heartbeat.enabled=true property removes the default HTTP check. When removing this property, we can see the HTTP check in the log:

Registering service with consul: NewService{id='test-service-local-8081', name='test-service', tags=[], address='erwins-mbp.home', port=8081, enableTagOverride=null, check=Check{script='null', interval='1s', ttl='null', http='http://mbp.home:8081/manage/health', tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status='null'}, checks=null}

So, now, the question is, with heartbeat enabled, how to I register a HTTP check from Spring Boot to Consul?

4

0 回答 0