Merge pull request #12683 from jkschneider:gh-12676

* pr/12683:
  Polish "Remove HierarchicalNameMapper as a configured @Bean"
  Remove HierarchicalNameMapper as a configured @Bean
pull/12715/merge
Stephane Nicoll 7 years ago
commit 5bf4a5fa98

@ -17,7 +17,6 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.ganglia; package org.springframework.boot.actuate.autoconfigure.metrics.export.ganglia;
import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.util.HierarchicalNameMapper;
import io.micrometer.ganglia.GangliaConfig; import io.micrometer.ganglia.GangliaConfig;
import io.micrometer.ganglia.GangliaMeterRegistry; import io.micrometer.ganglia.GangliaMeterRegistry;
@ -60,14 +59,8 @@ public class GangliaMetricsExportAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public GangliaMeterRegistry gangliaMeterRegistry(GangliaConfig gangliaConfig, public GangliaMeterRegistry gangliaMeterRegistry(GangliaConfig gangliaConfig,
HierarchicalNameMapper nameMapper, Clock clock) { Clock clock) {
return new GangliaMeterRegistry(gangliaConfig, clock, nameMapper); 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; package org.springframework.boot.actuate.autoconfigure.metrics.export.graphite;
import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.util.HierarchicalNameMapper;
import io.micrometer.graphite.GraphiteConfig; import io.micrometer.graphite.GraphiteConfig;
import io.micrometer.graphite.GraphiteHierarchicalNameMapper;
import io.micrometer.graphite.GraphiteMeterRegistry; import io.micrometer.graphite.GraphiteMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
@ -61,14 +59,8 @@ public class GraphiteMetricsExportAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig graphiteConfig, public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig graphiteConfig,
HierarchicalNameMapper nameMapper, Clock clock) { Clock clock) {
return new GraphiteMeterRegistry(graphiteConfig, clock, nameMapper); return new GraphiteMeterRegistry(graphiteConfig, clock);
}
@Bean
@ConditionalOnMissingBean
public HierarchicalNameMapper hierarchicalNameMapper(GraphiteConfig graphiteConfig) {
return new GraphiteHierarchicalNameMapper(graphiteConfig.tagsAsPrefix());
} }
} }

@ -17,7 +17,6 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.jmx; package org.springframework.boot.actuate.autoconfigure.metrics.export.jmx;
import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.util.HierarchicalNameMapper;
import io.micrometer.jmx.JmxConfig; import io.micrometer.jmx.JmxConfig;
import io.micrometer.jmx.JmxMeterRegistry; import io.micrometer.jmx.JmxMeterRegistry;
@ -59,15 +58,8 @@ public class JmxMetricsExportAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, Clock clock) {
HierarchicalNameMapper nameMapper, Clock clock) { return new JmxMeterRegistry(config, clock);
return new JmxMeterRegistry(config, clock, nameMapper);
}
@Bean
@ConditionalOnMissingBean
public HierarchicalNameMapper hierarchicalNameMapper() {
return HierarchicalNameMapper.DEFAULT;
} }
} }

@ -17,7 +17,6 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.statsd; package org.springframework.boot.actuate.autoconfigure.metrics.export.statsd;
import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.util.HierarchicalNameMapper;
import io.micrometer.statsd.StatsdConfig; import io.micrometer.statsd.StatsdConfig;
import io.micrometer.statsd.StatsdMeterRegistry; import io.micrometer.statsd.StatsdMeterRegistry;
import io.micrometer.statsd.StatsdMetrics; import io.micrometer.statsd.StatsdMetrics;
@ -61,14 +60,8 @@ public class StatsdMetricsExportAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public StatsdMeterRegistry statsdMeterRegistry(StatsdConfig statsdConfig, public StatsdMeterRegistry statsdMeterRegistry(StatsdConfig statsdConfig,
HierarchicalNameMapper hierarchicalNameMapper, Clock clock) { Clock clock) {
return new StatsdMeterRegistry(statsdConfig, hierarchicalNameMapper, clock); return new StatsdMeterRegistry(statsdConfig, clock);
}
@Bean
@ConditionalOnMissingBean
public HierarchicalNameMapper hierarchicalNameMapper() {
return HierarchicalNameMapper.DEFAULT;
} }
@Bean @Bean

