hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sur...@apache.org
Subject svn commit: r1451385 - in /hadoop/common/branches/branch-1/src: hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java test/org/apache/hadoop/test/MetricsAsserts.java
Date Thu, 28 Feb 2013 22:07:07 GMT
Author: suresh
Date: Thu Feb 28 22:07:07 2013
New Revision: 1451385

URL: http://svn.apache.org/r1451385
Log:
HDFS-4518. Finer grained metrics for HDFS capacity. Contributed by Arpit Agarwal.

Modified:
    hadoop/common/branches/branch-1/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
    hadoop/common/branches/branch-1/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java
    hadoop/common/branches/branch-1/src/test/org/apache/hadoop/test/MetricsAsserts.java

Modified: hadoop/common/branches/branch-1/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java?rev=1451385&r1=1451384&r2=1451385&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
(original)
+++ hadoop/common/branches/branch-1/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
Thu Feb 28 22:07:07 2013
@@ -6383,6 +6383,10 @@ public class FSNamesystem implements FSC
                 roundBytesToGBytes(getCapacityUsed()))
       .addGauge("CapacityRemainingGB", "",
                 roundBytesToGBytes(getCapacityRemaining()))
+      .addGauge("CapacityTotal", "", getCapacityTotal())
+      .addGauge("CapacityUsed", "", getCapacityUsed())
+      .addGauge("CapacityRemaining", "", getCapacityRemaining())
+      .addGauge("CapacityUsedNonDFS", "", getNonDfsUsedSpace())
       .addGauge("TotalLoad", "", getTotalLoad())
       .addGauge("CorruptBlocks", "", getCorruptReplicaBlocks())
       .addGauge("ExcessBlocks", "", getExcessBlocks())

Modified: hadoop/common/branches/branch-1/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java?rev=1451385&r1=1451384&r2=1451385&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java
(original)
+++ hadoop/common/branches/branch-1/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java
Thu Feb 28 22:07:07 2013
@@ -101,6 +101,23 @@ public class TestNameNodeMetrics extends
     stm.close();
   }
 
+  /**
+   * Test that capacity metrics are exported and pass
+   * basic sanity tests.
+   */
+  public void testCapacityMetrics() throws Exception {
+    MetricsRecordBuilder rb = getMetrics(fsnMetrics);
+    long capacityTotal = getLongGauge("CapacityTotal", rb);
+    assert(capacityTotal != 0);
+    long capacityUsed = getLongGauge("CapacityUsed", rb);
+    long capacityRemaining =
+        getLongGauge("CapacityRemaining", rb);
+    long capacityUsedNonDFS =
+        getLongGauge("CapacityUsedNonDFS", rb);
+    assert(capacityUsed + capacityRemaining + capacityUsedNonDFS ==
+        capacityTotal);
+  }  
+
   /** Test metrics associated with addition of a file */
   public void testFileAdd() throws Exception {
     // Add files with 32 blocks

Modified: hadoop/common/branches/branch-1/src/test/org/apache/hadoop/test/MetricsAsserts.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/test/org/apache/hadoop/test/MetricsAsserts.java?rev=1451385&r1=1451384&r2=1451385&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/test/org/apache/hadoop/test/MetricsAsserts.java (original)
+++ hadoop/common/branches/branch-1/src/test/org/apache/hadoop/test/MetricsAsserts.java Thu
Feb 28 22:07:07 2013
@@ -21,6 +21,9 @@ package org.apache.hadoop.test;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import static org.mockito.Mockito.*;
+
+import org.junit.Assert;
+import org.mockito.ArgumentCaptor;
 import org.mockito.stubbing.Answer;
 import org.mockito.invocation.InvocationOnMock;
 import static org.mockito.AdditionalMatchers.*;
@@ -174,6 +177,29 @@ public class MetricsAsserts {
   }
 
   /**
+   * Check that this metric was captured exactly once.
+   */
+  private static void checkCaptured(ArgumentCaptor<?> captor, String name) {
+    Assert.assertEquals("Expected exactly one metric for name " + name,
+        1, captor.getAllValues().size());
+  }
+
+  /**
+   * Lookup the value of a long metric by name. Throws exception if the
+   * metric could not be found.
+   *
+   * @param name of the metric.
+   * @param rb  the record builder mock used to getMetrics
+   * @return the long value of the metric if found.
+   */
+  public static long getLongGauge(String name, MetricsRecordBuilder rb) {
+    ArgumentCaptor<Long> captor = ArgumentCaptor.forClass(Long.class);
+    verify(rb, atLeast(0)).addGauge(eq(name), anyString(), captor.capture());
+    checkCaptured(captor, name);
+    return captor.getValue();
+  }
+
+  /**
    * Assert that a double gauge metric is greater than a value
    * @param name  of the metric
    * @param greater value of the metric should be greater than this



Mime
View raw message