HADOOP-16495. Fix invalid metric types in PrometheusMetricsSink (#1244)
This commit is contained in:
parent
e6d240dc91
commit
0f8add8a60
@ -46,6 +46,7 @@ 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 DELIMITERS = Pattern.compile("[^a-zA-Z0-9]+");
|
||||
|
||||
public PrometheusMetricsSink() {
|
||||
}
|
||||
@ -92,9 +93,9 @@ public String prometheusName(String recordName,
|
||||
String metricName) {
|
||||
String baseName = StringUtils.capitalize(recordName)
|
||||
+ StringUtils.capitalize(metricName);
|
||||
baseName = baseName.replace('-', '_');
|
||||
String[] parts = SPLIT_PATTERN.split(baseName);
|
||||
return String.join("_", parts).toLowerCase();
|
||||
String joined = String.join("_", parts).toLowerCase();
|
||||
return DELIMITERS.matcher(joined).replaceAll("_");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,6 +99,28 @@ public void testNamingPipeline() {
|
||||
sink.prometheusName(recordName, metricName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamingPeriods() {
|
||||
PrometheusMetricsSink sink = new PrometheusMetricsSink();
|
||||
|
||||
String recordName = "org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsDatasetImpl";
|
||||
String metricName = "DfsUsed";
|
||||
Assert.assertEquals(
|
||||
"org_apache_hadoop_hdfs_server_datanode_fsdataset_impl_fs_dataset_impl_dfs_used",
|
||||
sink.prometheusName(recordName, metricName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamingWhitespaces() {
|
||||
PrometheusMetricsSink sink = new PrometheusMetricsSink();
|
||||
|
||||
String recordName = "JvmMetrics";
|
||||
String metricName = "GcCount" + "G1 Old Generation";
|
||||
Assert.assertEquals(
|
||||
"jvm_metrics_gc_count_g1_old_generation",
|
||||
sink.prometheusName(recordName, metricName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Example metric pojo.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user