Skip to content

Fix tags concatenation in custom metric #77

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

Merged
merged 1 commit into from
Mar 31, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.timgroup.statsd.NonBlockingStatsDClientBuilder;
import com.timgroup.statsd.StatsDClient;

import java.util.stream.Collectors;

abstract class MetricWriter {
private static MetricWriter IMPL;
public static synchronized MetricWriter getMetricWriterImpl(){
Expand Down Expand Up @@ -59,14 +61,17 @@ public ExtensionMetricWriter() {
@Override
public void write(CustomMetric cm){
if(null != client) {
StringBuilder tagsSb = new StringBuilder();
String tags = "";
if (cm.getTags() != null) {
cm.getTags().forEach((k, val) ->
tagsSb.append(k.toLowerCase())
.append(":")
.append(val.toString().toLowerCase()));
tags = cm
.getTags()
.entrySet()
.stream()
.map(
entry -> entry.getKey().toLowerCase() + ":" + entry.getValue().toString().toLowerCase()
).collect(Collectors.joining(","));
}
client.distribution(cm.getName(), cm.getValue(), tagsSb.toString());
client.distribution(cm.getName(), cm.getValue(), tags);
} else {
DDLogger.getLoggerImpl().error("Could not write the metric because the client is null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void run() {
if (null == text[0] || text[0].equals("notYetReceived")) {
Thread.sleep(1000);
} else {
assertTrue(text[0].startsWith("foo:24.3|d|#firsttag:firsttagvaluesecondtag:100.34"));
assertTrue(text[0].startsWith("foo:24.3|d|#firsttag:firsttagvalue,secondtag:100.34"));
break;
}
}
Expand Down