Forráskód Böngészése

HADOOP-12683. Add number of samples in last interval in snapshot of MutableStat. (Vikram Srivastava via kasha)

(cherry picked from commit fb64e6051a65b43e1db051915af84711a8120ea1)
Karthik Kambatla 9 éve
szülő
commit
327297a600

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -22,6 +22,9 @@ Release 2.9.0 - UNRELEASED
     when using kerberos and attempting to bind to any port on the local IP
     address (cmccabe)
 
+    HADOOP-12683. Add number of samples in last interval in snapshot of 
+    MutableStat. (Vikram Srivastava via kasha)
+
   BUG FIXES
 
     HADOOP-12655. TestHttpServer.testBindAddress bind port range is wider

+ 5 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableStat.java

@@ -41,6 +41,7 @@ public class MutableStat extends MutableMetric {
   private final MetricsInfo iMaxInfo;
   private final MetricsInfo minInfo;
   private final MetricsInfo maxInfo;
+  private final MetricsInfo iNumInfo;
 
   private final SampleStat intervalStat = new SampleStat();
   private final SampleStat prevStat = new SampleStat();
@@ -65,6 +66,8 @@ public class MutableStat extends MutableMetric {
     String lsName = StringUtils.uncapitalize(sampleName);
     String lvName = StringUtils.uncapitalize(valueName);
     numInfo = info(ucName +"Num"+ usName, "Number of "+ lsName +" for "+ desc);
+    iNumInfo = info(ucName +"INum"+ usName,
+                    "Interval number of "+ lsName +" for "+ desc);
     avgInfo = info(ucName +"Avg"+ uvName, "Average "+ lvName +" for "+ desc);
     stdevInfo = info(ucName +"Stdev"+ uvName,
                      "Standard deviation of "+ lvName +" for "+ desc);
@@ -127,7 +130,8 @@ public class MutableStat extends MutableMetric {
                .addGauge(iMinInfo, lastStat().min())
                .addGauge(iMaxInfo, lastStat().max())
                .addGauge(minInfo, minMax.min())
-               .addGauge(maxInfo, minMax.max());
+               .addGauge(maxInfo, minMax.max())
+               .addGauge(iNumInfo, lastStat().numSamples());
       }
       if (changed()) {
         if (numSamples > 0) {

+ 14 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java

@@ -86,6 +86,10 @@ public class TestMutableMetrics {
                            eq(0.0, EPSILON));
     verify(mb).addGauge(eq(info("S1MaxTime","Max time for stat")),
                            eq(0.0, EPSILON));
+    verify(mb).addGauge(
+        eq(info("S1INumOps", "Interval number of ops for stat")),
+        eq(1L));
+
     verify(mb, times(2))
         .addCounter(info("S2NumOps", "Number of ops for stat"), 1L);
     verify(mb, times(2)).addGauge(eq(info("S2AvgTime",
@@ -94,6 +98,16 @@ public class TestMutableMetrics {
     verify(mb).addCounter(info("S2NumOps", "Number of ops for stat"), 2L);
     verify(mb).addGauge(eq(info("S2AvgTime", "Average time for stat")),
                            eq(1.0, EPSILON));
+
+    // Add one more sample to s1 and verify that total number of ops
+    // has increased to 2, but interval number is 1 for both intervals.
+    MutableStat s1 = (MutableStat) registry.get("s1");
+    s1.add(0);
+    registry.snapshot(mb, true);
+    verify(mb).addCounter(info("S1NumOps", "Number of ops for stat"), 2L);
+    verify(mb, times(2)).addGauge(
+        eq(info("S1INumOps", "Interval number of ops for stat")),
+        eq(1L));
   }
 
   interface TestProtocol {