diff --git a/src/main/java/org/datadog/jmxfetch/reporter/StatsdReporter.java b/src/main/java/org/datadog/jmxfetch/reporter/StatsdReporter.java index a93d111bf..fd13982a6 100644 --- a/src/main/java/org/datadog/jmxfetch/reporter/StatsdReporter.java +++ b/src/main/java/org/datadog/jmxfetch/reporter/StatsdReporter.java @@ -61,7 +61,7 @@ public static String formatDataName(String name){ String[] chunks = name.split("\\."); // Escaping the prefix name - chunks[0] = chunks[0].replaceAll("[_A-Z0-9:-]", ""); + chunks[0] = chunks[0].replaceAll("[A-Z0-9:_\\-]", ""); // Putting the chunks together (there's nothing in the standard library to do that :o ) String res = ""; diff --git a/src/test/java/org/datadog/jmxfetch/TestApp.java b/src/test/java/org/datadog/jmxfetch/TestApp.java index 3c7a62aed..b2522675b 100644 --- a/src/test/java/org/datadog/jmxfetch/TestApp.java +++ b/src/test/java/org/datadog/jmxfetch/TestApp.java @@ -4,6 +4,7 @@ import org.apache.log4j.Level; import org.datadog.jmxfetch.reporter.ConsoleReporter; +import org.datadog.jmxfetch.reporter.StatsdReporter; import org.datadog.jmxfetch.util.CustomLogger; import org.junit.BeforeClass; import org.junit.Test; @@ -396,6 +397,20 @@ public void testServiceCheckCRITICAL() throws Exception { mbs.unregisterMBean(objectName); } + @Test + public void testPrefixFormatter() throws Exception { + // Let's get a list of Strings to test (add real versionned check names + // here when you add new versionned check) + String[][] data = { + {"activemq_58.foo.bar12", "activemq.foo.bar12"}, + {"test_package-X86_64-VER1:0.weird.metric_name", "testpackage.weird.metric_name" } + }; + + // Let's test them all + for(int i=0; i