Skip to content

Commit

Permalink
Fix default HierarchicalNameMapper implementation for Graphite
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Apr 3, 2018
1 parent 958f3d5 commit 7c36c00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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 @@ -66,8 +67,8 @@ public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig graphiteConfig

@Bean
@ConditionalOnMissingBean
public HierarchicalNameMapper hierarchicalNameMapper() {
return HierarchicalNameMapper.DEFAULT;
public HierarchicalNameMapper hierarchicalNameMapper(GraphiteConfig graphiteConfig) {
return new GraphiteHierarchicalNameMapper(graphiteConfig.tagsAsPrefix());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;

import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.Tags;
import io.micrometer.graphite.GraphiteConfig;
import io.micrometer.graphite.GraphiteMeterRegistry;
import org.junit.Test;
Expand All @@ -39,6 +40,7 @@
* Tests for {@link GraphiteMetricsExportAutoConfiguration}.
*
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
public class GraphiteMetricsExportAutoConfigurationTests {

Expand All @@ -52,6 +54,20 @@ public void backsOffWithoutAClock() {
.doesNotHaveBean(GraphiteMeterRegistry.class));
}

@Test
public void autoConfiguresUseTagsAsPrefix() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.graphite.tags-as-prefix=app")
.run((context) -> {
assertThat(context).hasSingleBean(GraphiteMeterRegistry.class);
GraphiteMeterRegistry registry = context.getBean(
GraphiteMeterRegistry.class);
registry.counter("test.count", Tags.of("app", "myapp"));
assertThat(registry.getDropwizardRegistry().getMeters())
.containsOnlyKeys("myapp.testCount");
});
}

@Test
public void autoConfiguresItsConfigAndMeterRegistry() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
Expand Down

0 comments on commit 7c36c00

Please sign in to comment.