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
This commit is contained in:
Leo Li 2020-06-19 17:27:53 +08:00 committed by Phillip Webb
parent bf04baba73
commit 10de88884f
2 changed files with 27 additions and 0 deletions

View File

@ -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<String> exclude;
/**
* The default value of this field should be null for group.
*/
private Show showDetails;
public Set<String> 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;
}
}
}

View File

@ -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 {