From d31a3ce767d3bb68bdbb4f36d45600eab9f4f8b7 Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Fri, 15 Jun 2018 15:59:19 -0700 Subject: [PATCH] HDFS-13686. Add overall metrics for FSNamesystemLock. Contributed by Lukas Majercak. --- .../hdfs/server/namenode/FSNamesystemLock.java | 17 ++++++++++++----- .../server/namenode/TestFSNamesystemLock.java | 10 ++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java index 900f8a2291..f8e69e288e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java @@ -107,6 +107,8 @@ public Long initialValue() { private static final String WRITE_LOCK_METRIC_PREFIX = "FSNWriteLock"; private static final String LOCK_METRIC_SUFFIX = "Nanos"; + private static final String OVERALL_METRIC_NAME = "Overall"; + FSNamesystemLock(Configuration conf, MutableRatesWithAggregation detailedHoldTimeMetrics) { this(conf, detailedHoldTimeMetrics, new Timer()); @@ -320,12 +322,17 @@ public int getQueueLength() { */ private void addMetric(String operationName, long value, boolean isWrite) { if (metricsEnabled) { - String metricName = - (isWrite ? WRITE_LOCK_METRIC_PREFIX : READ_LOCK_METRIC_PREFIX) + - org.apache.commons.lang.StringUtils.capitalize(operationName) + - LOCK_METRIC_SUFFIX; - detailedHoldTimeMetrics.add(metricName, value); + String opMetric = getMetricName(operationName, isWrite); + detailedHoldTimeMetrics.add(opMetric, value); + + String overallMetric = getMetricName(OVERALL_METRIC_NAME, isWrite); + detailedHoldTimeMetrics.add(overallMetric, value); } } + private static String getMetricName(String operationName, boolean isWrite) { + return (isWrite ? WRITE_LOCK_METRIC_PREFIX : READ_LOCK_METRIC_PREFIX) + + org.apache.commons.lang.StringUtils.capitalize(operationName) + + LOCK_METRIC_SUFFIX; + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemLock.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemLock.java index 2daf5c2cf6..49506fe54d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemLock.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemLock.java @@ -333,7 +333,7 @@ public void testDetailedHoldMetrics() throws Exception { FSNamesystemLock fsLock = new FSNamesystemLock(conf, rates, timer); fsLock.readLock(); - timer.advanceNanos(1200000); + timer.advanceNanos(1300000); fsLock.readUnlock("foo"); fsLock.readLock(); timer.advanceNanos(2400000); @@ -353,12 +353,18 @@ public void testDetailedHoldMetrics() throws Exception { MetricsRecordBuilder rb = MetricsAsserts.mockMetricsRecordBuilder(); rates.snapshot(rb, true); - assertGauge("FSNReadLockFooNanosAvgTime", 1800000.0, rb); + assertGauge("FSNReadLockFooNanosAvgTime", 1850000.0, rb); assertCounter("FSNReadLockFooNanosNumOps", 2L, rb); assertGauge("FSNReadLockBarNanosAvgTime", 2000000.0, rb); assertCounter("FSNReadLockBarNanosNumOps", 1L, rb); assertGauge("FSNWriteLockBazNanosAvgTime", 1000000.0, rb); assertCounter("FSNWriteLockBazNanosNumOps", 1L, rb); + + // Overall + assertGauge("FSNReadLockOverallNanosAvgTime", 1900000.0, rb); + assertCounter("FSNReadLockOverallNanosNumOps", 3L, rb); + assertGauge("FSNWriteLockOverallNanosAvgTime", 1000000.0, rb); + assertCounter("FSNWriteLockOverallNanosNumOps", 1L, rb); } /**