parent
02bd02b5af
commit
902ff4a2f6
|
@ -49,6 +49,9 @@ public class PrometheusMetricsSink implements MetricsSink {
|
|||
private static final Pattern SPLIT_PATTERN =
|
||||
Pattern.compile("(?<!(^|[A-Z_]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])");
|
||||
|
||||
private static final Pattern REPLACE_PATTERN =
|
||||
Pattern.compile("[^a-zA-Z0-9]+");
|
||||
|
||||
public PrometheusMetricsSink() {
|
||||
}
|
||||
|
||||
|
@ -101,9 +104,9 @@ public class PrometheusMetricsSink implements MetricsSink {
|
|||
|
||||
String baseName = StringUtils.capitalize(recordName)
|
||||
+ StringUtils.capitalize(metricName);
|
||||
baseName = baseName.replace('-', '_');
|
||||
String[] parts = SPLIT_PATTERN.split(baseName);
|
||||
return String.join("_", parts).toLowerCase();
|
||||
String result = String.join("_", parts).toLowerCase();
|
||||
return REPLACE_PATTERN.matcher(result).replaceAll("_");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -107,6 +107,17 @@ public class TestPrometheusMetricsSink {
|
|||
sink.prometheusName(recordName, metricName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamingSpaces() {
|
||||
PrometheusMetricsSink sink = new PrometheusMetricsSink();
|
||||
|
||||
String recordName = "JvmMetrics";
|
||||
String metricName = "GcTimeMillisG1 Young Generation";
|
||||
Assert.assertEquals(
|
||||
"jvm_metrics_gc_time_millis_g1_young_generation",
|
||||
sink.prometheusName(recordName, metricName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Example metric pojo.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue