Skip to content

Commit 83ad15b

Browse files
committed
Enable liveness and readiness by default
Closes gh-22825
1 parent 8f0d87a commit 83ad15b

File tree

6 files changed

+18
-80
lines changed

6 files changed

+18
-80
lines changed

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/endpoints.adoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ TIP: The `ssl` javadoc:org.springframework.boot.actuate.health.HealthIndicator[]
672672
If an SSL certificate will be invalid within the time span defined by this threshold, the javadoc:org.springframework.boot.actuate.health.HealthIndicator[] will warn you but it will still return HTTP 200 to not disrupt the application.
673673
You can use this threshold to give yourself enough lead time to rotate the soon to be expired certificate.
674674

675-
Additional javadoc:org.springframework.boot.actuate.health.HealthIndicator[] beans are available but are not enabled by default:
675+
Additional javadoc:org.springframework.boot.actuate.health.HealthIndicator[] beans are enabled by default:
676676

677677
[cols="3,4,6"]
678678
|===
@@ -687,6 +687,8 @@ Additional javadoc:org.springframework.boot.actuate.health.HealthIndicator[] bea
687687
| Exposes the "`Readiness`" application availability state.
688688
|===
689689

690+
These can be disabled by using the configprop:management.endpoint.health.probes.enabled[] configuration property.
691+
690692

691693

692694
[[actuator.endpoints.health.writing-custom-health-indicators]]
@@ -952,8 +954,8 @@ readinessProbe:
952954
NOTE: `<actuator-port>` should be set to the port that the actuator endpoints are available on.
953955
It could be the main web server port or a separate management port if the `"management.server.port"` property has been set.
954956

955-
These health groups are automatically enabled only if the application xref:how-to:deployment/cloud.adoc#howto.deployment.cloud.kubernetes[runs in a Kubernetes environment].
956-
You can enable them in any environment by using the configprop:management.endpoint.health.probes.enabled[] configuration property.
957+
These health groups are automatically enabled.
958+
You can disable them by using the configprop:management.endpoint.health.probes.enabled[] configuration property.
957959

958960
NOTE: If an application takes longer to start than the configured liveness period, Kubernetes mentions the `"startupProbe"` as a possible solution.
959961
Generally speaking, the `"startupProbe"` is not necessarily needed here, as the `"readinessProbe"` fails until all startup tasks are done.

module/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfiguration.java

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,18 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.availability;
1818

19-
import org.jspecify.annotations.Nullable;
20-
2119
import org.springframework.boot.actuate.availability.LivenessStateHealthIndicator;
2220
import org.springframework.boot.actuate.availability.ReadinessStateHealthIndicator;
2321
import org.springframework.boot.autoconfigure.AutoConfiguration;
2422
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2523
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
26-
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
27-
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
2825
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2926
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
30-
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
3127
import org.springframework.boot.availability.ApplicationAvailability;
32-
import org.springframework.boot.cloud.CloudPlatform;
3328
import org.springframework.boot.health.contributor.Health;
3429
import org.springframework.context.annotation.Bean;
35-
import org.springframework.context.annotation.ConditionContext;
36-
import org.springframework.context.annotation.Conditional;
3730
import org.springframework.core.env.Environment;
38-
import org.springframework.core.type.AnnotatedTypeMetadata;
3931

