Skip to content

Commit fd0293c

Browse files
committed
Merge pull request #12106 from jkschneider:simple-enable
* pr/12106: Polish "Restore behavior of management.metrics.export.simple.enabled" Restore behavior of management.metrics.export.simple.enabled
2 parents 19ce68d + 1dab83a commit fd0293c

File tree

7 files changed

+34
-19
lines changed

7 files changed

+34
-19
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2929
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
3030
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
31+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
3132
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3233
import org.springframework.context.annotation.Bean;
3334
import org.springframework.context.annotation.Configuration;
@@ -46,6 +47,7 @@
4647
@ConditionalOnBean(Clock.class)
4748
@EnableConfigurationProperties(SimpleProperties.class)
4849
@ConditionalOnMissingBean(MeterRegistry.class)
50+
@ConditionalOnProperty(name = "management.metrics.export.simple.enabled", havingValue = "true", matchIfMissing = true)
4951
public class SimpleMetricsExportAutoConfiguration {
5052

5153
@Bean

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleProperties.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@
3333
@ConfigurationProperties(prefix = "management.metrics.export.simple")
3434
public class SimpleProperties {
3535

36-
/**
37-
* Enable publishing to the backend.
38-
*/
39-
private boolean enabled;
40-
4136
/**
4237
* Step size (i.e. reporting frequency) to use.
4338
*/
@@ -48,14 +43,6 @@ public class SimpleProperties {
4843
*/
4944
private CountingMode mode = CountingMode.CUMULATIVE;
5045

51-
public boolean getEnabled() {
52-
return this.enabled;
53-
}
54-
55-
public void setEnabled(boolean enabled) {
56-
this.enabled = enabled;
57-
}
58-
5946
public Duration getStep() {
6047
return this.step;
6148
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapter.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ public String get(String k) {
4141
return null;
4242
}
4343

44-
@Override
45-
public boolean enabled() {
46-
return get(SimpleProperties::getEnabled, SimpleConfig.super::enabled);
47-
}
48-
4944
@Override
5045
public Duration step() {
5146
return get(SimpleProperties::getStep, SimpleConfig.super::step);

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@
215215
"description": "Whether to enable uptime metrics.",
216216
"defaultValue": true
217217
},
218+
{
219+
"name": "management.metrics.export.simple.enabled",
220+
"type": "java.lang.Boolean",
221+
"description": "Whether, in the absence of any other exporter, exporting of metrics to an in-memory backend is enabled.",
222+
"defaultValue": true
223+
},
218224
{
219225
"name": "management.trace.http.enabled",
220226
"type": "java.lang.Boolean",

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfigurationTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ public void autoConfiguresConfigAndMeterRegistry() {
5151
.hasSingleBean(Clock.class).hasSingleBean(SimpleConfig.class));
5252
}
5353

54+
@Test
55+
public void backsOffWhenSpecificallyDisabled() {
56+
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
57+
.withPropertyValues("management.metrics.export.simple.enabled=false")
58+
.run((context) -> assertThat(context)
59+
.doesNotHaveBean(SimpleMeterRegistry.class)
60+
.doesNotHaveBean(SimpleConfig.class));
61+
}
62+
5463
@Test
5564
public void allowsConfigToBeCustomized() {
5665
this.contextRunner.withUserConfiguration(CustomConfigConfiguration.class)

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ content into your application. Rather, pick only the properties that you need.
13841384
management.metrics.export.signalfx.uri= # Optional custom URI for the SignalFX API.
13851385
management.metrics.export.simple.mode=cumulative # Counting mode.
13861386
management.metrics.export.simple.step=10s # Step size (i.e. reporting frequency) to use.
1387-
management.metrics.export.statsd.enabled= # Whether exporting of metrics to this backend is enabled.
1387+
management.metrics.export.statsd.enabled=true # Whether, in the absence of any other exporter, exporting of metrics to an in-memory backend is enabled.
13881388
management.metrics.export.statsd.flavor=datadog # StatsD line protocol to use.
13891389
management.metrics.export.statsd.host=localhost # Host of the StatsD server to receive exported metrics.
13901390
management.metrics.export.statsd.max-packet-length=1400 # Total length of a single payload should be kept within your network's MTU.

spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,22 @@ using:
12721272

12731273

12741274

1275+
[[production-ready-metrics-export-simple]]
1276+
==== Simple
1277+
Micrometer ships with a simple, in-memory backend that is automatically used as a fallback
1278+
if no other registry is configured. This allows you to see what metrics are collected in
1279+
the <<production-ready-metrics-endpoint,metrics endpoint>>.
1280+
1281+
The in-memory backend disables itself as soon as you're using any of the other available
1282+
backend. You can also disable it explicitly:
1283+
1284+
[source,properties,indent=0]
1285+
----
1286+
management.metrics.export.simple.enabled=false
1287+
----
1288+
1289+
1290+
12751291
[[production-ready-metrics-export-newrelic]]
12761292
==== New Relic
12771293
New Relic registry pushes metrics to New Relic periodically. To export metrics to

0 commit comments

Comments
 (0)