diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java index 585fe7a2199..a5d634ca46c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java @@ -44,7 +44,7 @@ class IncludeExcludeGroupMemberPredicate implements Predicate { } private boolean isIncluded(String name) { - return this.include.contains("*") || this.include.contains(clean(name)); + return this.include.isEmpty() || this.include.contains("*") || this.include.contains(clean(name)); } private boolean isExcluded(String name) { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicateTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicateTests.java index 7944ac6251d..c9080c89b16 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicateTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicateTests.java @@ -17,6 +17,7 @@ package org.springframework.boot.actuate.autoconfigure.health; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; import java.util.function.Predicate; @@ -29,13 +30,14 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link IncludeExcludeGroupMemberPredicate}. * * @author Phillip Webb + * @author Madhura Bhave */ class IncludeExcludeGroupMemberPredicateTests { @Test - void testWhenEmptyIncludeAndExcludeRejectsAll() { + void testWhenEmptyIncludeAndExcludeAcceptsAll() { Predicate predicate = new IncludeExcludeGroupMemberPredicate(null, null); - assertThat(predicate).rejects("a", "b", "c"); + assertThat(predicate).accepts("a", "b", "c"); } @Test @@ -44,6 +46,12 @@ class IncludeExcludeGroupMemberPredicateTests { assertThat(predicate).accepts("a", "b", "c"); } + @Test + void testWhenEmptyIncludeAndNonEmptyExcludeAcceptsAllButExclude() { + Predicate predicate = new IncludeExcludeGroupMemberPredicate(null, Collections.singleton("c")); + assertThat(predicate).accepts("a", "b"); + } + @Test void testWhenStarIncludeAndSpecificExcludeDoesNotAcceptExclude() { Predicate predicate = include("*").exclude("c"); diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc index 1522f4afbcc..f7987affaee 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc @@ -881,6 +881,13 @@ For example, to create a group that includes only database indicators you can de You can then check the result by hitting `http://localhost:8080/actuator/health/custom`. +Similarly, to create a group that excludes the database indicators from the group and includes all the other indicators, you can define the following: + +[source,properties,indent=0,configprops] +---- + management.endpoint.health.group.custom.exclude=db +---- + By default groups will inherit the same `StatusAggregator` and `HttpCodeStatusMapper` settings as the system health, however, these can also be defined on a per-group basis. It's also possible to override the `show-details` and `roles` properties if required: