Skip to content

Commit ea054f9

Browse files
committed
PR feedback for influx style statsd tags parsing
1 parent 6bf06c1 commit ea054f9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/com/arpnetworking/metrics/mad/parsers/StatsdToRecordParser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@
6363
* aggregation layer as a first-class metric type.
6464
*
6565
* Except for the differences described above this parser supports both the
66-
* traditional and Data Dog variants of the statsd protocol as defined here:
66+
* traditional, Data Dog, and Influx variants of the statsd protocol as defined here:
6767
*
6868
* https://github.com/b/statsd_spec
6969
* https://docs.datadoghq.com/guides/dogstatsd/
70+
* https://github.com/influxdata/telegraf/tree/master/plugins/inputs/statsd#influx-statsd
7071
*
7172
* @author Ville Koskela (ville dot koskela at inscopemetrics dot com)
7273
*/
@@ -164,7 +165,7 @@ private Number parseValue(
164165
// See: https://github.com/findbugsproject/findbugs/issues/79
165166
private ImmutableMap<String, String> parseTags(@Nullable final String tagsAsString) {
166167
if (null != tagsAsString) {
167-
return ImmutableMap.copyOf(Splitter.on(',').withKeyValueSeparator(':').split(tagsAsString));
168+
return ImmutableMap.copyOf(TAG_SPLITTER.split(tagsAsString));
168169
}
169170
return ImmutableMap.of();
170171
}
@@ -173,7 +174,7 @@ private ImmutableMap<String, String> parseTags(@Nullable final String tagsAsStri
173174
// See: https://github.com/findbugsproject/findbugs/issues/79
174175
private ImmutableMap<String, String> parseInfluxStyleTags(@Nullable final String tagsAsString) {
175176
if (null != tagsAsString) {
176-
return ImmutableMap.copyOf(Splitter.on(',').withKeyValueSeparator('=').split(tagsAsString));
177+
return ImmutableMap.copyOf(INFLUX_STYLE_TAGS_SPLITTER.split(tagsAsString));
177178
}
178179
return ImmutableMap.of();
179180
}
@@ -250,6 +251,8 @@ public StatsdToRecordParser() {
250251
private static final ThreadLocal<NumberFormat> NUMBER_FORMAT = ThreadLocal.withInitial(NumberFormat::getInstance);
251252
private static final Pattern STATSD_PATTERN = Pattern.compile(
252253
"^(?<NAME>[^:@|,]+)(,(?<INFLUXTAGS>[^:@|]+))?:(?<VALUE>[^|]+)\\|(?<TYPE>[^|]+)(\\|@(?<SAMPLERATE>[^|]+))?(\\|#(?<TAGS>.+))?$");
254+
private static final Splitter.MapSplitter INFLUX_STYLE_TAGS_SPLITTER = Splitter.on(',').withKeyValueSeparator('=');
255+
private static final Splitter.MapSplitter TAG_SPLITTER = Splitter.on(',').withKeyValueSeparator(':');
253256

254257
private enum StatsdType {
255258
COUNTER("c", MetricType.COUNTER, null),

0 commit comments

Comments
 (0)