Browse Source
Prior to this commit, `HealthContributor` would be exposed under the main `HealthEndpoint` and subgroups, `HealthEndpointGroups`. Groups are driven by configuration properties and there was no way to contribute programmatically new groups. This commit introduces the `HealthEndpointGroupsRegistry` (a mutable version of `HealthEndpointGroups`) and a `HealthEndpointGroupsRegistryCustomizer`. This allows configurations to add/remove groups during Actuator auto-configuration. Closes gh-20554pull/20577/head
11 changed files with 485 additions and 107 deletions
138
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroups.java → spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupsRegistry.java
138
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroups.java → spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupsRegistry.java
9
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroup.java → spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/DefaultHealthEndpointGroup.java
9
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroup.java → spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/DefaultHealthEndpointGroup.java
@ -0,0 +1,110 @@
@@ -0,0 +1,110 @@
|
||||
/* |
||||
* 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.health; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
|
||||
import org.springframework.boot.actuate.health.HealthEndpointGroup; |
||||
import org.springframework.boot.actuate.health.HealthEndpointGroup.Show; |
||||
import org.springframework.boot.actuate.health.HealthEndpointGroupConfigurer; |
||||
import org.springframework.boot.actuate.health.HttpCodeStatusMapper; |
||||
import org.springframework.boot.actuate.health.StatusAggregator; |
||||
|
||||
/** |
||||
* Mutable {@link HealthEndpointGroupConfigurer configurer} for |
||||
* {@link HealthEndpointGroup}. |
||||
* |
||||
* @author Brian Clozel |
||||
*/ |
||||
class DefaultHealthEndpointGroupConfigurer implements HealthEndpointGroupConfigurer { |
||||
|
||||
Set<String> includedIndicators; |
||||
|
||||
Set<String> excludedIndicators; |
||||
|
||||
private StatusAggregator statusAggregator; |
||||
|
||||
private HttpCodeStatusMapper httpCodeStatusMapper; |
||||
|
||||
private Show showComponents; |
||||
|
||||
private Show showDetails; |
||||
|
||||
private Set<String> roles; |
||||
|
||||
DefaultHealthEndpointGroupConfigurer(StatusAggregator defaultStatusAggregator, |
||||
HttpCodeStatusMapper defaultHttpCodeStatusMapper, Show defaultShowComponents, Show defaultShowDetails, |
||||
Set<String> defaultRoles) { |
||||
this.statusAggregator = defaultStatusAggregator; |
||||
this.httpCodeStatusMapper = defaultHttpCodeStatusMapper; |
||||
this.showComponents = defaultShowComponents; |
||||
this.showDetails = defaultShowDetails; |
||||
this.roles = new HashSet<>(defaultRoles); |
||||
} |
||||
|
||||
@Override |
||||
public HealthEndpointGroupConfigurer include(String... indicators) { |
||||
this.includedIndicators = new HashSet<>(Arrays.asList(indicators)); |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public HealthEndpointGroupConfigurer exclude(String... exclude) { |
||||
this.excludedIndicators = new HashSet<>(Arrays.asList(exclude)); |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public HealthEndpointGroupConfigurer statusAggregator(StatusAggregator statusAggregator) { |
||||
this.statusAggregator = statusAggregator; |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public HealthEndpointGroupConfigurer httpCodeStatusMapper(HttpCodeStatusMapper httpCodeStatusMapper) { |
||||
this.httpCodeStatusMapper = httpCodeStatusMapper; |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public HealthEndpointGroupConfigurer showComponents(Show showComponents) { |
||||
this.showComponents = showComponents; |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public HealthEndpointGroupConfigurer showDetails(Show showDetails) { |
||||
this.showDetails = showDetails; |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public HealthEndpointGroupConfigurer roles(String... roles) { |
||||
this.roles = new HashSet<>(Arrays.asList(roles)); |
||||
return this; |
||||
} |
||||
|
||||
HealthEndpointGroup toHealthEndpointGroup() { |
||||
IncludeExcludeGroupMemberPredicate predicate = new IncludeExcludeGroupMemberPredicate(this.includedIndicators, |
||||
this.excludedIndicators); |
||||
return new DefaultHealthEndpointGroup(predicate, this.statusAggregator, this.httpCodeStatusMapper, |
||||
this.showComponents, this.showDetails, this.roles); |
||||
} |
||||
|
||||
} |
||||
10
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupsTests.java → spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupsBuilderTests.java
10
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupsTests.java → spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupsBuilderTests.java
98
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupTests.java → spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/DefaultHealthEndpointGroupTests.java
98
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupTests.java → spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/DefaultHealthEndpointGroupTests.java
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
/* |
||||
* 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.actuate.health; |
||||
|
||||
import org.springframework.boot.actuate.health.HealthEndpointGroup.Show; |
||||
|
||||
/** |
||||
* A configurer for customizing an {@link HealthEndpointGroup} being built. |
||||
* |
||||
* @author Brian Clozel |
||||
* @since 2.3.0 |
||||
*/ |
||||
public interface HealthEndpointGroupConfigurer { |
||||
|
||||
/** |
||||
* Configure the indicator endpoint ids to include in this group. |
||||
* @param indicators the indicator endpoint ids |
||||
* @return the configurer instance |
||||
*/ |
||||
HealthEndpointGroupConfigurer include(String... indicators); |
||||
|
||||
/** |
||||
* Configure the indicator endpoint ids to exclude from this group. |
||||
* @param indicators the indicator endpoint ids |
||||
* @return the configurer instance |
||||
*/ |
||||
HealthEndpointGroupConfigurer exclude(String... indicators); |
||||
|
||||
/** |
||||
* Configure the {@link StatusAggregator} to use for this group. |
||||
* <p> |
||||
* If none set, this will default to the globalmy configured {@link StatusAggregator}. |
||||
* @param statusAggregator the status aggregator |
||||
* @return the configurer instance |
||||
*/ |
||||
HealthEndpointGroupConfigurer statusAggregator(StatusAggregator statusAggregator); |
||||
|
||||
/** |
||||
* Configure the {@link HttpCodeStatusMapper} to use for this group. |
||||
* <p> |
||||
* If none set, this will default to the globalmy configured |
||||
* {@link HttpCodeStatusMapper}. |
||||
* @param httpCodeStatusMapper the status code mapper |
||||
* @return the configurer instance |
||||
*/ |
||||
HealthEndpointGroupConfigurer httpCodeStatusMapper(HttpCodeStatusMapper httpCodeStatusMapper); |
||||
|
||||
/** |
||||
* Configure the {@link Show visbility option} for showing components of this group. |
||||
* @param showComponents the components visibility |
||||
* @return the configurer instance |
||||
*/ |
||||
HealthEndpointGroupConfigurer showComponents(Show showComponents); |
||||
|
||||
/** |
||||
* Configure the {@link Show visbility option} for showing details of this group. |
||||
* @param showDetails the details visibility |
||||
* @return the configurer instance |
||||
*/ |
||||
HealthEndpointGroupConfigurer showDetails(Show showDetails); |
||||
|
||||
/** |
||||
* Configure roles used to determine whether or not a user is authorized to be shown |
||||
* details. |
||||
* @param roles the roles |
||||
* @return the configurer instance |
||||
*/ |
||||
HealthEndpointGroupConfigurer roles(String... roles); |
||||
|
||||
} |
||||
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
/* |
||||
* 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.actuate.health; |
||||
|
||||
import java.util.function.Consumer; |
||||
|
||||
/** |
||||
* Builder for an {@link HealthEndpointGroups} immutable instance. |
||||
* |
||||
* @author Brian Clozel |
||||
* @since 2.3.0 |
||||
*/ |
||||
public interface HealthEndpointGroupsRegistry extends HealthEndpointGroups { |
||||
|
||||
/** |
||||
* Add a new {@link HealthEndpointGroup}. |
||||
* @param groupName the name of the group to add |
||||
* @param builder the group to add |
||||
* @return the builder instance |
||||
*/ |
||||
HealthEndpointGroupsRegistry add(String groupName, Consumer<HealthEndpointGroupConfigurer> builder); |
||||
|
||||
/** |
||||
* Remove an existing {@link HealthEndpointGroup}. |
||||
* @param groupName the name of the group to remove |
||||
* @return the builder instance |
||||
*/ |
||||
HealthEndpointGroupsRegistry remove(String groupName); |
||||
|
||||
/** |
||||
* Build an immutable {@link HealthEndpointGroups}. |
||||
* @return the {@link HealthEndpointGroups} |
||||
*/ |
||||
HealthEndpointGroups toGroups(); |
||||
|
||||
} |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.actuate.health; |
||||
|
||||
/** |
||||
* Callback interface that can be used to customize a |
||||
* {@link HealthEndpointGroupsRegistry}. |
||||
* |
||||
* @author Brian Clozel |
||||
* @since 2.3.0 |
||||
*/ |
||||
@FunctionalInterface |
||||
public interface HealthEndpointGroupsRegistryCustomizer { |
||||
|
||||
/** |
||||
* Callback to customize a {@link HealthEndpointGroupsRegistry} instance. |
||||
* @param healthEndpointGroupsRegistry the registry to customize |
||||
*/ |
||||
void customize(HealthEndpointGroupsRegistry healthEndpointGroupsRegistry); |
||||
|
||||
} |
||||
Loading…
Reference in new issue