question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consul Health indicator not showing in SpringBoot' actuator health endpoint

See original GitHub issue

I have a SpringBoot based web application that exposes a consul health indicator bean.
The bean is correctly created and initialized by springboot’s autoconfiguration, yet, the indicator is not showing in the actuator health endpoint despite the fact that the associated configuration property “management.health.consul.enabled” is set to true:

{
   "status": "UP",
   "components": {
        "Kafka": {...},
        "SchemaRegistry": {...},
        "discoveryComposite": {...},
        "diskSpace": {...},
        "ping": {...},
        "refreshScope": {...}
    }
}

Upon further inspection, I found the bellow snippet that is responsible for fetching all the available indicators (HealthEndpointConfiguration.java) :

    @Bean
	@ConditionalOnMissingBean
	HealthContributorRegistry healthContributorRegistry(ApplicationContext applicationContext,
			HealthEndpointGroups groups) {
		Map<String, HealthContributor> healthContributors = new LinkedHashMap<>(
				applicationContext.getBeansOfType(HealthContributor.class));
		if (ClassUtils.isPresent("reactor.core.publisher.Flux", applicationContext.getClassLoader())) {
			healthContributors.putAll(new AdaptedReactiveHealthContributors(applicationContext).get());
		}
		return new AutoConfiguredHealthContributorRegistry(healthContributors, groups.getNames());
	}

Setting a break point there, I see that indeed the ConsulHealthIndicator bean is not listed in the output of the applicationContext.getBeansOfType(HealthContributor.class) call as shows bellow :

enter image description here

But when I test the same call with the parent application context instead, I get the following : AnnotationConfigApplicationContext

Can someone please shed some light on why this particular bean is present in the root context but not in the child context ?

Is there a way to force it’s initialisation in the child context so that it will get correctly registered in the health endpoint ?

I’ve attached a sample project allowing the reproduction of the issue. I’ve also included a sample of consul configuration that is used by the app (you can import it via consul import command). Running the example above and going to the health endpoint (localhost:8080/monitoring/health) you will clearly see that the consul component is missing from the list.

Thank you in advance.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
plmaheucommented, Sep 1, 2020

I noticed the health check wasn’t showing up in my system either. After digging I figured out the cause: the health check auto config is part of the Consul auto config so it gets created in the bootstrap context. That’s why you see it in the parent context, that;s the bootstrap context in Spring Cloud Config.

I’ll make a PR when I have a bit of time.

0reactions
M3hdicommented, Feb 8, 2021
ConsulAutoConfiguration.ConsulHealthConfig#consulHealthIndicator matched:
  - @ConditionalOnMissingBean (types: org.springframework.cloud.consul.ConsulHealthIndicator; SearchStrategy: all) did not find any beans (OnBeanCondition)
  - @ConditionalOnEnabledHealthIndicator management.health.defaults.enabled is considered true (OnEnabledHealthIndicatorCondition)

As you see above, the consul auto-configuration is matched and the health indicator is created. The problem is that the health indicator bean is registered into the root spring context and is therefore missed when the call to applicationContext.getBeansOfType(HealthContributor.class) is made.

That said, the above issue (reproducible on SpringBoot 2.3 / Hoxton.SR8 version), seems to be resolved with SpringBoot 2.4 in combination of the latest spring cloud release (2020.0.0).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Consul Health indicator not showing in SpringBoot' actuator ...
Running the example above and going to the health endpoint (localhost:8080/monitoring/health) you will clearly see that the consul component is ...
Read more >
Consul Health indicator not showing in SpringBoot' actuator ...
As it seems, the Consul health indicator is not registered to the health contributor registry, you can work around this by registering the...
Read more >
Springboot: Consul Health Indicator Missing From ... - ADocLib
If a local consul agent is restarted for what ever reason then the local Spring Consul Health indicator not showing in SpringBoot' actuator...
Read more >
2. Spring Cloud Commons: Common Abstractions
2.1.1 Health Indicator ... Commons creates a Spring Boot HealthIndicator that DiscoveryClient implementations can participate in by implementing ...
Read more >
A Quick Guide to Spring Cloud Consul - Baeldung
Health Checking – to detect when a service instance is up and running; Distributed Configuration – to ensure all service instances use the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found