Skip to content

Commit 4be64e8

Browse files
committed
Add "management.health.probes.enabled" config property
Prior to this commit, we were relying on the `"spring.main.cloud-platform"` property for overriding cloud platform detection and enabling liveness and readiness probes. Changes made in gh-20553 have now been reverted. This commit adds the `"management.health.probes.enabled"` configuration property. The auto-configuration now enables the HTTP Probes and `HealthIndicator` if this property is enabled, or if the Kubernetes cloud platform is detected. This property is `false` by default for now, since enabling this for all Spring Boot applications would be a breaking change. In this case, the global `"/actuator/health"` endpoint could report `OUT_OF_SERVICE` during startup time because the application now reports the readiness as well. See gh-19593
1 parent 05db469 commit 4be64e8

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/kubernetes/ProbesHealthContributorAutoConfiguration.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@
1717
package org.springframework.boot.actuate.autoconfigure.kubernetes;
1818

1919
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
20+
import org.springframework.boot.actuate.autoconfigure.kubernetes.ProbesHealthContributorAutoConfiguration.KubernetesOrPropertyCondition;
2021
import org.springframework.boot.actuate.availability.LivenessProbeHealthIndicator;
2122
import org.springframework.boot.actuate.availability.ReadinessProbeHealthIndicator;
2223
import org.springframework.boot.actuate.health.HealthEndpointGroupsRegistryCustomizer;
2324
import org.springframework.boot.actuate.kubernetes.ProbesHealthEndpointGroupsRegistrar;
2425
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2526
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2627
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
28+
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
2729
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
2830
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
31+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2932
import org.springframework.boot.availability.ApplicationAvailabilityProvider;
3033
import org.springframework.boot.cloud.CloudPlatform;
3134
import org.springframework.context.annotation.Bean;
35+
import org.springframework.context.annotation.Conditional;
3236
import org.springframework.context.annotation.Configuration;
3337

3438
/**
@@ -39,7 +43,7 @@
3943
* @since 2.3.0
4044
*/
4145
@Configuration(proxyBeanMethods = false)
42-
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
46+
@Conditional(KubernetesOrPropertyCondition.class)
4347
@AutoConfigureAfter(ApplicationAvailabilityAutoConfiguration.class)
4448
public class ProbesHealthContributorAutoConfiguration {
4549

@@ -64,4 +68,22 @@ public HealthEndpointGroupsRegistryCustomizer probesRegistryCustomizer() {
6468
return new ProbesHealthEndpointGroupsRegistrar();
6569
}
6670

71+
static class KubernetesOrPropertyCondition extends AnyNestedCondition {
72+
73+
KubernetesOrPropertyCondition() {
74+
super(ConfigurationPhase.PARSE_CONFIGURATION);
75+
}
76+
77+
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
78+
static class Kubernetes {
79+
80+
}
81+
82+
@ConditionalOnProperty(prefix = "management.health.probes", name = "enabled")
83+
static class ProbesIndicatorsEnabled {
84+
85+
}
86+
87+
}
88+
6789
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@
146146
"description": "Whether to enable ping health check.",
147147
"defaultValue": true
148148
},
149+
{
150+
"name": "management.health.probes.enabled",
151+
"type": "java.lang.Boolean",
152+
"description": "Whether to enable liveness and readiness probes.",
153+
"defaultValue": false
154+
},
149155
{
150156
"name": "management.health.rabbit.enabled",
151157
"type": "java.lang.Boolean",

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/kubernetes/ProbesHealthContributorAutoConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ void probesNotConfiguredIfNotKubernetes() {
4747
}
4848

4949
@Test
50-
void probesConfiguredIfKubernetes() {
51-
this.contextRunner.withPropertyValues("spring.main.cloud-platform=kubernetes")
50+
void probesConfiguredIfProperty() {
51+
this.contextRunner.withPropertyValues("management.health.probes.enabled=true")
5252
.run((context) -> assertThat(context).hasSingleBean(ApplicationAvailabilityProvider.class)
5353
.hasSingleBean(LivenessProbeHealthIndicator.class)
5454
.hasSingleBean(ReadinessProbeHealthIndicator.class)

spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ TIP: The https://github.com/pivotal-cf/java-cfenv/[Java CFEnv] project is a bett
184184
[[cloud-deployment-kubernetes]]
185185
=== Kubernetes
186186
Spring Boot auto-detects Kubernetes deployment environments by checking the environment for `"*_SERVICE_HOST"` and `"*_SERVICE_PORT"` variables.
187-
You can override this detection with the configprop:spring.main.cloud-platform[] configuration property.
187+
You can override this detection with the configprop:management.health.probes.enabled[] configuration property.
188188

189189
Spring Boot helps you to <<spring-boot-features.adoc#boot-features-application-availability-state,manage the state of your application>> and export it with <<production-ready-features.adoc#production-ready-kubernetes-probes, HTTP Kubernetes Probes using Actuator>>.
190190

0 commit comments

Comments
 (0)