Skip to content

Commit

Permalink
Remove HierarchicalNameMapper as a configured @bean
Browse files Browse the repository at this point in the history
HierarchicalNameMapper is not a component that can be shared amongst
multiple monitoring systems.

See spring-projectsgh-12683
  • Loading branch information
Jon Schneider authored and snicoll committed Apr 3, 2018
1 parent 7c36c00 commit 8572a09
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -60,14 +59,7 @@ public GangliaConfig gangliaConfig(GangliaProperties gangliaProperties) {
@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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,14 +59,8 @@ public GraphiteConfig graphiteConfig(GraphiteProperties graphiteProperties) {
@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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -59,15 +58,7 @@ public JmxConfig jmxConfig(JmxProperties jmxProperties) {

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,14 +60,8 @@ public StatsdConfig statsdConfig(StatsdProperties statsdProperties) {
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
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;
Expand Down Expand Up @@ -56,12 +53,11 @@ public void backsOffWithoutAClock() {
}

@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
Expand All @@ -70,35 +66,23 @@ public void autoConfigurationCanBeDisabled() {
.withPropertyValues("management.metrics.export.jmx.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(JmxMeterRegistry.class)
.doesNotHaveBean(JmxConfig.class)
.doesNotHaveBean(HierarchicalNameMapper.class));
.doesNotHaveBean(JmxConfig.class));
}

@Test
public void allowsCustomConfigToBeUsed() {
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
public void allowsCustomRegistryToBeUsed() {
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
Expand Down Expand Up @@ -142,14 +126,7 @@ static class CustomConfigConfiguration {

@Bean
public JmxConfig customConfig() {
return new JmxConfig() {

@Override
public String get(String k) {
return null;
}

};
return k -> null;
}

}
Expand All @@ -165,22 +142,4 @@ public JmxMeterRegistry customRegistry(JmxConfig config, Clock clock) {

}

@Configuration
@Import(BaseConfiguration.class)
static class CustomNameMapperConfiguration {

@Bean
public HierarchicalNameMapper customNameMapper() {
return new HierarchicalNameMapper() {

@Override
public String toHierarchicalName(Id id, NamingConvention convention) {
return "test";
}

};
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
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;
Expand Down Expand Up @@ -57,12 +54,11 @@ public void backsOffWithoutAClock() {
}

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

Expand All @@ -72,35 +68,23 @@ public void autoConfigurationCanBeDisabled() {
.withPropertyValues("management.metrics.export.statsd.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(StatsdMeterRegistry.class)
.doesNotHaveBean(StatsdConfig.class)
.doesNotHaveBean(HierarchicalNameMapper.class));
.doesNotHaveBean(StatsdConfig.class));
}

@Test
public void allowsCustomConfigToBeUsed() {
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
public void allowsCustomRegistryToBeUsed() {
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
Expand Down Expand Up @@ -144,14 +128,7 @@ static class CustomConfigConfiguration {

@Bean
public StatsdConfig customConfig() {
return new StatsdConfig() {

@Override
public String get(String k) {
return null;
}

};
return k -> null;
}

}
Expand All @@ -167,22 +144,4 @@ public StatsdMeterRegistry customRegistry(StatsdConfig config, Clock clock) {

}

@Configuration
@Import(BaseConfiguration.class)
static class CustomNameMapperConfiguration {

@Bean
public HierarchicalNameMapper customNameMapper() {
return new HierarchicalNameMapper() {

@Override
public String toHierarchicalName(Id id, NamingConvention convention) {
return "test";
}

};
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8572a09

Please sign in to comment.