0

I have a consul server running on my local machine in dev mode with ACL enabled. Here is my ACL policy for service named web:

service "web" {
   policy = "write"
}

And I have a token where I have attached this policy.

enter image description here

I am trying to register the service named "web" written using spring boot V2.6.1 and the service is getting registered but the health check is failing.

enter image description here

Here are the details of spring boot application:

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.ms</groupId>
    <artifactId>web</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>web</name>
    <description>Demo project for Spring Boot</description>
    <packaging>jar</packaging>
    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>2021.0.0</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

application.yml

server:
  port: 8080

spring:
  application:
    name: web
  cloud:
    consul:
      config:
        enabled: false
        
      host: localhost
      port: 8500  
      discovery:
        instance-id: "${spring.application.name}-${server.port}" 
        prefer-ip-address: true
        health-check-critical-timeout: "1m"
        health-check-path: /actuator/health
        health-check-interval: 10s
        acl-token: "8a0a8090-08df-2cae-cb5d-9b6f91f34933"

Am I missing any configuration around health check?

Mudit Shukla
  • 814
  • 2
  • 6
  • 16
  • what can you see in `{baseUrl}/management/health` ? – eth4io Dec 20 '21 at 01:53
  • @eth4io I did not get, where should I check? – Mudit Shukla Dec 20 '21 at 02:47
  • send a get request to this endpoint. eg if you are on localhost, check `http://localhost:{port}/actuator/health` or maybe just `http://localhost:{port}/actuator` – eth4io Dec 20 '21 at 05:10
  • @eth4io I have already checked that, actuator endpoints are working. If I disable ACL then I am able to see health checks passing in consul. But, with ACL enabled health check are failing. – Mudit Shukla Dec 20 '21 at 05:25
  • @eth4io Well, this issue got resolved once I removed down_policy = "extend-cache" from my acl configuration. More at the following link. https://www.consul.io/docs/agent/options#acl_down_policy – Mudit Shukla Dec 21 '21 at 17:56

2 Answers2

0

Consul service health check is working in 2 way:

  1. call your actuator endpoint periodically, and this is the reason you need actuator dependency. in this case, you should make sure the consul can reach to your machine through specified port.
  2. Heart beat, in this case your service will call consul http endpoint for health check status. I suggest u to use health check property configuration and check whether the problem exist or not. if problem is gone, it means your issue was consul connection in point 1.
Ali mjz
  • 13
  • 4
0

I also had the same issue. The logs in consul show the health check URL used was http://localhost:4244/actuator/health without considering the server.servlet.context-path.

After modifying the health check path in the config, it worked.

consul:
  discovery:
    hostname: localhost
    health-check-path: /InfyGoBoot/flight/actuator/health
    health-check-interval: 10s

Now in Consul, it hits the correct URL for a health check,

HTTP GET http://localhost:4244/InfyGoBoot/flight/actuator/health: 200 Output: {"status":"UP"}