PrometheusMetricsSink implements MetricsSink { public String prometheusName(String recordName, String metricName) { String baseName = StringUtils.capitalize(recordName) + StringUtils.capitalize(metricName); String[] parts = SPLIT_PATTERN.split(baseName); String joined = String.join("_", parts).toLowerCase(); return DELIMITERS.matcher(joined).replaceAll("_"); } PrometheusMetricsSink(); @Override void putMetrics(MetricsRecord metricsRecord); String prometheusName(String recordName,
                               String metricName); @Override void flush(); @Override void init(SubsetConfiguration subsetConfiguration); void writeMetrics(Writer writer);  }
@Test public void testNamingCamelCase() { PrometheusMetricsSink sink = new PrometheusMetricsSink(); Assert.assertEquals("rpc_time_some_metrics", sink.prometheusName("RpcTime", "SomeMetrics")); Assert.assertEquals("om_rpc_time_om_info_keys", sink.prometheusName("OMRpcTime", "OMInfoKeys")); Assert.assertEquals("rpc_time_small", sink.prometheusName("RpcTime", "small")); }
@Test public void testNamingPipeline() { PrometheusMetricsSink sink = new PrometheusMetricsSink(); String recordName = "SCMPipelineMetrics"; String metricName = "NumBlocksAllocated-" + "RATIS-THREE-47659e3d-40c9-43b3-9792-4982fc279aba"; Assert.assertEquals( "scm_pipeline_metrics_" + "num_blocks_allocated_" + "ratis_three_47659e3d_40c9_43b3_9792_4982fc279aba", 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)); }