Filter empty health contributions
Update `HealthEndpointSupport` so that aggregate elements that don't ultimately provide a contribution are filtered out. Prior to this commit an NPE was returned when calculating the aggregate status. Fixes gh-18687
This commit is contained in:
parent
6378863771
commit
7c9ac03014
|
|
@ -112,10 +112,12 @@ abstract class HealthEndpointSupport<C, T> {
|
|||
Map<String, T> contributions = new LinkedHashMap<>();
|
||||
for (NamedContributor<C> namedContributor : namedContributors) {
|
||||
String name = namedContributor.getName();
|
||||
C contributor = namedContributor.getContributor();
|
||||
if (group.isMember(name)) {
|
||||
T contribution = getContribution(apiVersion, group, namedContributor.getContributor(), showComponents,
|
||||
showDetails, null);
|
||||
contributions.put(name, contribution);
|
||||
T contribution = getContribution(apiVersion, group, contributor, showComponents, showDetails, null);
|
||||
if (contribution != null) {
|
||||
contributions.put(name, contribution);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (contributions.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -207,6 +207,14 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
|||
assertThat(getHealth(result)).isNotInstanceOf(SystemHealth.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getHealthWithEmptyCompositeReturnsNullResult() { // gh-18687
|
||||
this.registry.registerContributor("test", createCompositeContributor(Collections.emptyMap()));
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
|
||||
false);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
protected abstract HealthEndpointSupport<C, T> create(R registry, HealthEndpointGroups groups);
|
||||
|
||||
protected abstract R createRegistry();
|
||||
|
|
|
|||
Loading…
Reference in New Issue