4032
/**
4133
* {@link EnableAutoConfiguration Auto-configuration} for availability probes.
@@ -47,7 +39,7 @@
4739
@AutoConfiguration(after = { AvailabilityHealthContributorAutoConfiguration.class,
4840
ApplicationAvailabilityAutoConfiguration.class })
4941
@ConditionalOnClass(Health.class)
50-
@Conditional(AvailabilityProbesAutoConfiguration.ProbesCondition.class)
42+
@ConditionalOnBooleanProperty(name = "management.endpoint.health.probes.enabled", matchIfMissing = true)
5143
public final class AvailabilityProbesAutoConfiguration {
5244

5345
@Bean
@@ -68,49 +60,4 @@ AvailabilityProbesHealthEndpointGroupsPostProcessor availabilityProbesHealthEndp
6860
return new AvailabilityProbesHealthEndpointGroupsPostProcessor(environment);
6961
}
7062

71-
/**
72-
* {@link SpringBootCondition} to enable or disable probes.
73-
* <p>
74-
* Probes are enabled if the dedicated configuration property is enabled or if the
75-
* Kubernetes cloud environment is detected/enforced.
76-
*/
77-
static class ProbesCondition extends SpringBootCondition {
78-
79-
private static final String ENABLED_PROPERTY = "management.endpoint.health.probes.enabled";
80-
81-
private static final String DEPRECATED_ENABLED_PROPERTY = "management.health.probes.enabled";
82-
83-
@Override
84-
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
85-
Environment environment = context.getEnvironment();
86-
ConditionMessage.Builder message = ConditionMessage.forCondition("Probes availability");
87-
ConditionOutcome outcome = onProperty(environment, message, ENABLED_PROPERTY);
88-
if (outcome != null) {
89-
return outcome;
90-
}
91-
outcome = onProperty(environment, message, DEPRECATED_ENABLED_PROPERTY);
92-
if (outcome != null) {
93-
return outcome;
94-
}
95-
if (CloudPlatform.getActive(environment) == CloudPlatform.KUBERNETES) {
96-
return ConditionOutcome.match(message.because("running on Kubernetes"));
97-
}
98-
if (CloudPlatform.getActive(environment) == CloudPlatform.CLOUD_FOUNDRY) {
99-
return ConditionOutcome.match(message.because("running on Cloud Foundry"));
100-
}
101-
return ConditionOutcome.noMatch(message.because("not running on a supported cloud platform"));
102-
}
103-
104-
private @Nullable ConditionOutcome onProperty(Environment environment, ConditionMessage.Builder message,
105-
String propertyName) {
106-
String enabled = environment.getProperty(propertyName);
107-
if (enabled != null) {
108-
boolean match = !"false".equalsIgnoreCase(enabled);
109-
return new ConditionOutcome(match, message.because("'" + propertyName + "' set to '" + enabled + "'"));
110-
}
111-
return null;
112-
}
113-
114-
}
115-
11663
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"name": "management.endpoint.health.probes.enabled",
3535
"type": "java.lang.Boolean",
3636
"description": "Whether to enable liveness and readiness probes.",
37-
"defaultValue": false
37+
"defaultValue": true
3838
},
3939
{
4040
"name": "management.endpoint.health.status.order",
@@ -137,6 +137,7 @@
137137
"description": "Whether to enable liveness and readiness probes.",
138138
"defaultValue": false,
139139
"deprecation": {
140+
"level": "error",
140141
"replacement": "management.endpoint.health.probes.enabled"
141142
}
142143
},

module/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfigurationTests.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,8 @@ class AvailabilityProbesAutoConfigurationTests {
4141
AvailabilityHealthContributorAutoConfiguration.class, AvailabilityProbesAutoConfiguration.class));
4242

4343
@Test
44-
void probesWhenNotKubernetesAddsNoBeans() {
45-
this.contextRunner.run(this::doesNotHaveProbeBeans);
46-
}
47-
48-
@Test
49-
void probesWhenKubernetesAddsBeans() {
50-
this.contextRunner.withPropertyValues("spring.main.cloud-platform=kubernetes").run(this::hasProbesBeans);
51-
}
52-
53-
@Test
54-
void probesWhenCloudFoundryAddsBeans() {
55-
this.contextRunner.withPropertyValues("spring.main.cloud-platform=cloud_foundry").run(this::hasProbesBeans);
44+
void probesWhenDefaultAddsBeans() {
45+
this.contextRunner.run(this::hasProbesBeans);
5646
}
5747

5848
@Test
@@ -62,17 +52,14 @@ void probesWhenPropertyEnabledAddsBeans() {
6252
}
6353

6454
@Test
65-
void probesWhenPropertyEnabledButNoHealthDependencyDoesNotAddBeans() {
66-
this.contextRunner.withPropertyValues("management.endpoint.health.probes.enabled=true")
67-
.withClassLoader(new FilteredClassLoader("org.springframework.boot.health"))
55+
void probesWhenNoHealthDependencyDoesNotAddBeans() {
56+
this.contextRunner.withClassLoader(new FilteredClassLoader("org.springframework.boot.health"))
6857
.run(this::doesNotHaveProbeBeans);
6958
}
7059

7160
@Test
72-
void probesWhenKubernetesAndPropertyDisabledAddsNotBeans() {
73-
this.contextRunner
74-
.withPropertyValues("spring.main.cloud-platform=kubernetes",
75-
"management.endpoint.health.probes.enabled=false")
61+
void probesWhenPropertyDisabledAddsNotBeans() {
62+
this.contextRunner.withPropertyValues("management.endpoint.health.probes.enabled=false")
7663
.run(this::doesNotHaveProbeBeans);
7764
}
7865

smoke-test/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/AbstractManagementPortAndPathSampleActuatorApplicationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ void testHealth() {
6767
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
6868
.getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class);
6969
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
70-
assertThat(entity.getBody()).isEqualTo("{\"groups\":[\"comp\",\"live\",\"ready\"],\"status\":\"UP\"}");
70+
assertThat(entity.getBody())
71+
.isEqualTo("{\"groups\":[\"comp\",\"live\",\"liveness\",\"readiness\",\"ready\"],\"status\":\"UP\"}");
7172
}
7273

7374
@Test

smoke-test/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/SampleSecureWebFluxApplicationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void actuatorsAccessibleOnLogin() {
8787
.header("Authorization", getBasicAuth())
8888
.exchange()
8989
.expectBody(String.class)
90-
.isEqualTo("{\"status\":\"UP\"}");
90+
.isEqualTo("{\"groups\":[\"liveness\",\"readiness\"],\"status\":\"UP\"}");
9191
}
9292

9393
private String getBasicAuth() {

0 commit comments

Comments
 (0)