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 commit is contained in:
parent
9a1d8cfaf5
commit
e356e4f4b7
@ -61,7 +61,7 @@ public static RpcDetailedMetrics create(int port) {
|
||||
*/
|
||||
public void init(Class<?> protocol) {
|
||||
rates.init(protocol);
|
||||
deferredRpcRates.init(protocol);
|
||||
deferredRpcRates.init(protocol, "Deferred");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 @@ Map<String, MutableRate> getGlobalMetrics() {
|
||||
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 @@ synchronized void snapshotInto(MutableRate metric) {
|
||||
}
|
||||
}
|
||||
|
||||
public void init(Class<?> protocol, String prefix) {
|
||||
this.typePrefix = prefix;
|
||||
init(protocol);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -274,6 +274,23 @@ private static void snapshotMutableRatesWithAggregation(
|
||||
}
|
||||
}
|
||||
|
||||
@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.
|
||||
|
Loading…
Reference in New Issue
Block a user