From 10de88884f70d342eb7d5c31a251a63d69fadb1f Mon Sep 17 00:00:00 2001 From: Leo Li <269739606@qq.com> Date: Fri, 19 Jun 2020 17:27:53 +0800 Subject: [PATCH] Inherit show-details property in health groups Update `Group` properties so that the `showDetails` value does not inherit `Show.NEVER`. Prior to this commit, the `Group` properties would not correctly inherit a `showDetails` value from the main `management.endpoint.health.show-details` property. See gh-22022 --- .../health/HealthEndpointProperties.java | 16 ++++++++++++++++ .../AutoConfiguredHealthEndpointGroupsTests.java | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java index d2b6d9c467..cef5d13e68 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java @@ -27,6 +27,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * Configuration properties for {@link HealthEndpoint}. * * @author Phillip Webb + * @author Leo Li * @since 2.0.0 */ @ConfigurationProperties("management.endpoint.health") @@ -56,6 +57,11 @@ public class HealthEndpointProperties extends HealthProperties { */ private Set exclude; + /** + * The default value of this field should be null for group. + */ + private Show showDetails; + public Set getInclude() { return this.include; } @@ -72,6 +78,16 @@ public class HealthEndpointProperties extends HealthProperties { this.exclude = exclude; } + @Override + public Show getShowDetails() { + return this.showDetails; + } + + @Override + public void setShowDetails(Show showDetails) { + this.showDetails = showDetails; + } + } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupsTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupsTests.java index b63154031a..3f410bdd03 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupsTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupsTests.java @@ -43,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link AutoConfiguredHealthEndpointGroups}. * * @author Phillip Webb + * @author Leo Li */ class AutoConfiguredHealthEndpointGroupsTests { @@ -308,6 +309,16 @@ class AutoConfiguredHealthEndpointGroupsTests { }); } + @Test + void createWhenNoDefinedGroupsShowDetails() { + this.contextRunner.withPropertyValues("management.endpoint.health.show-details=always", + "management.endpoint.health.group.a.include=*").run((context) -> { + HealthEndpointGroups groups = context.getBean(HealthEndpointGroups.class); + HealthEndpointGroup groupA = groups.get("a"); + assertThat(groupA.showDetails(SecurityContext.NONE)).isTrue(); + }); + } + @Configuration(proxyBeanMethods = false) @EnableConfigurationProperties(HealthEndpointProperties.class) static class AutoConfiguredHealthEndpointGroupsTestConfiguration {