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
pull/22138/head
Leo Li 4 years ago committed by Phillip Webb
parent bf04baba73
commit 10de88884f

@ -27,6 +27,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* Configuration properties for {@link HealthEndpoint}. * Configuration properties for {@link HealthEndpoint}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Leo Li
* @since 2.0.0 * @since 2.0.0
*/ */
@ConfigurationProperties("management.endpoint.health") @ConfigurationProperties("management.endpoint.health")
@ -56,6 +57,11 @@ public class HealthEndpointProperties extends HealthProperties {
*/ */
private Set<String> exclude; private Set<String> exclude;
/**
* The default value of this field should be null for group.
*/
private Show showDetails;
public Set<String> getInclude() { public Set<String> getInclude() {
return this.include; return this.include;
} }
@ -72,6 +78,16 @@ public class HealthEndpointProperties extends HealthProperties {
this.exclude = exclude; this.exclude = exclude;
} }
@Override
public Show getShowDetails() {
return this.showDetails;
}
@Override
public void setShowDetails(Show showDetails) {
this.showDetails = showDetails;
}
} }
} }

@ -43,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link AutoConfiguredHealthEndpointGroups}. * Tests for {@link AutoConfiguredHealthEndpointGroups}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Leo Li
*/ */
class AutoConfiguredHealthEndpointGroupsTests { 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) @Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(HealthEndpointProperties.class) @EnableConfigurationProperties(HealthEndpointProperties.class)
static class AutoConfiguredHealthEndpointGroupsTestConfiguration { static class AutoConfiguredHealthEndpointGroupsTestConfiguration {

Loading…
Cancel
Save