ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject [36/50] [abbrv] ambari git commit: AMBARI-22044 : Rate metrics should not have negative values whenever the underlying counter metric has been reset.(avijayan)
Date Tue, 26 Sep 2017 22:26:35 GMT
AMBARI-22044 : Rate metrics should not have negative values whenever the underlying counter
metric has been reset.(avijayan)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ced70f7d
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ced70f7d
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ced70f7d

Branch: refs/heads/branch-3.0-ams
Commit: ced70f7db01384e11b1a7f52fa0f64924eea0ab8
Parents: 84fed85
Author: Aravindan Vijayan <avijayan@hortonworks.com>
Authored: Mon Sep 25 22:16:20 2017 -0700
Committer: Aravindan Vijayan <avijayan@hortonworks.com>
Committed: Mon Sep 25 22:16:20 2017 -0700

----------------------------------------------------------------------
 .../timeline/HBaseTimelineMetricStore.java      |  8 +++--
 .../timeline/HBaseTimelineMetricStoreTest.java  | 36 +++++++++++---------
 2 files changed, 26 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ced70f7d/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
index ad1fd67..2342bd8 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
@@ -312,8 +312,12 @@ public class HBaseTimelineMetricStore extends AbstractService implements
Timelin
       if (prevTime != null) {
         step = currTime - prevTime;
         diff = currVal - prevVal;
-        Double rate = isDiff ? diff : (diff / TimeUnit.MILLISECONDS.toSeconds(step));
-        timeValueEntry.setValue(rate);
+        if (diff < 0) {
+          it.remove(); //Discard calculating rate when the metric counter has been reset.
+        } else {
+          Double rate = isDiff ? diff : (diff / TimeUnit.MILLISECONDS.toSeconds(step));
+          timeValueEntry.setValue(rate);
+        }
       } else {
         it.remove();
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/ced70f7d/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStoreTest.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStoreTest.java
b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStoreTest.java
index aae1d4b..70dd583 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStoreTest.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStoreTest.java
@@ -95,22 +95,26 @@ public class HBaseTimelineMetricStoreTest {
   @Test
   public void testRateCalculationOnMetricsWithEqualValues() throws Exception {
     Map<Long, Double> metricValues = new TreeMap<>();
-    metricValues.put(1454016368371L, 1011.25);
-    metricValues.put(1454016428371L, 1011.25);
-    metricValues.put(1454016488371L, 1011.25);
-    metricValues.put(1454016548371L, 1011.25);
-    metricValues.put(1454016608371L, 1011.25);
-    metricValues.put(1454016668371L, 1011.25);
-    metricValues.put(1454016728371L, 1011.25);
+    metricValues.put(1454000000000L, 1.0);
+    metricValues.put(1454000001000L, 6.0);
+    metricValues.put(1454000002000L, 0.0);
+    metricValues.put(1454000003000L, 3.0);
+    metricValues.put(1454000004000L, 4.0);
+    metricValues.put(1454000005000L, 7.0);
 
     // Calculate rate
     Map<Long, Double> rates = HBaseTimelineMetricStore.updateValuesAsRate(new TreeMap<>(metricValues),
false);
 
     // Make sure rate is zero
-    for (Map.Entry<Long, Double> rateEntry : rates.entrySet()) {
-      Assert.assertEquals("Rate should be zero, key = " + rateEntry.getKey()
-          + ", value = " + rateEntry.getValue(), 0.0, rateEntry.getValue());
-    }
+    Assert.assertTrue(rates.size() == 4);
+
+    Assert.assertFalse(rates.containsKey(1454000000000L));
+    Assert.assertFalse(rates.containsKey(1454000002000L));
+
+    Assert.assertEquals(rates.get(1454000001000L), 5.0);
+    Assert.assertEquals(rates.get(1454000003000L), 3.0);
+    Assert.assertEquals(rates.get(1454000004000L), 1.0);
+    Assert.assertEquals(rates.get(1454000005000L), 3.0);
   }
 
   @Test
@@ -119,14 +123,14 @@ public class HBaseTimelineMetricStoreTest {
     metricValues.put(1454016368371L, 1011.25);
     metricValues.put(1454016428371L, 1010.25);
     metricValues.put(1454016488371L, 1012.25);
-    metricValues.put(1454016548371L, 1010.25);
-    metricValues.put(1454016608371L, 1010.25);
+    metricValues.put(1454016548371L, 1015.25);
+    metricValues.put(1454016608371L, 1020.25);
 
     Map<Long, Double> rates = HBaseTimelineMetricStore.updateValuesAsRate(new TreeMap<>(metricValues),
true);
 
-    Assert.assertTrue(rates.size()==4);
-    Assert.assertTrue(rates.containsValue(-1.0));
+    Assert.assertTrue(rates.size() == 3);
     Assert.assertTrue(rates.containsValue(2.0));
-    Assert.assertTrue(rates.containsValue(0.0));
+    Assert.assertTrue(rates.containsValue(3.0));
+    Assert.assertTrue(rates.containsValue(5.0));
   }
 }


Mime
View raw message