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 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 @@ class FSNamesystemLock {
*/
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;
}
}

View File

@ -333,7 +333,7 @@ public class TestFSNamesystemLock {
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 class TestFSNamesystemLock {
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);
}
/**