Expose Graphite's graphiteTagsEnabled property
This commit exposes an additional property for Graphite that allows to restore the previous default behaviour with regards to tags, i.e. prefixing the ones defined by the "tagsAsPrefix" property. Close gh-20834
This commit is contained in:
parent
08533c79e0
commit
4813606b70
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -70,8 +70,14 @@ public class GraphiteProperties {
|
|||
private GraphiteProtocol protocol = GraphiteProtocol.PICKLED;
|
||||
|
||||
/**
|
||||
* For the default naming convention, turn the specified tag keys into part of the
|
||||
* metric prefix.
|
||||
* Whether Graphite tags should be used, as opposed to a hierarchical naming
|
||||
* convention.
|
||||
*/
|
||||
private boolean graphiteTagsEnabled = true;
|
||||
|
||||
/**
|
||||
* For the hierarchical naming convention, turn the specified tag keys into part of
|
||||
* the metric prefix. Ignored if "graphiteTagsEnabled" is true.
|
||||
*/
|
||||
private String[] tagsAsPrefix = new String[0];
|
||||
|
||||
|
@ -131,6 +137,14 @@ public class GraphiteProperties {
|
|||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public boolean isGraphiteTagsEnabled() {
|
||||
return this.graphiteTagsEnabled;
|
||||
}
|
||||
|
||||
public void setGraphiteTagsEnabled(boolean graphiteTagsEnabled) {
|
||||
this.graphiteTagsEnabled = graphiteTagsEnabled;
|
||||
}
|
||||
|
||||
public String[] getTagsAsPrefix() {
|
||||
return this.tagsAsPrefix;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -76,6 +76,11 @@ class GraphitePropertiesConfigAdapter extends PropertiesConfigAdapter<GraphitePr
|
|||
return get(GraphiteProperties::getProtocol, GraphiteConfig.super::protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean graphiteTagsEnabled() {
|
||||
return get(GraphiteProperties::isGraphiteTagsEnabled, GraphiteConfig.super::graphiteTagsEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] tagsAsPrefix() {
|
||||
return get(GraphiteProperties::getTagsAsPrefix, GraphiteConfig.super::tagsAsPrefix);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -46,10 +46,23 @@ class GraphiteMetricsExportAutoConfigurationTests {
|
|||
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(GraphiteMeterRegistry.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfiguresUseTagsAsPrefixIsIgnoredByDefault() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.graphite.tags-as-prefix=ignored").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("test.count;app=myapp");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfiguresUseTagsAsPrefix() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.graphite.tags-as-prefix=app").run((context) -> {
|
||||
.withPropertyValues("management.metrics.export.graphite.tags-as-prefix=app",
|
||||
"management.metrics.export.graphite.graphite-tags-enabled=false")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(GraphiteMeterRegistry.class);
|
||||
GraphiteMeterRegistry registry = context.getBean(GraphiteMeterRegistry.class);
|
||||
registry.counter("test.count", Tags.of("app", "myapp"));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -39,6 +39,7 @@ class GraphitePropertiesTests {
|
|||
assertThat(properties.getHost()).isEqualTo(config.host());
|
||||
assertThat(properties.getPort()).isEqualTo(config.port());
|
||||
assertThat(properties.getProtocol()).isEqualTo(config.protocol());
|
||||
assertThat(properties.isGraphiteTagsEnabled()).isEqualTo(config.graphiteTagsEnabled());
|
||||
assertThat(properties.getTagsAsPrefix()).isEqualTo(config.tagsAsPrefix());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue