You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by av...@apache.org on 2016/04/06 02:19:07 UTC

ambari git commit: AMBARI-15638 : [AMS] Sum Calculation Incorrect - Patch 2 (avijayan)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 bc711e716 -> 599a64ae8


AMBARI-15638 : [AMS] Sum Calculation Incorrect - Patch 2 (avijayan)


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

Branch: refs/heads/branch-2.2
Commit: 599a64ae8fb7dc653e870814c23cd6cd301d51d1
Parents: bc711e7
Author: Aravindan Vijayan <av...@hortonworks.com>
Authored: Tue Apr 5 16:57:38 2016 -0700
Committer: Aravindan Vijayan <av...@hortonworks.com>
Committed: Tue Apr 5 16:57:38 2016 -0700

----------------------------------------------------------------------
 .../timeline/aggregators/AggregatorUtils.java   |  4 +--
 .../TimelineMetricClusterAggregatorSecond.java  | 34 +++++++++++++-------
 .../timeline/query/PhoenixTransactSQL.java      |  2 +-
 3 files changed, 25 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/599a64ae/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/AggregatorUtils.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/AggregatorUtils.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/AggregatorUtils.java
index 126b3a3..ce79b6f 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/AggregatorUtils.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/AggregatorUtils.java
@@ -43,11 +43,9 @@ public class AggregatorUtils {
             min = value;
           }
           sum += value;
-          if (value > 0.0) {
-            metricCount++;
-          }
         }
       }
+      metricCount = metricValues.values().size();
     }
     // BR: WHY ZERO is a good idea?
     values[0] = sum;

http://git-wip-us.apache.org/repos/asf/ambari/blob/599a64ae/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
index 67c463f..dacb32f 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
@@ -209,6 +209,11 @@ public class TimelineMetricClusterAggregatorSecond extends AbstractTimelineAggre
       timeShift = 0l;
     }
 
+    Long prevTimestamp = -1l;
+    TimelineClusterMetric prevMetric = null;
+    int count = 0;
+    double sum = 0.0;
+
     Map<Long,Double> timeSliceValueMap = new HashMap<>();
     for (Map.Entry<Long, Double> metric : timelineMetric.getMetricValues().entrySet()) {
       // TODO: investigate null values - pre filter
@@ -226,24 +231,31 @@ public class TimelineMetricClusterAggregatorSecond extends AbstractTimelineAggre
           timestamp,
           timelineMetric.getType());
 
-        // do a sum / count here to get average for all points in a slice
-        int count = 1;
-        Double sum = 0.0;
-        if (!timelineClusterMetricMap.containsKey(clusterMetric)) {
-          sum = metric.getValue();
-        } else {
+        if (prevTimestamp < 0 || timestamp.equals(prevTimestamp)) {
           Double newValue = metric.getValue();
           if (newValue > 0.0) {
+            sum += newValue;
             count++;
-            Double oldValue = timelineClusterMetricMap.get(clusterMetric);
-            sum = oldValue + newValue;
           }
+        } else {
+          double metricValue = (count > 0) ? (sum / count) : 0.0;
+          timelineClusterMetricMap.put(prevMetric, metricValue);
+          timeSliceValueMap.put(timestamp, metricValue);
+          sum = metric.getValue();
+          count = sum > 0.0 ? 1 : 0;
         }
-        double metricValue = sum / count;
-        timelineClusterMetricMap.put(clusterMetric, metricValue);
-        timeSliceValueMap.put(timestamp, metricValue);
+
+        prevTimestamp = timestamp;
+        prevMetric = clusterMetric;
       }
     }
+
+    if (prevTimestamp > 0) {
+      double metricValue = (count > 0) ? (sum / count) : 0.0;
+      timelineClusterMetricMap.put(prevMetric, metricValue);
+      timeSliceValueMap.put(prevTimestamp, metricValue);
+    }
+
     if (interpolationEnabled) {
       interpolateMissingPeriods(timelineClusterMetricMap, timelineMetric, timeSlices, timeSliceValueMap);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/599a64ae/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/PhoenixTransactSQL.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/PhoenixTransactSQL.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/PhoenixTransactSQL.java
index e3030f6..6a231c2 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/PhoenixTransactSQL.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/PhoenixTransactSQL.java
@@ -271,7 +271,7 @@ public class PhoenixTransactSQL {
   public static final String GET_AGGREGATED_APP_METRIC_GROUPBY_SQL = "UPSERT %s " +
     "INTO %s (METRIC_NAME, APP_ID, INSTANCE_ID, SERVER_TIME, UNITS, " +
     "METRIC_SUM, METRIC_COUNT, METRIC_MAX, METRIC_MIN) SELECT METRIC_NAME, APP_ID, " +
-    "INSTANCE_ID, %s AS SERVER_TIME, UNITS, AVG(METRIC_SUM), AVG(%s), " +
+    "INSTANCE_ID, %s AS SERVER_TIME, UNITS, ROUND(AVG(METRIC_SUM),2), ROUND(AVG(%s)), " +
     "MAX(METRIC_MAX), MIN(METRIC_MIN) FROM %s WHERE SERVER_TIME > %s AND " +
     "SERVER_TIME <= %s GROUP BY METRIC_NAME, APP_ID, INSTANCE_ID, UNITS";