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 xk...@apache.org on 2019/08/16 16:02:07 UTC
[hadoop] branch trunk updated: HADOOP-16391 Add a prefix to the
metric names for MutableRatesWithAggregation used for deferred RPC metrics
to avoid collision with non-deferred metrics. Contributed by Bilwa S T.
This is an automated email from the ASF dual-hosted git repository.
xkrogen pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new e356e4f HADOOP-16391 Add a prefix to the metric names for MutableRatesWithAggregation used for deferred RPC metrics to avoid collision with non-deferred metrics. Contributed by Bilwa S T.
e356e4f is described below
commit e356e4f4b70b756667f76c2f9d0d47eb8fceeb9d
Author: Erik Krogen <xk...@apache.org>
AuthorDate: Fri Aug 16 09:01:44 2019 -0700
HADOOP-16391 Add a prefix to the metric names for MutableRatesWithAggregation used for deferred RPC metrics to avoid collision with non-deferred metrics. Contributed by Bilwa S T.
---
.../apache/hadoop/ipc/metrics/RpcDetailedMetrics.java | 2 +-
.../metrics2/lib/MutableRatesWithAggregation.java | 9 ++++++++-
.../apache/hadoop/metrics2/lib/TestMutableMetrics.java | 17 +++++++++++++++++
3 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/metrics/RpcDetailedMetrics.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/metrics/RpcDetailedMetrics.java
index 67ae4cc..98b9f26 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/metrics/RpcDetailedMetrics.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/metrics/RpcDetailedMetrics.java
@@ -61,7 +61,7 @@ public class RpcDetailedMetrics {
*/
public void init(Class<?> protocol) {
rates.init(protocol);
- deferredRpcRates.init(protocol);
+ deferredRpcRates.init(protocol, "Deferred");
}
/**
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableRatesWithAggregation.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableRatesWithAggregation.java
index 26a1506..aa7b759 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableRatesWithAggregation.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableRatesWithAggregation.java
@@ -58,6 +58,8 @@ public class MutableRatesWithAggregation extends MutableMetric {
weakReferenceQueue = new ConcurrentLinkedDeque<>();
private final ThreadLocal<ConcurrentMap<String, ThreadSafeSampleStat>>
threadLocalMetricsMap = new ThreadLocal<>();
+ // prefix for metric name
+ private String typePrefix = "";
/**
* Initialize the registry with all the methods in a protocol
@@ -148,7 +150,7 @@ public class MutableRatesWithAggregation extends MutableMetric {
private synchronized MutableRate addMetricIfNotExists(String name) {
MutableRate metric = globalMetrics.get(name);
if (metric == null) {
- metric = new MutableRate(name, name, false);
+ metric = new MutableRate(name + typePrefix, name + typePrefix, false);
globalMetrics.put(name, metric);
}
return metric;
@@ -170,4 +172,9 @@ public class MutableRatesWithAggregation extends MutableMetric {
}
}
+ public void init(Class<?> protocol, String prefix) {
+ this.typePrefix = prefix;
+ init(protocol);
+ }
+
}
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java
index 29d47cf..b5f62b1 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java
@@ -274,6 +274,23 @@ public class TestMutableMetrics {
}
}
+ @Test
+ public void testDuplicateMetrics() {
+ MutableRatesWithAggregation rates = new MutableRatesWithAggregation();
+ MutableRatesWithAggregation deferredRpcRates =
+ new MutableRatesWithAggregation();
+ Class<?> protocol = Long.class;
+ rates.init(protocol);
+ deferredRpcRates.init(protocol, "Deferred");
+ MetricsRecordBuilder rb = mockMetricsRecordBuilder();
+ rates.snapshot(rb, true);
+ deferredRpcRates.snapshot(rb, true);
+ verify(rb, times(1))
+ .addCounter(info("GetLongNumOps", "Number of ops for getLong"), 0L);
+ verify(rb, times(1)).addCounter(
+ info("GetLongDeferredNumOps", "Number of ops for getLongDeferred"), 0L);
+ }
+
/**
* Tests that when using {@link MutableStat#add(long, long)}, even with a high
* sample count, the mean does not lose accuracy.
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org