Skip to content

Commit 19b7dc8

Browse files
committed
Merge branch '2.2.x'
Closes gh-20114
2 parents ec42dcd + d485708 commit 19b7dc8

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpointSupport.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private HealthResult<T> getHealth(ApiVersion apiVersion, HealthEndpointGroup gro
7272
}
7373
Object contributor = getContributor(path, pathOffset);
7474
T health = getContribution(apiVersion, group, contributor, showComponents, showDetails,
75-
isSystemHealth ? this.groups.getNames() : null);
75+
isSystemHealth ? this.groups.getNames() : null, false);
7676
return (health != null) ? new HealthResult<>(health, group) : null;
7777
}
7878

@@ -91,23 +91,24 @@ private Object getContributor(String[] path, int pathOffset) {
9191

9292
@SuppressWarnings("unchecked")
9393
private T getContribution(ApiVersion apiVersion, HealthEndpointGroup group, Object contributor,
94-
boolean showComponents, boolean showDetails, Set<String> groupNames) {
94+
boolean showComponents, boolean showDetails, Set<String> groupNames, boolean isNested) {
9595
if (contributor instanceof NamedContributors) {
9696
return getAggregateHealth(apiVersion, group, (NamedContributors<C>) contributor, showComponents,
97-
showDetails, groupNames);
97+
showDetails, groupNames, isNested);
9898
}
9999
return (contributor != null) ? getHealth((C) contributor, showDetails) : null;
100100
}
101101

102102
private T getAggregateHealth(ApiVersion apiVersion, HealthEndpointGroup group,
103-
NamedContributors<C> namedContributors, boolean showComponents, boolean showDetails,
104-
Set<String> groupNames) {
103+
NamedContributors<C> namedContributors, boolean showComponents, boolean showDetails, Set<String> groupNames,
104+
boolean isNested) {
105105
Map<String, T> contributions = new LinkedHashMap<>();
106106
for (NamedContributor<C> namedContributor : namedContributors) {
107107
String name = namedContributor.getName();
108108
C contributor = namedContributor.getContributor();
109-
if (group.isMember(name)) {
110-
T contribution = getContribution(apiVersion, group, contributor, showComponents, showDetails, null);
109+
if (group.isMember(name) || isNested) {
110+
T contribution = getContribution(apiVersion, group, contributor, showComponents, showDetails, null,
111+
true);
111112
if (contribution != null) {
112113
contributions.put(name, contribution);
113114
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointSupportTests.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@
3838
* @param <C> the contributor type
3939
* @param <T> the contributed health component type
4040
* @author Phillip Webb
41+
* @author Madhura Bhave
4142
*/
4243
abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T> {
4344

@@ -215,6 +216,20 @@ void getHealthWithEmptyCompositeReturnsNullResult() { // gh-18687
215216
assertThat(result).isNull();
216217
}
217218

219+
@Test
220+
void getHealthWhenGroupContainsCompositeContributorReturnsHealth() {
221+
C contributor = createContributor(this.up);
222+
C compositeContributor = createCompositeContributor(Collections.singletonMap("spring", contributor));
223+
this.registry.registerContributor("test", compositeContributor);
224+
TestHealthEndpointGroup testGroup = new TestHealthEndpointGroup((name) -> name.startsWith("test"));
225+
HealthEndpointGroups groups = HealthEndpointGroups.of(this.primaryGroup,
226+
Collections.singletonMap("testGroup", testGroup));
227+
HealthResult<T> result = create(this.registry, groups).getHealth(ApiVersion.V3, SecurityContext.NONE, false,
228+
"testGroup");
229+
CompositeHealth health = (CompositeHealth) getHealth(result);
230+
assertThat(health.getComponents()).containsKey("test");
231+
}
232+
218233
protected abstract HealthEndpointSupport<C, T> create(R registry, HealthEndpointGroups groups);
219234

220235
protected abstract R createRegistry();

0 commit comments

Comments
 (0)