HDFS-13686. Add overall metrics for FSNamesystemLock. Contributed by Lukas Majercak.

This commit is contained in:
Inigo Goiri 2018-06-15 15:59:19 -07:00
parent 1da3b55659
commit d31a3ce767
2 changed files with 20 additions and 7 deletions

View File

@ -107,6 +107,8 @@ class FSNamesystemLock {
private static final String WRITE_LOCK_METRIC_PREFIX = "FSNWriteLock"; private static final String WRITE_LOCK_METRIC_PREFIX = "FSNWriteLock";
private static final String LOCK_METRIC_SUFFIX = "Nanos"; private static final String LOCK_METRIC_SUFFIX = "Nanos";
private static final String OVERALL_METRIC_NAME = "Overall";
FSNamesystemLock(Configuration conf, FSNamesystemLock(Configuration conf,
MutableRatesWithAggregation detailedHoldTimeMetrics) { MutableRatesWithAggregation detailedHoldTimeMetrics) {
this(conf, detailedHoldTimeMetrics, new Timer()); this(conf, detailedHoldTimeMetrics, new Timer());
@ -320,12 +322,17 @@ class FSNamesystemLock {
*/ */
private void addMetric(String operationName, long value, boolean isWrite) { private void addMetric(String operationName, long value, boolean isWrite) {
if (metricsEnabled) { if (metricsEnabled) {
String metricName = String opMetric = getMetricName(operationName, isWrite);
(isWrite ? WRITE_LOCK_METRIC_PREFIX : READ_LOCK_METRIC_PREFIX) + detailedHoldTimeMetrics.add(opMetric, value);
org.apache.commons.lang.StringUtils.capitalize(operationName) +
LOCK_METRIC_SUFFIX; String overallMetric = getMetricName(OVERALL_METRIC_NAME, isWrite);
detailedHoldTimeMetrics.add(metricName, value); 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;
}
} }

View File

@ -333,7 +333,7 @@ public class TestFSNamesystemLock {
FSNamesystemLock fsLock = new FSNamesystemLock(conf, rates, timer); FSNamesystemLock fsLock = new FSNamesystemLock(conf, rates, timer);
fsLock.readLock(); fsLock.readLock();
timer.advanceNanos(1200000); timer.advanceNanos(1300000);
fsLock.readUnlock("foo"); fsLock.readUnlock("foo");
fsLock.readLock(); fsLock.readLock();
timer.advanceNanos(2400000); timer.advanceNanos(2400000);
@ -353,12 +353,18 @@ public class TestFSNamesystemLock {
MetricsRecordBuilder rb = MetricsAsserts.mockMetricsRecordBuilder(); MetricsRecordBuilder rb = MetricsAsserts.mockMetricsRecordBuilder();
rates.snapshot(rb, true); rates.snapshot(rb, true);
assertGauge("FSNReadLockFooNanosAvgTime", 1800000.0, rb); assertGauge("FSNReadLockFooNanosAvgTime", 1850000.0, rb);
assertCounter("FSNReadLockFooNanosNumOps", 2L, rb); assertCounter("FSNReadLockFooNanosNumOps", 2L, rb);
assertGauge("FSNReadLockBarNanosAvgTime", 2000000.0, rb); assertGauge("FSNReadLockBarNanosAvgTime", 2000000.0, rb);
assertCounter("FSNReadLockBarNanosNumOps", 1L, rb); assertCounter("FSNReadLockBarNanosNumOps", 1L, rb);
assertGauge("FSNWriteLockBazNanosAvgTime", 1000000.0, rb); assertGauge("FSNWriteLockBazNanosAvgTime", 1000000.0, rb);
assertCounter("FSNWriteLockBazNanosNumOps", 1L, rb); assertCounter("FSNWriteLockBazNanosNumOps", 1L, rb);
// Overall
assertGauge("FSNReadLockOverallNanosAvgTime", 1900000.0, rb);
assertCounter("FSNReadLockOverallNanosNumOps", 3L, rb);
assertGauge("FSNWriteLockOverallNanosAvgTime", 1000000.0, rb);
assertCounter("FSNWriteLockOverallNanosNumOps", 1L, rb);
} }
/** /**