You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ae...@apache.org on 2019/07/22 21:34:42 UTC
[hadoop] branch ozone-0.4.1 updated: HDDS-1811. Prometheus metrics
are broken.
This is an automated email from the ASF dual-hosted git repository.
aengineer pushed a commit to branch ozone-0.4.1
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/ozone-0.4.1 by this push:
new 2224072 HDDS-1811. Prometheus metrics are broken.
2224072 is described below
commit 22240727e5cd8ee169e8a2796015540124cd1593
Author: Doroszlai, Attila <ad...@apache.org>
AuthorDate: Wed Jul 17 23:29:56 2019 +0200
HDDS-1811. Prometheus metrics are broken.
Signed-off-by: Anu Engineer <ae...@apache.org>
(cherry picked from commit c958eddcf4b1f1cd9f6e5c2368a77a5962532435)
---
.../common/transport/server/ratis/CSMMetrics.java | 2 +-
.../hadoop/hdds/server/PrometheusMetricsSink.java | 34 +++++-----------------
.../hdds/server/TestPrometheusMetricsSink.java | 30 +++++++++++++++----
3 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/CSMMetrics.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/CSMMetrics.java
index def0d7f..ebbec4d 100644
--- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/CSMMetrics.java
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/CSMMetrics.java
@@ -62,7 +62,7 @@ public class CSMMetrics {
public CSMMetrics() {
int numCmdTypes = ContainerProtos.Type.values().length;
this.opsLatency = new MutableRate[numCmdTypes];
- this.registry = new MetricsRegistry(CSMMetrics.class.getName());
+ this.registry = new MetricsRegistry(CSMMetrics.class.getSimpleName());
for (int i = 0; i < numCmdTypes; i++) {
opsLatency[i] = registry.newRate(
ContainerProtos.Type.forNumber(i + 1).toString(),
diff --git a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/PrometheusMetricsSink.java b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/PrometheusMetricsSink.java
index 52532f1..df25cfc 100644
--- a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/PrometheusMetricsSink.java
+++ b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/PrometheusMetricsSink.java
@@ -23,7 +23,6 @@ import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
@@ -47,8 +46,8 @@ public class PrometheusMetricsSink implements MetricsSink {
*/
private Map<String, String> metricLines = new HashMap<>();
- private static final Pattern UPPER_CASE_SEQ =
- Pattern.compile("([A-Z]*)([A-Z])");
+ private static final Pattern SPLIT_PATTERN =
+ Pattern.compile("(?<!(^|[A-Z_]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])");
public PrometheusMetricsSink() {
}
@@ -88,7 +87,7 @@ public class PrometheusMetricsSink implements MetricsSink {
}
/**
- * Convert CamelCase based namess to lower-case names where the separator
+ * Convert CamelCase based names to lower-case names where the separator
* is the underscore, to follow prometheus naming conventions.
*/
public String prometheusName(String recordName,
@@ -99,29 +98,12 @@ public class PrometheusMetricsSink implements MetricsSink {
recordName.startsWith(ROCKSDB_CONTEXT_PREFIX)) {
return recordName.toLowerCase() + "_" + metricName.toLowerCase();
}
- String baseName = upperFirst(recordName) + upperFirst(metricName);
- Matcher m = UPPER_CASE_SEQ.matcher(baseName);
- StringBuffer sb = new StringBuffer();
- while (m.find()) {
- String replacement = "_" + m.group(2).toLowerCase();
- if (m.group(1).length() > 0) {
- replacement = "_" + m.group(1).toLowerCase() + replacement;
- }
- m.appendReplacement(sb, replacement);
- }
- m.appendTail(sb);
-
- //always prefixed with "_"
- return sb.toString().substring(1);
- }
-
- private String upperFirst(String name) {
- if (Character.isLowerCase(name.charAt(0))) {
- return Character.toUpperCase(name.charAt(0)) + name.substring(1);
- } else {
- return name;
- }
+ String baseName = StringUtils.capitalize(recordName)
+ + StringUtils.capitalize(metricName);
+ baseName = baseName.replace('-', '_');
+ String[] parts = SPLIT_PATTERN.split(baseName);
+ return String.join("_", parts).toLowerCase();
}
@Override
diff --git a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/TestPrometheusMetricsSink.java b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/TestPrometheusMetricsSink.java
index 0a8eb67..a1a9a55 100644
--- a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/TestPrometheusMetricsSink.java
+++ b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/TestPrometheusMetricsSink.java
@@ -30,7 +30,7 @@ import org.apache.hadoop.metrics2.lib.MutableCounterLong;
import org.junit.Assert;
import org.junit.Test;
-import static org.apache.commons.codec.CharEncoding.UTF_8;
+import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Test prometheus Sink.
@@ -59,10 +59,11 @@ public class TestPrometheusMetricsSink {
writer.flush();
//THEN
- System.out.println(stream.toString(UTF_8));
+ String writtenMetrics = stream.toString(UTF_8.name());
+ System.out.println(writtenMetrics);
Assert.assertTrue(
"The expected metric line is missing from prometheus metrics output",
- stream.toString(UTF_8).contains(
+ writtenMetrics.contains(
"test_metrics_num_bucket_create_fails{context=\"dfs\"")
);
@@ -71,7 +72,7 @@ public class TestPrometheusMetricsSink {
}
@Test
- public void testNaming() throws IOException {
+ public void testNamingCamelCase() {
PrometheusMetricsSink sink = new PrometheusMetricsSink();
Assert.assertEquals("rpc_time_some_metrics",
@@ -82,18 +83,35 @@ public class TestPrometheusMetricsSink {
Assert.assertEquals("rpc_time_small",
sink.prometheusName("RpcTime", "small"));
+ }
+ @Test
+ public void testNamingRocksDB() {
//RocksDB metrics are handled differently.
-
+ PrometheusMetricsSink sink = new PrometheusMetricsSink();
Assert.assertEquals("rocksdb_om.db_num_open_connections",
sink.prometheusName("Rocksdb_om.db", "num_open_connections"));
}
+ @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));
+ }
+
/**
* Example metric pojo.
*/
@Metrics(about = "Test Metrics", context = "dfs")
- public static class TestMetrics {
+ private static class TestMetrics {
@Metric
private MutableCounterLong numBucketCreateFails;
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org