From 8dedeb4c6a66bf518a455bf1331ebdb9a94bda19 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Sat, 1 Aug 2020 20:57:34 +0200 Subject: [PATCH] Fix missing liveness and readiness indicators Prior to this commit, the livenessState and readinessState health indicators would not be configured automatically and would be missing from the "liveness" and "readiness" health groups, leading to 404s when hitting the `/actuator/health/liveness` or `/actuator/health/readiness`. This commit ensures that the health indicators beans have the proper name and revisits the auto-configuration conditions to reflect that as well. Fixes gh-22562 --- .../AvailabilityHealthContributorAutoConfiguration.java | 4 ++-- .../AvailabilityProbesAutoConfiguration.java | 9 +++++---- .../AvailabilityProbesAutoConfigurationTests.java | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityHealthContributorAutoConfiguration.java index daa6dfdb42..4a028096f7 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityHealthContributorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityHealthContributorAutoConfiguration.java @@ -40,14 +40,14 @@ import org.springframework.context.annotation.Configuration; public class AvailabilityHealthContributorAutoConfiguration { @Bean - @ConditionalOnMissingBean + @ConditionalOnMissingBean(name = "livenessStateHealthIndicator") @ConditionalOnProperty(prefix = "management.health.livenessstate", name = "enabled", havingValue = "true") public LivenessStateHealthIndicator livenessStateHealthIndicator(ApplicationAvailability applicationAvailability) { return new LivenessStateHealthIndicator(applicationAvailability); } @Bean - @ConditionalOnMissingBean + @ConditionalOnMissingBean(name = "readinessStateHealthIndicator") @ConditionalOnProperty(prefix = "management.health.readinessstate", name = "enabled", havingValue = "true") public ReadinessStateHealthIndicator readinessStateHealthIndicator( ApplicationAvailability applicationAvailability) { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfiguration.java index 2863b3c1b3..99e0e84d10 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfiguration.java @@ -48,14 +48,15 @@ import org.springframework.core.type.AnnotatedTypeMetadata; public class AvailabilityProbesAutoConfiguration { @Bean - @ConditionalOnMissingBean - public LivenessStateHealthIndicator livenessStateProbeIndicator(ApplicationAvailability applicationAvailability) { + @ConditionalOnMissingBean(name = "livenessStateHealthIndicator") + public LivenessStateHealthIndicator livenessStateHealthIndicator(ApplicationAvailability applicationAvailability) { return new LivenessStateHealthIndicator(applicationAvailability); } @Bean - @ConditionalOnMissingBean - public ReadinessStateHealthIndicator readinessStateProbeIndicator(ApplicationAvailability applicationAvailability) { + @ConditionalOnMissingBean(name = "readinessStateHealthIndicator") + public ReadinessStateHealthIndicator readinessStateHealthIndicator( + ApplicationAvailability applicationAvailability) { return new ReadinessStateHealthIndicator(applicationAvailability); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfigurationTests.java index f44b8389d3..7e422cc579 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfigurationTests.java @@ -50,8 +50,8 @@ class AvailabilityProbesAutoConfigurationTests { void probesWhenKubernetesAddsBeans() { this.contextRunner.withPropertyValues("spring.main.cloud-platform=kubernetes") .run((context) -> assertThat(context).hasSingleBean(ApplicationAvailability.class) - .hasSingleBean(LivenessStateHealthIndicator.class) - .hasSingleBean(ReadinessStateHealthIndicator.class) + .hasSingleBean(LivenessStateHealthIndicator.class).hasBean("livenessStateHealthIndicator") + .hasSingleBean(ReadinessStateHealthIndicator.class).hasBean("readinessStateHealthIndicator") .hasSingleBean(AvailabilityProbesHealthEndpointGroupsPostProcessor.class)); } @@ -59,8 +59,8 @@ class AvailabilityProbesAutoConfigurationTests { void probesWhenPropertyEnabledAddsBeans() { this.contextRunner.withPropertyValues("management.endpoint.health.probes.enabled=true") .run((context) -> assertThat(context).hasSingleBean(ApplicationAvailability.class) - .hasSingleBean(LivenessStateHealthIndicator.class) - .hasSingleBean(ReadinessStateHealthIndicator.class) + .hasSingleBean(LivenessStateHealthIndicator.class).hasBean("livenessStateHealthIndicator") + .hasSingleBean(ReadinessStateHealthIndicator.class).hasBean("readinessStateHealthIndicator") .hasSingleBean(AvailabilityProbesHealthEndpointGroupsPostProcessor.class)); }