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 1/2] 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 { From e6eb02603c3dd26d127057ce203b5638c2273074 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 22 Jun 2020 22:59:37 -0700 Subject: [PATCH 2/2] Polish 'Inherit show-details property in health groups' Rework the inheritance so that the property metadata JSON more accurately reflects the default value. See gh-22022 --- .../health/HealthEndpointProperties.java | 20 ++++++++++++++++--- .../health/HealthProperties.java | 15 ++------------ ...toConfiguredHealthEndpointGroupsTests.java | 4 ++-- 3 files changed, 21 insertions(+), 18 deletions(-) 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 cef5d13e68..6ccf2ae5a1 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,11 +33,25 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties("management.endpoint.health") public class HealthEndpointProperties extends HealthProperties { + /** + * When to show full health details. + */ + private Show showDetails = Show.NEVER; + /** * Health endpoint groups. */ private Map group = new LinkedHashMap<>(); + @Override + public Show getShowDetails() { + return this.showDetails; + } + + public void setShowDetails(Show showDetails) { + this.showDetails = showDetails; + } + public Map getGroup() { return this.group; } @@ -58,7 +72,8 @@ public class HealthEndpointProperties extends HealthProperties { private Set exclude; /** - * The default value of this field should be null for group. + * When to show full health details. Defaults to the value of + * 'management.endpoint.health.show-details'. */ private Show showDetails; @@ -83,7 +98,6 @@ public class HealthEndpointProperties extends HealthProperties { return this.showDetails; } - @Override public void setShowDetails(Show showDetails) { this.showDetails = showDetails; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthProperties.java index 901c4031d5..8603f79aa5 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,11 +43,6 @@ public abstract class HealthProperties { */ private Show showComponents; - /** - * When to show full health details. - */ - private Show showDetails = Show.NEVER; - /** * Roles used to determine whether or not a user is authorized to be shown details. * When empty, all authenticated users are authorized. @@ -66,13 +61,7 @@ public abstract class HealthProperties { this.showComponents = showComponents; } - public Show getShowDetails() { - return this.showDetails; - } - - public void setShowDetails(Show showDetails) { - this.showDetails = showDetails; - } + public abstract Show getShowDetails(); public Set getRoles() { return this.roles; 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 3f410bdd03..c9782e2cb5 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -310,7 +310,7 @@ class AutoConfiguredHealthEndpointGroupsTests { } @Test - void createWhenNoDefinedGroupsShowDetails() { + void createWhenGroupWithNoShowDetailsOverrideInheritsShowDetails() { this.contextRunner.withPropertyValues("management.endpoint.health.show-details=always", "management.endpoint.health.group.a.include=*").run((context) -> { HealthEndpointGroups groups = context.getBean(HealthEndpointGroups.class);