Commit 4be64e8f authored by Brian Clozel's avatar Brian Clozel

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
parent 05db4695
......@@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.kubernetes;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.autoconfigure.kubernetes.ProbesHealthContributorAutoConfiguration.KubernetesOrPropertyCondition;
import org.springframework.boot.actuate.availability.LivenessProbeHealthIndicator;
import org.springframework.boot.actuate.availability.ReadinessProbeHealthIndicator;
import org.springframework.boot.actuate.health.HealthEndpointGroupsRegistryCustomizer;
......@@ -24,11 +25,14 @@ import org.springframework.boot.actuate.kubernetes.ProbesHealthEndpointGroupsReg
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.availability.ApplicationAvailabilityProvider;
import org.springframework.boot.cloud.CloudPlatform;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
/**
......@@ -39,7 +43,7 @@ import org.springframework.context.annotation.Configuration;
* @since 2.3.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
@Conditional(KubernetesOrPropertyCondition.class)
@AutoConfigureAfter(ApplicationAvailabilityAutoConfiguration.class)
public class ProbesHealthContributorAutoConfiguration {
......@@ -64,4 +68,22 @@ public class ProbesHealthContributorAutoConfiguration {
return new ProbesHealthEndpointGroupsRegistrar();
}
static class KubernetesOrPropertyCondition extends AnyNestedCondition {
KubernetesOrPropertyCondition() {
super(ConfigurationPhase.PARSE_CONFIGURATION);
}
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
static class Kubernetes {
}
@ConditionalOnProperty(prefix = "management.health.probes", name = "enabled")
static class ProbesIndicatorsEnabled {
}
}
}
......@@ -146,6 +146,12 @@
"description": "Whether to enable ping health check.",
"defaultValue": true
},
{
"name": "management.health.probes.enabled",
"type": "java.lang.Boolean",
"description": "Whether to enable liveness and readiness probes.",
"defaultValue": false
},
{
"name": "management.health.rabbit.enabled",
"type": "java.lang.Boolean",
......
......@@ -47,8 +47,8 @@ class ProbesHealthContributorAutoConfigurationTests {
}
@Test
void probesConfiguredIfKubernetes() {
this.contextRunner.withPropertyValues("spring.main.cloud-platform=kubernetes")
void probesConfiguredIfProperty() {
this.contextRunner.withPropertyValues("management.health.probes.enabled=true")
.run((context) -> assertThat(context).hasSingleBean(ApplicationAvailabilityProvider.class)
.hasSingleBean(LivenessProbeHealthIndicator.class)
.hasSingleBean(ReadinessProbeHealthIndicator.class)
......
......@@ -184,7 +184,7 @@ TIP: The https://github.com/pivotal-cf/java-cfenv/[Java CFEnv] project is a bett
[[cloud-deployment-kubernetes]]
=== Kubernetes
Spring Boot auto-detects Kubernetes deployment environments by checking the environment for `"*_SERVICE_HOST"` and `"*_SERVICE_PORT"` variables.
You can override this detection with the configprop:spring.main.cloud-platform[] configuration property.
You can override this detection with the configprop:management.health.probes.enabled[] configuration property.
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>>.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment