From 327297a6006ac60ea5e76bfccbe7354a113f8d1b Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Wed, 13 Jan 2016 15:43:47 -0800 Subject: [PATCH] HADOOP-12683. Add number of samples in last interval in snapshot of MutableStat. (Vikram Srivastava via kasha) (cherry picked from commit fb64e6051a65b43e1db051915af84711a8120ea1) --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../apache/hadoop/metrics2/lib/MutableStat.java | 6 +++++- .../hadoop/metrics2/lib/TestMutableMetrics.java | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 47882128e24..d82806cef62 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/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 diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableStat.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableStat.java index 9410c76e218..510862450eb 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableStat.java +++ b/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) { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java index ed83000390e..e9f4e10d7cc 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java +++ b/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 {