Fix statsd metrics collection for names with ":"

Statsd server is ignoring malformed metrics. This change introduces
a basic sanitizing to metric names for avoid losing those metrics.

See gh-8906
This commit is contained in:
Odín del Río
2017-04-16 11:56:20 +02:00
committed by Stephane Nicoll
parent cdf3eadc95
commit 9e705c83c8
2 changed files with 28 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link StatsdMetricWriter}.
*
* @author Dave Syer
* @author Odín del Río
*/
public class StatsdMetricWriterTests {
@@ -97,6 +98,20 @@ public class StatsdMetricWriterTests {
assertThat(this.server.messagesReceived().get(0)).isEqualTo("my.gauge.foo:3|g");
}
@Test
public void incrementMetricWithInvalidCharsInName() throws Exception {
this.writer.increment(new Delta<>("counter.fo:o", 3L));
this.server.waitForMessage();
assertThat(this.server.messagesReceived().get(0)).isEqualTo("me.counter.foo:3|c");
}
@Test
public void setMetricWithInvalidCharsInName() throws Exception {
this.writer.set(new Metric<>("gauge.f:o:o", 3L));
this.server.waitForMessage();
assertThat(this.server.messagesReceived().get(0)).isEqualTo("me.gauge.foo:3|g");
}
private static final class DummyStatsDServer implements Runnable {
private final List<String> messagesReceived = new ArrayList<String>();