diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaMetricsExportAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaMetricsExportAutoConfiguration.java index 8c65b5e17f..a1c5d43766 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaMetricsExportAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaMetricsExportAutoConfiguration.java @@ -17,7 +17,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.ganglia; import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.util.HierarchicalNameMapper; import io.micrometer.ganglia.GangliaConfig; import io.micrometer.ganglia.GangliaMeterRegistry; @@ -60,14 +59,8 @@ public class GangliaMetricsExportAutoConfiguration { @Bean @ConditionalOnMissingBean public GangliaMeterRegistry gangliaMeterRegistry(GangliaConfig gangliaConfig, - HierarchicalNameMapper nameMapper, Clock clock) { - return new GangliaMeterRegistry(gangliaConfig, clock, nameMapper); - } - - @Bean - @ConditionalOnMissingBean - public HierarchicalNameMapper hierarchicalNameMapper() { - return HierarchicalNameMapper.DEFAULT; + Clock clock) { + return new GangliaMeterRegistry(gangliaConfig, clock); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfiguration.java index 67b4710585..37c8a1a014 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfiguration.java @@ -17,9 +17,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.graphite; import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.util.HierarchicalNameMapper; import io.micrometer.graphite.GraphiteConfig; -import io.micrometer.graphite.GraphiteHierarchicalNameMapper; import io.micrometer.graphite.GraphiteMeterRegistry; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; @@ -61,14 +59,8 @@ public class GraphiteMetricsExportAutoConfiguration { @Bean @ConditionalOnMissingBean public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig graphiteConfig, - HierarchicalNameMapper nameMapper, Clock clock) { - return new GraphiteMeterRegistry(graphiteConfig, clock, nameMapper); - } - - @Bean - @ConditionalOnMissingBean - public HierarchicalNameMapper hierarchicalNameMapper(GraphiteConfig graphiteConfig) { - return new GraphiteHierarchicalNameMapper(graphiteConfig.tagsAsPrefix()); + Clock clock) { + return new GraphiteMeterRegistry(graphiteConfig, clock); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfiguration.java index bc7501bf45..f1e6f2abcd 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfiguration.java @@ -17,7 +17,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.jmx; import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.util.HierarchicalNameMapper; import io.micrometer.jmx.JmxConfig; import io.micrometer.jmx.JmxMeterRegistry; @@ -59,15 +58,8 @@ public class JmxMetricsExportAutoConfiguration { @Bean @ConditionalOnMissingBean - public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, - HierarchicalNameMapper nameMapper, Clock clock) { - return new JmxMeterRegistry(config, clock, nameMapper); - } - - @Bean - @ConditionalOnMissingBean - public HierarchicalNameMapper hierarchicalNameMapper() { - return HierarchicalNameMapper.DEFAULT; + public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, Clock clock) { + return new JmxMeterRegistry(config, clock); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfiguration.java index fdfa8c1c3d..b53333a0c5 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfiguration.java @@ -17,7 +17,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.statsd; import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.util.HierarchicalNameMapper; import io.micrometer.statsd.StatsdConfig; import io.micrometer.statsd.StatsdMeterRegistry; import io.micrometer.statsd.StatsdMetrics; @@ -61,14 +60,8 @@ public class StatsdMetricsExportAutoConfiguration { @Bean @ConditionalOnMissingBean public StatsdMeterRegistry statsdMeterRegistry(StatsdConfig statsdConfig, - HierarchicalNameMapper hierarchicalNameMapper, Clock clock) { - return new StatsdMeterRegistry(statsdConfig, hierarchicalNameMapper, clock); - } - - @Bean - @ConditionalOnMissingBean - public HierarchicalNameMapper hierarchicalNameMapper() { - return HierarchicalNameMapper.DEFAULT; + Clock clock) { + return new StatsdMeterRegistry(statsdConfig, clock); } @Bean diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfigurationTests.java index a0550223ce..b44c938ce7 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfigurationTests.java @@ -19,9 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.jmx; import java.util.Map; import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.Meter.Id; -import io.micrometer.core.instrument.config.NamingConvention; -import io.micrometer.core.instrument.util.HierarchicalNameMapper; import io.micrometer.jmx.JmxConfig; import io.micrometer.jmx.JmxMeterRegistry; import org.junit.Test; @@ -56,12 +53,11 @@ public class JmxMetricsExportAutoConfigurationTests { } @Test - public void autoConfiguresItsConfigMeterRegistryAndNameMapper() { + public void autoConfiguresItsConfigAndMeterRegistry() { this.contextRunner.withUserConfiguration(BaseConfiguration.class) .run((context) -> assertThat(context) .hasSingleBean(JmxMeterRegistry.class) - .hasSingleBean(JmxConfig.class) - .hasSingleBean(HierarchicalNameMapper.class)); + .hasSingleBean(JmxConfig.class)); } @Test @@ -70,8 +66,7 @@ public class JmxMetricsExportAutoConfigurationTests { .withPropertyValues("management.metrics.export.jmx.enabled=false") .run((context) -> assertThat(context) .doesNotHaveBean(JmxMeterRegistry.class) - .doesNotHaveBean(JmxConfig.class) - .doesNotHaveBean(HierarchicalNameMapper.class)); + .doesNotHaveBean(JmxConfig.class)); } @Test @@ -79,8 +74,7 @@ public class JmxMetricsExportAutoConfigurationTests { this.contextRunner.withUserConfiguration(CustomConfigConfiguration.class) .run((context) -> assertThat(context) .hasSingleBean(JmxMeterRegistry.class) - .hasSingleBean(JmxConfig.class).hasBean("customConfig") - .hasSingleBean(HierarchicalNameMapper.class)); + .hasSingleBean(JmxConfig.class).hasBean("customConfig")); } @Test @@ -88,17 +82,7 @@ public class JmxMetricsExportAutoConfigurationTests { this.contextRunner.withUserConfiguration(CustomRegistryConfiguration.class) .run((context) -> assertThat(context) .hasSingleBean(JmxMeterRegistry.class).hasBean("customRegistry") - .hasSingleBean(JmxConfig.class) - .hasSingleBean(HierarchicalNameMapper.class)); - } - - @Test - public void allowsCustomHierarchicalNameMapperToBeUsed() { - this.contextRunner.withUserConfiguration(CustomNameMapperConfiguration.class) - .run((context) -> assertThat(context) - .hasSingleBean(JmxMeterRegistry.class) - .hasSingleBean(JmxConfig.class).hasBean("customNameMapper") - .hasSingleBean(HierarchicalNameMapper.class)); + .hasSingleBean(JmxConfig.class)); } @Test @@ -142,14 +126,7 @@ public class JmxMetricsExportAutoConfigurationTests { @Bean public JmxConfig customConfig() { - return new JmxConfig() { - - @Override - public String get(String k) { - return null; - } - - }; + return k -> null; } } @@ -165,22 +142,4 @@ public class JmxMetricsExportAutoConfigurationTests { } - @Configuration - @Import(BaseConfiguration.class) - static class CustomNameMapperConfiguration { - - @Bean - public HierarchicalNameMapper customNameMapper() { - return new HierarchicalNameMapper() { - - @Override - public String toHierarchicalName(Id id, NamingConvention convention) { - return "test"; - } - - }; - } - - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java index 1867166fdc..fd6ed0b3e2 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java @@ -19,9 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.statsd; import java.util.Map; import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.Meter.Id; -import io.micrometer.core.instrument.config.NamingConvention; -import io.micrometer.core.instrument.util.HierarchicalNameMapper; import io.micrometer.statsd.StatsdConfig; import io.micrometer.statsd.StatsdMeterRegistry; import io.micrometer.statsd.StatsdMetrics; @@ -57,12 +54,11 @@ public class StatsdMetricsExportAutoConfigurationTests { } @Test - public void autoConfiguresItsConfigMeterRegistryNameMapperAndMetrics() { + public void autoConfiguresItsConfigMeterRegistryAndMetrics() { this.contextRunner.withUserConfiguration(BaseConfiguration.class) .run((context) -> assertThat(context) .hasSingleBean(StatsdMeterRegistry.class) .hasSingleBean(StatsdConfig.class) - .hasSingleBean(HierarchicalNameMapper.class) .hasSingleBean(StatsdMetrics.class)); } @@ -72,8 +68,7 @@ public class StatsdMetricsExportAutoConfigurationTests { .withPropertyValues("management.metrics.export.statsd.enabled=false") .run((context) -> assertThat(context) .doesNotHaveBean(StatsdMeterRegistry.class) - .doesNotHaveBean(StatsdConfig.class) - .doesNotHaveBean(HierarchicalNameMapper.class)); + .doesNotHaveBean(StatsdConfig.class)); } @Test @@ -81,8 +76,7 @@ public class StatsdMetricsExportAutoConfigurationTests { this.contextRunner.withUserConfiguration(CustomConfigConfiguration.class) .run((context) -> assertThat(context) .hasSingleBean(StatsdMeterRegistry.class) - .hasSingleBean(StatsdConfig.class).hasBean("customConfig") - .hasSingleBean(HierarchicalNameMapper.class)); + .hasSingleBean(StatsdConfig.class).hasBean("customConfig")); } @Test @@ -90,17 +84,7 @@ public class StatsdMetricsExportAutoConfigurationTests { this.contextRunner.withUserConfiguration(CustomRegistryConfiguration.class) .run((context) -> assertThat(context) .hasSingleBean(StatsdMeterRegistry.class) - .hasBean("customRegistry").hasSingleBean(StatsdConfig.class) - .hasSingleBean(HierarchicalNameMapper.class)); - } - - @Test - public void allowsCustomHierarchicalNameMapperToBeUsed() { - this.contextRunner.withUserConfiguration(CustomNameMapperConfiguration.class) - .run((context) -> assertThat(context) - .hasSingleBean(StatsdMeterRegistry.class) - .hasSingleBean(StatsdConfig.class).hasBean("customNameMapper") - .hasSingleBean(HierarchicalNameMapper.class)); + .hasBean("customRegistry").hasSingleBean(StatsdConfig.class)); } @Test @@ -144,14 +128,7 @@ public class StatsdMetricsExportAutoConfigurationTests { @Bean public StatsdConfig customConfig() { - return new StatsdConfig() { - - @Override - public String get(String k) { - return null; - } - - }; + return k -> null; } } @@ -167,22 +144,4 @@ public class StatsdMetricsExportAutoConfigurationTests { } - @Configuration - @Import(BaseConfiguration.class) - static class CustomNameMapperConfiguration { - - @Bean - public HierarchicalNameMapper customNameMapper() { - return new HierarchicalNameMapper() { - - @Override - public String toHierarchicalName(Id id, NamingConvention convention) { - return "test"; - } - - }; - } - - } - } diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index 4c6ad89594..12633f9281 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -1435,6 +1435,21 @@ to use can be provided using: management.metrics.export.graphite.port=9004 ---- +Micrometer provides a default `HierarchicalNameMapper` that governs how a dimensional +meter id is mapped to flat hierarchical names. + +TIP: To take control over this behaviour, define your `GraphiteMeterRegistry` and supply +your own `HierarchicalNameMapper`. An auto-configured `GraphiteConfig` and `Clock` beans +are provided unless you define your own: + +[source,java] +---- +@Bean +public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig config, Clock clock) { + return new GraphiteMeterRegistry(config, clock, MY_HIERARCHICAL_MAPPER); +} +---- + [[production-ready-metrics-export-influx]] @@ -1454,10 +1469,20 @@ server] to use can be provided using: ==== JMX Micrometer provides a hierarchical mapping to {micrometer-registry-documentation}/jmx[JMX], primarily as a cheap and portable way to -view metrics locally. Spring Boot provides a default `HierarchicalNameMapper` that governs +view metrics locally. Micrometer provides a default `HierarchicalNameMapper` that governs how a dimensional meter id is mapped to flat hierarchical names. -TIP: To take control over this behaviour, define your own `HierarchicalNameMapper` bean. +TIP: To take control over this behaviour, define your `JmxMeterRegistry` and supply your +own `HierarchicalNameMapper`. An auto-configured `JmxConfig` and `Clock` beans are +provided unless you define your own: + +[source,java] +---- +@Bean +public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, Clock clock) { + return new JmxMeterRegistry(config, clock, MY_HIERARCHICAL_MAPPER); +} +----