Disable the java info contributor by default
Closes gh-28310 Co-authored-by Phillip Webb <pwebb@vmware.com>
This commit is contained in:
parent
f2b3f1f41f
commit
f98c1e7231
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -54,7 +54,7 @@ public abstract class OnEndpointElementCondition extends SpringBootCondition {
|
||||||
if (outcome != null) {
|
if (outcome != null) {
|
||||||
return outcome;
|
return outcome;
|
||||||
}
|
}
|
||||||
return getDefaultEndpointsOutcome(context);
|
return getDefaultOutcome(context, annotationAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ConditionOutcome getEndpointOutcome(ConditionContext context, String endpointName) {
|
protected ConditionOutcome getEndpointOutcome(ConditionContext context, String endpointName) {
|
||||||
|
|
@ -68,6 +68,27 @@ public abstract class OnEndpointElementCondition extends SpringBootCondition {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the default outcome that should be used if not property is set. By default
|
||||||
|
* this method will use the {@code <prefix>.defaults.enabled} property, matching if it
|
||||||
|
* is {@code true} or if it is not configured.
|
||||||
|
* @param context the condition context
|
||||||
|
* @param annotationAttributes the annotation attributes
|
||||||
|
* @return the default outcome
|
||||||
|
* @since 2.6.0
|
||||||
|
*/
|
||||||
|
protected ConditionOutcome getDefaultOutcome(ConditionContext context, AnnotationAttributes annotationAttributes) {
|
||||||
|
return getDefaultEndpointsOutcome(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the default outcome that should be used.
|
||||||
|
* @param context the condition context
|
||||||
|
* @return the default outcome
|
||||||
|
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
||||||
|
* {@link #getDefaultOutcome(ConditionContext, AnnotationAttributes)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
protected ConditionOutcome getDefaultEndpointsOutcome(ConditionContext context) {
|
protected ConditionOutcome getDefaultEndpointsOutcome(ConditionContext context) {
|
||||||
boolean match = Boolean
|
boolean match = Boolean
|
||||||
.parseBoolean(context.getEnvironment().getProperty(this.prefix + "defaults.enabled", "true"));
|
.parseBoolean(context.getEnvironment().getProperty(this.prefix + "defaults.enabled", "true"));
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -25,11 +25,9 @@ import java.lang.annotation.Target;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Conditional @Conditional} that checks whether or not a default info contributor
|
* {@link Conditional @Conditional} that checks whether or not an info contributor is
|
||||||
* is enabled. Matches if the value of the {@code management.info.<name>.enabled} property
|
* enabled. Matches if the value of the {@code management.info.<name>.enabled} property is
|
||||||
* is {@code true}. Otherwise, matches if the value of the
|
* {@code true}. Otherwise, use the specific {@link #fallback() fallback} method.
|
||||||
* {@code management.info.defaults.enabled} property is {@code true} or if it is not
|
|
||||||
* configured.
|
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
|
|
@ -46,4 +44,10 @@ public @interface ConditionalOnEnabledInfoContributor {
|
||||||
*/
|
*/
|
||||||
String value();
|
String value();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fallback behavior when {@code management.info.<name>.enabled} has not been set.
|
||||||
|
* @return the fallback behavior
|
||||||
|
*/
|
||||||
|
InfoContributorFallback fallback() default InfoContributorFallback.USE_DEFAULTS_PROPERTY;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ public class InfoContributorAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnEnabledInfoContributor("java")
|
@ConditionalOnEnabledInfoContributor(value = "java", fallback = InfoContributorFallback.DISABLE)
|
||||||
@Order(DEFAULT_ORDER)
|
@Order(DEFAULT_ORDER)
|
||||||
public JavaInfoContributor javaInfoContributor() {
|
public JavaInfoContributor javaInfoContributor() {
|
||||||
return new JavaInfoContributor();
|
return new JavaInfoContributor();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2021 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.info;
|
||||||
|
|
||||||
|
import org.springframework.boot.actuate.autoconfigure.OnEndpointElementCondition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls the fallback behavior when the primary property that controls whether an info
|
||||||
|
* contributor is enabled is not set.
|
||||||
|
*
|
||||||
|
* @author Andy Wilkinson
|
||||||
|
* @since 2.6.0
|
||||||
|
* @see OnEndpointElementCondition
|
||||||
|
*/
|
||||||
|
public enum InfoContributorFallback {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fall back to the {@code management.info.defaults.enabled} property, matching if it
|
||||||
|
* is {@code true} or if it is not configured.
|
||||||
|
*/
|
||||||
|
USE_DEFAULTS_PROPERTY,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not fall back, thereby disabling the info contributor.
|
||||||
|
*/
|
||||||
|
DISABLE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,7 +17,11 @@
|
||||||
package org.springframework.boot.actuate.autoconfigure.info;
|
package org.springframework.boot.actuate.autoconfigure.info;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.OnEndpointElementCondition;
|
import org.springframework.boot.actuate.autoconfigure.OnEndpointElementCondition;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||||
import org.springframework.context.annotation.Condition;
|
import org.springframework.context.annotation.Condition;
|
||||||
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
|
import org.springframework.core.annotation.AnnotationAttributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Condition} that checks if an info indicator is enabled.
|
* {@link Condition} that checks if an info indicator is enabled.
|
||||||
|
|
@ -30,4 +34,14 @@ class OnEnabledInfoContributorCondition extends OnEndpointElementCondition {
|
||||||
super("management.info.", ConditionalOnEnabledInfoContributor.class);
|
super("management.info.", ConditionalOnEnabledInfoContributor.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ConditionOutcome getDefaultOutcome(ConditionContext context, AnnotationAttributes annotationAttributes) {
|
||||||
|
InfoContributorFallback fallback = annotationAttributes.getEnum("fallback");
|
||||||
|
if (fallback == InfoContributorFallback.DISABLE) {
|
||||||
|
return new ConditionOutcome(false, ConditionMessage.forCondition(ConditionalOnEnabledInfoContributor.class)
|
||||||
|
.because("management.info." + annotationAttributes.getString("value") + ".enabled is not true"));
|
||||||
|
}
|
||||||
|
return super.getDefaultOutcome(context, annotationAttributes);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -273,6 +273,12 @@
|
||||||
"name": "management.info.git.mode",
|
"name": "management.info.git.mode",
|
||||||
"defaultValue": "simple"
|
"defaultValue": "simple"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "management.info.java.enabled",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "Whether to enable Java info.",
|
||||||
|
"defaultValue": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "management.metrics.binders.files.enabled",
|
"name": "management.metrics.binders.files.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
|
|
|
||||||
|
|
@ -54,18 +54,11 @@ class InfoContributorAutoConfigurationTests {
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(EnvironmentInfoContributor.class));
|
.run((context) -> assertThat(context).doesNotHaveBean(EnvironmentInfoContributor.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void disableJavaContributor() {
|
|
||||||
this.contextRunner.withPropertyValues("management.info.java.enabled=false")
|
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(JavaInfoContributor.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void defaultInfoContributorsEnabled() {
|
void defaultInfoContributorsEnabled() {
|
||||||
this.contextRunner.run((context) -> {
|
this.contextRunner.run((context) -> {
|
||||||
assertThat(context).hasSingleBean(EnvironmentInfoContributor.class)
|
assertThat(context).hasSingleBean(EnvironmentInfoContributor.class);
|
||||||
.hasSingleBean(JavaInfoContributor.class);
|
assertThat(context.getBeansOfType(InfoContributor.class)).hasSize(1);
|
||||||
assertThat(context.getBeansOfType(InfoContributor.class)).hasSize(2);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,7 +139,7 @@ class InfoContributorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void javaInfoContributor() {
|
void javaInfoContributor() {
|
||||||
this.contextRunner.run((context) -> {
|
this.contextRunner.withPropertyValues("management.info.java.enabled=true").run((context) -> {
|
||||||
assertThat(context).hasSingleBean(JavaInfoContributor.class);
|
assertThat(context).hasSingleBean(JavaInfoContributor.class);
|
||||||
Map<String, Object> content = invokeContributor(context.getBean(JavaInfoContributor.class));
|
Map<String, Object> content = invokeContributor(context.getBean(JavaInfoContributor.class));
|
||||||
assertThat(content).containsKey("java");
|
assertThat(content).containsKey("java");
|
||||||
|
|
|
||||||
|
|
@ -1145,24 +1145,41 @@ Spring Boot includes a number of auto-configured `InfoContributor` beans, and yo
|
||||||
==== Auto-configured InfoContributors
|
==== Auto-configured InfoContributors
|
||||||
When appropriate, Spring auto-configures the following `InfoContributor` beans:
|
When appropriate, Spring auto-configures the following `InfoContributor` beans:
|
||||||
|
|
||||||
[cols="1,4"]
|
[cols="1,4,8,4"]
|
||||||
|===
|
|===
|
||||||
| Name | Description
|
| ID | Name | Description | Prequisites
|
||||||
|
|
||||||
| {spring-boot-actuator-module-code}/info/EnvironmentInfoContributor.java[`EnvironmentInfoContributor`]
|
|
||||||
| Exposes any key from the `Environment` under the `info` key.
|
|
||||||
|
|
||||||
| {spring-boot-actuator-module-code}/info/GitInfoContributor.java[`GitInfoContributor`]
|
|
||||||
| Exposes git information if a `git.properties` file is available.
|
|
||||||
|
|
||||||
|
| `build`
|
||||||
| {spring-boot-actuator-module-code}/info/BuildInfoContributor.java[`BuildInfoContributor`]
|
| {spring-boot-actuator-module-code}/info/BuildInfoContributor.java[`BuildInfoContributor`]
|
||||||
| Exposes build information if a `META-INF/build-info.properties` file is available.
|
| Exposes build information.
|
||||||
|
| A `META-INF/build-info.properties` resource.
|
||||||
|
|
||||||
|
| `env`
|
||||||
|
| {spring-boot-actuator-module-code}/info/EnvironmentInfoContributor.java[`EnvironmentInfoContributor`]
|
||||||
|
| Exposes any property from the `Environment` whose name starts with `info.`.
|
||||||
|
| None.
|
||||||
|
|
||||||
|
| `git`
|
||||||
|
| {spring-boot-actuator-module-code}/info/GitInfoContributor.java[`GitInfoContributor`]
|
||||||
|
| Exposes git information.
|
||||||
|
| A `git.properties` resource.
|
||||||
|
|
||||||
|
| `java`
|
||||||
| {spring-boot-actuator-module-code}/info/JavaInfoContributor.java[`JavaInfoContributor`]
|
| {spring-boot-actuator-module-code}/info/JavaInfoContributor.java[`JavaInfoContributor`]
|
||||||
| Exposes Java runtime information under the `java` key.
|
| Exposes Java runtime information.
|
||||||
|
| None.
|
||||||
|
|
||||||
|===
|
|===
|
||||||
|
|
||||||
TIP: You can disable them all by setting the configprop:management.info.defaults.enabled[] property.
|
Whether or not an individual contributor is enabled is controlled by its `management.info.<id>.enabled` property.
|
||||||
|
Different contributors have different defaults for this property, depending on their prerequisites and the nature of the information that they expose.
|
||||||
|
|
||||||
|
With no prequisites to indicate that it should be enabled, the `java` contributor is disabled by default.
|
||||||
|
You can enable it by setting the configprop:management.info.java.enabled[] property to `true`.
|
||||||
|
|
||||||
|
The `env`, `git`, and `build` info contributors are enabled by default.
|
||||||
|
Each can be disabled by setting its `management.info.<id>.enabled` property to `false`.
|
||||||
|
Alternatively, to disable every contributor that is usually enabled by default, set the configprop:management.info.defaults.enabled[] property to `false`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue