Allow exclude only health groups

Closes gh-22053
pull/22631/head
Madhura Bhave 4 years ago
parent 8d70010fce
commit 4b2c94cb2b

@ -44,7 +44,7 @@ class IncludeExcludeGroupMemberPredicate implements Predicate<String> {
}
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) {

@ -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<String> 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<String> predicate = new IncludeExcludeGroupMemberPredicate(null, Collections.singleton("c"));
assertThat(predicate).accepts("a", "b");
}
@Test
void testWhenStarIncludeAndSpecificExcludeDoesNotAcceptExclude() {
Predicate<String> predicate = include("*").exclude("c");

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

Loading…
Cancel
Save