diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpointSupport.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpointSupport.java index 6a3bd7d0cd..b0e97c8f84 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpointSupport.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpointSupport.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. @@ -81,7 +81,7 @@ abstract class HealthEndpointSupport { } Object contributor = getContributor(path, pathOffset); T health = getContribution(apiVersion, group, contributor, showComponents, showDetails, - isSystemHealth ? this.groups.getNames() : null); + isSystemHealth ? this.groups.getNames() : null, false); return (health != null) ? new HealthResult<>(health, group) : null; } @@ -100,23 +100,24 @@ abstract class HealthEndpointSupport { @SuppressWarnings("unchecked") private T getContribution(ApiVersion apiVersion, HealthEndpointGroup group, Object contributor, - boolean showComponents, boolean showDetails, Set groupNames) { + boolean showComponents, boolean showDetails, Set groupNames, boolean isNested) { if (contributor instanceof NamedContributors) { return getAggregateHealth(apiVersion, group, (NamedContributors) contributor, showComponents, - showDetails, groupNames); + showDetails, groupNames, isNested); } return (contributor != null) ? getHealth((C) contributor, showDetails) : null; } private T getAggregateHealth(ApiVersion apiVersion, HealthEndpointGroup group, - NamedContributors namedContributors, boolean showComponents, boolean showDetails, - Set groupNames) { + NamedContributors namedContributors, boolean showComponents, boolean showDetails, Set groupNames, + boolean isNested) { Map contributions = new LinkedHashMap<>(); for (NamedContributor namedContributor : namedContributors) { String name = namedContributor.getName(); C contributor = namedContributor.getContributor(); - if (group.isMember(name)) { - T contribution = getContribution(apiVersion, group, contributor, showComponents, showDetails, null); + if (group.isMember(name) || isNested) { + T contribution = getContribution(apiVersion, group, contributor, showComponents, showDetails, null, + true); if (contribution != null) { contributions.put(name, contribution); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointSupportTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointSupportTests.java index 2f65c871db..be2a326b45 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointSupportTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointSupportTests.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. @@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @param the contributor type * @param the contributed health component type * @author Phillip Webb + * @author Madhura Bhave */ abstract class HealthEndpointSupportTests, C, T> { @@ -215,6 +216,20 @@ abstract class HealthEndpointSupportTests, C, T assertThat(result).isNull(); } + @Test + void getHealthWhenGroupContainsCompositeContributorReturnsHealth() { + C contributor = createContributor(this.up); + C compositeContributor = createCompositeContributor(Collections.singletonMap("spring", contributor)); + this.registry.registerContributor("test", compositeContributor); + TestHealthEndpointGroup testGroup = new TestHealthEndpointGroup((name) -> name.startsWith("test")); + HealthEndpointGroups groups = HealthEndpointGroups.of(this.primaryGroup, + Collections.singletonMap("testGroup", testGroup)); + HealthResult result = create(this.registry, groups).getHealth(ApiVersion.V3, SecurityContext.NONE, false, + "testGroup"); + CompositeHealth health = (CompositeHealth) getHealth(result); + assertThat(health.getComponents()).containsKey("test"); + } + protected abstract HealthEndpointSupport create(R registry, HealthEndpointGroups groups); protected abstract R createRegistry();