@ -19,9 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.jmx;
import java.util.Map; import java.util.Map;
import io.micrometer.core.instrument.Clock; 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.JmxConfig;
import io.micrometer.jmx.JmxMeterRegistry; import io.micrometer.jmx.JmxMeterRegistry;
import org.junit.Test; import org.junit.Test;
@ -56,12 +53,11 @@ public class JmxMetricsExportAutoConfigurationTests {
} }
@Test @Test
public void autoConfiguresItsConfigMeterRegistryAndNameMapper() { public void autoConfiguresItsConfigAndMeterRegistry() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(JmxMeterRegistry.class) .hasSingleBean(JmxMeterRegistry.class)
.hasSingleBean(JmxConfig.class) .hasSingleBean(JmxConfig.class));
.hasSingleBean(HierarchicalNameMapper.class));
} }
@Test @Test
@ -70,8 +66,7 @@ public class JmxMetricsExportAutoConfigurationTests {
.withPropertyValues("management.metrics.export.jmx.enabled=false") .withPropertyValues("management.metrics.export.jmx.enabled=false")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(JmxMeterRegistry.class) .doesNotHaveBean(JmxMeterRegistry.class)
.doesNotHaveBean(JmxConfig.class) .doesNotHaveBean(JmxConfig.class));
.doesNotHaveBean(HierarchicalNameMapper.class));
} }
@Test @Test
@ -79,8 +74,7 @@ public class JmxMetricsExportAutoConfigurationTests {
this.contextRunner.withUserConfiguration(CustomConfigConfiguration.class) this.contextRunner.withUserConfiguration(CustomConfigConfiguration.class)
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(JmxMeterRegistry.class) .hasSingleBean(JmxMeterRegistry.class)
.hasSingleBean(JmxConfig.class).hasBean("customConfig") .hasSingleBean(JmxConfig.class).hasBean("customConfig"));
.hasSingleBean(HierarchicalNameMapper.class));
} }
@Test @Test
@ -88,17 +82,7 @@ public class JmxMetricsExportAutoConfigurationTests {
this.contextRunner.withUserConfiguration(CustomRegistryConfiguration.class) this.contextRunner.withUserConfiguration(CustomRegistryConfiguration.class)
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(JmxMeterRegistry.class).hasBean("customRegistry") .hasSingleBean(JmxMeterRegistry.class).hasBean("customRegistry")
.hasSingleBean(JmxConfig.class) .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));
} }
@Test @Test
@ -142,14 +126,7 @@ public class JmxMetricsExportAutoConfigurationTests {
@Bean @Bean
public JmxConfig customConfig() { public JmxConfig customConfig() {
return new JmxConfig() { return k -> null;
@Override
public String get(String k) {
return 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 java.util.Map;
import io.micrometer.core.instrument.Clock; 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.StatsdConfig;
import io.micrometer.statsd.StatsdMeterRegistry; import io.micrometer.statsd.StatsdMeterRegistry;
import io.micrometer.statsd.StatsdMetrics; import io.micrometer.statsd.StatsdMetrics;
@ -57,12 +54,11 @@ public class StatsdMetricsExportAutoConfigurationTests {
} }
@Test @Test
public void autoConfiguresItsConfigMeterRegistryNameMapperAndMetrics() { public void autoConfiguresItsConfigMeterRegistryAndMetrics() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(StatsdMeterRegistry.class) .hasSingleBean(StatsdMeterRegistry.class)
.hasSingleBean(StatsdConfig.class) .hasSingleBean(StatsdConfig.class)
.hasSingleBean(HierarchicalNameMapper.class)
.hasSingleBean(StatsdMetrics.class)); .hasSingleBean(StatsdMetrics.class));
} }
@ -72,8 +68,7 @@ public class StatsdMetricsExportAutoConfigurationTests {
.withPropertyValues("management.metrics.export.statsd.enabled=false") .withPropertyValues("management.metrics.export.statsd.enabled=false")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(StatsdMeterRegistry.class) .doesNotHaveBean(StatsdMeterRegistry.class)
.doesNotHaveBean(StatsdConfig.class) .doesNotHaveBean(StatsdConfig.class));
.doesNotHaveBean(HierarchicalNameMapper.class));
} }
@Test @Test
@ -81,8 +76,7 @@ public class StatsdMetricsExportAutoConfigurationTests {
this.contextRunner.withUserConfiguration(CustomConfigConfiguration.class) this.contextRunner.withUserConfiguration(CustomConfigConfiguration.class)
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(StatsdMeterRegistry.class) .hasSingleBean(StatsdMeterRegistry.class)
.hasSingleBean(StatsdConfig.class).hasBean("customConfig") .hasSingleBean(StatsdConfig.class).hasBean("customConfig"));
.hasSingleBean(HierarchicalNameMapper.class));
} }
@Test @Test
@ -90,17 +84,7 @@ public class StatsdMetricsExportAutoConfigurationTests {
this.contextRunner.withUserConfiguration(CustomRegistryConfiguration.class) this.contextRunner.withUserConfiguration(CustomRegistryConfiguration.class)
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(StatsdMeterRegistry.class) .hasSingleBean(StatsdMeterRegistry.class)
.hasBean("customRegistry").hasSingleBean(StatsdConfig.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));
} }
@Test @Test
@ -144,14 +128,7 @@ public class StatsdMetricsExportAutoConfigurationTests {
@Bean @Bean
public StatsdConfig customConfig() { public StatsdConfig customConfig() {
return new StatsdConfig() { return k -> null;
@Override
public String get(String k) {
return 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,6 +1435,21 @@ to use can be provided using:
management.metrics.export.graphite.port=9004 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]] [[production-ready-metrics-export-influx]]
@ -1454,10 +1469,20 @@ server] to use can be provided using:
==== JMX ==== JMX
Micrometer provides a hierarchical mapping to Micrometer provides a hierarchical mapping to
{micrometer-registry-documentation}/jmx[JMX], primarily as a cheap and portable way 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. 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);
}
----

Loading…
Cancel
Save