Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statsd-emitter: support constant DogStatsD tags #6791

Merged
merged 1 commit into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/content/development/extensions-contrib/statsd.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ All the configuration parameters for the StatsD emitter are under `druid.emitter
|`druid.emitter.statsd.dimensionMapPath`|JSON file defining the StatsD type, and desired dimensions for every Druid metric|no|Default mapping provided. See below.|
|`druid.emitter.statsd.blankHolder`|The blank character replacement as statsD does not support path with blank character|no|"-"|
|`druid.emitter.statsd.dogstatsd`|Flag to enable [DogStatsD](https://docs.datadoghq.com/developers/dogstatsd/) support. Causes dimensions to be included as tags, not as a part of the metric name. `convertRange` fields will be ignored.|no|false|
|`druid.emitter.statsd.dogstatsdConstantTags`|If `druid.emitter.statsd.dogstatsd` is true, the tags in the JSON list of strings will be sent with every event.|no|[]|

### Druid to StatsD Event Converter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static StatsDEmitter of(StatsDEmitterConfig config, ObjectMapper mapper)
config.getPrefix(),
config.getHostname(),
config.getPort(),
EMPTY_ARRAY,
config.isDogstatsd() ? config.getDogstatsdConstantTags().toArray(new String[0]) : EMPTY_ARRAY,
new StatsDClientErrorHandler()
{
private int exceptionCount = 0;
Expand Down Expand Up @@ -106,7 +106,7 @@ public void emit(Event event)
if (statsDMetric != null) {
List<String> fullNameList;
String[] tags;
if (config.getDogstatsd()) {
if (config.isDogstatsd()) {
if (config.getIncludeHost()) {
dimsBuilder.put("hostname", host);
}
Expand All @@ -133,7 +133,7 @@ public void emit(Event event)
fullName = STATSD_SEPARATOR.matcher(fullName).replaceAll(config.getSeparator());
fullName = BLANK.matcher(fullName).replaceAll(config.getBlankHolder());

if (config.getDogstatsd() && (value instanceof Float || value instanceof Double)) {
if (config.isDogstatsd() && (value instanceof Float || value instanceof Double)) {
switch (statsDMetric.type) {
case count:
statsd.count(fullName, value.doubleValue(), tags);
Expand All @@ -146,7 +146,7 @@ public void emit(Event event)
break;
}
} else {
long val = statsDMetric.convertRange && !config.getDogstatsd() ?
long val = statsDMetric.convertRange && !config.isDogstatsd() ?
Math.round(value.doubleValue() * 100) :
value.longValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
*/
public class StatsDEmitterConfig
Expand All @@ -44,6 +48,8 @@ public class StatsDEmitterConfig
private final String blankHolder;
@JsonProperty
private final Boolean dogstatsd;
@JsonProperty
private final List<String> dogstatsdConstantTags;

@JsonCreator
public StatsDEmitterConfig(
Expand All @@ -54,7 +60,8 @@ public StatsDEmitterConfig(
@JsonProperty("includeHost") Boolean includeHost,
@JsonProperty("dimensionMapPath") String dimensionMapPath,
@JsonProperty("blankHolder") String blankHolder,
@JsonProperty("dogstatsd") Boolean dogstatsd
@JsonProperty("dogstatsd") Boolean dogstatsd,
@JsonProperty("dogstatsdConstantTags") List<String> dogstatsdConstantTags
)
{
this.hostname = Preconditions.checkNotNull(hostname, "StatsD hostname cannot be null.");
Expand All @@ -65,6 +72,7 @@ public StatsDEmitterConfig(
this.dimensionMapPath = dimensionMapPath;
this.blankHolder = blankHolder != null ? blankHolder : "-";
this.dogstatsd = dogstatsd != null ? dogstatsd : false;
this.dogstatsdConstantTags = dogstatsdConstantTags != null ? dogstatsdConstantTags : Collections.emptyList();
}

@Override
Expand Down Expand Up @@ -97,22 +105,19 @@ public boolean equals(Object o)
if (dimensionMapPath != null ? !dimensionMapPath.equals(that.dimensionMapPath) : that.dimensionMapPath != null) {
return false;
}
return dogstatsd != null ? dogstatsd.equals(that.dogstatsd) : that.dogstatsd == null;
if (dogstatsd != null ? !dogstatsd.equals(that.dogstatsd) : that.dogstatsd != null) {
return false;
}
return dogstatsdConstantTags != null ? dogstatsdConstantTags.equals(that.dogstatsdConstantTags)
: that.dogstatsdConstantTags == null;

}

@Override
public int hashCode()
{
int result = hostname != null ? hostname.hashCode() : 0;
result = 31 * result + (port != null ? port.hashCode() : 0);
result = 31 * result + (prefix != null ? prefix.hashCode() : 0);
result = 31 * result + (separator != null ? separator.hashCode() : 0);
result = 31 * result + (includeHost != null ? includeHost.hashCode() : 0);
result = 31 * result + (dimensionMapPath != null ? dimensionMapPath.hashCode() : 0);
result = 31 * result + (blankHolder != null ? blankHolder.hashCode() : 0);
result = 31 * result + (dogstatsd != null ? dogstatsd.hashCode() : 0);
return result;
return Objects.hash(hostname, port, prefix, separator, includeHost, dimensionMapPath,
blankHolder, dogstatsd, dogstatsdConstantTags);
}

@JsonProperty
Expand Down Expand Up @@ -158,8 +163,14 @@ public String getBlankHolder()
}

@JsonProperty
public Boolean getDogstatsd()
public Boolean isDogstatsd()
{
return dogstatsd;
}

@JsonProperty
public List<String> getDogstatsdConstantTags()
{
return dogstatsdConstantTags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void testConvertRange()
{
StatsDClient client = createMock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, null),
new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, null, null),
new ObjectMapper(),
client
);
Expand All @@ -57,7 +57,7 @@ public void testConvertRangeWithDogstatsd()
{
StatsDClient client = createMock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, true),
new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, true, null),
new ObjectMapper(),
client
);
Expand All @@ -76,7 +76,7 @@ public void testNoConvertRange()
{
StatsDClient client = createMock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, null),
new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, null, null),
new ObjectMapper(),
client
);
Expand Down Expand Up @@ -104,7 +104,7 @@ public void testConfigOptions()
{
StatsDClient client = createMock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, "#", true, null, null, null),
new StatsDEmitterConfig("localhost", 8888, null, "#", true, null, null, null, null),
new ObjectMapper(),
client
);
Expand Down Expand Up @@ -132,7 +132,7 @@ public void testDogstatsdEnabled()
{
StatsDClient client = createMock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, "#", true, null, null, true),
new StatsDEmitterConfig("localhost", 8888, null, "#", true, null, null, true, null),
new ObjectMapper(),
client
);
Expand Down Expand Up @@ -161,7 +161,7 @@ public void testBlankHolderOptions()
{
StatsDClient client = createMock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, null, true, null, null, null),
new StatsDEmitterConfig("localhost", 8888, null, null, true, null, null, null, null),
new ObjectMapper(),
client
);
Expand Down