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

Fix dogstatsd metric without tags in StatsDOutputWriter #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions src/main/java/org/jmxtrans/agent/StatsDOutputWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ protected synchronized String buildMetricsString(String metricName, String metri
.append(":")
.append(strValue)
.append("|")
.append(type)
.append("|#")
.append(StringUtils2.join(Tag.convertTagsToStrings(tags), ","))
.append("\n");
.append(type);
if (!tags.isEmpty()) {
sb.append("|#");
sb.append(StringUtils2.join(Tag.convertTagsToStrings(tags), ","));
}
sb.append("\n");
} else if (statsType.equals(STATSD_SYSDIG)) {
sb.append(metricNamePrefix)
.append(".")
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/jmxtrans/agent/StatsDOutputWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ public void test_write_counter_metric_dd() throws IOException {

}

@Test
public void test_write_counter_metric_dd_without_tags() throws IOException {
Map<String, String> settings = new HashMap<>();
settings.put(StatsDOutputWriter.SETTING_ROOT_PREFIX, "foo.bar");
// No real connect is done. Config is here to please the postConstruct.
settings.put(StatsDOutputWriter.SETTING_HOST, "localhost");
settings.put(StatsDOutputWriter.SETTING_PORT, "8125");
settings.put(StatsDOutputWriter.SETTINGS_STATSD_TYPE, "dd");

writer.postConstruct(settings);
writer.writeQueryResult("my-metric", "gauge", 12);
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.my-metric:12|g\n"));
}

@Test
public void test_write_counter_metric_sysdig() throws IOException {
Map<String, String> settings = new HashMap<>();
Expand Down