Remove HierarchicalNameMapper as a configured @Bean

HierarchicalNameMapper is not a component that can be shared amongst
multiple monitoring systems.

See gh-12683
pull/12715/merge
Jon Schneider 7 years ago committed by Stephane Nicoll
parent 7c36c00331
commit 8572a091b8

@ -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,7 @@ public class GangliaMetricsExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public GangliaMeterRegistry gangliaMeterRegistry(GangliaConfig gangliaConfig,
HierarchicalNameMapper nameMapper, Clock clock) {
return new GangliaMeterRegistry(gangliaConfig, clock, nameMapper);
Clock clock) {
return new GangliaMeterRegistry(gangliaConfig, clock);
}
@Bean
@ConditionalOnMissingBean
public HierarchicalNameMapper hierarchicalNameMapper() {
return HierarchicalNameMapper.DEFAULT;
}
}

@ -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);
}
}

@ -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,7 @@ public class JmxMetricsExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public JmxMeterRegistry jmxMeterRegistry(JmxConfig config,
HierarchicalNameMapper nameMapper, Clock clock) {
return new JmxMeterRegistry(config, clock, nameMapper);
public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, Clock clock) {
return new JmxMeterRegistry(config, clock);
}
@Bean
@ConditionalOnMissingBean
public HierarchicalNameMapper hierarchicalNameMapper() {
return HierarchicalNameMapper.DEFAULT;
}
}

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

@ -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";
}
};
}
}
}

@ -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";
}
};
}
}
}

@ -1435,7 +1435,19 @@ 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`.
[source,java]
----
@Bean
public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig config, Clock clock) {
return new GraphiteMeterRegistry(config, clock, MY_HIERARCHICAL_MAPPER);
}
----
[[production-ready-metrics-export-influx]]
==== Influx
@ -1454,12 +1466,19 @@ 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`.
[source,java]
----
@Bean
public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, Clock clock) {
return new JmxMeterRegistry(config, clock, MY_HIERARCHICAL_MAPPER);
}
----
[[production-ready-metrics-export-newrelic]]
==== New Relic

Loading…
Cancel
Save