ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From avija...@apache.org
Subject ambari git commit: AMBARI-15638 : [AMS] Sum Calculation Incorrect - Patch 2 (avijayan)
Date Wed, 06 Apr 2016 02:03:37 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 7343f6d6b -> dc366dbe7


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/dc366dbe
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/dc366dbe
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/dc366dbe

Branch: refs/heads/trunk
Commit: dc366dbe7f993630e1af91e656059c221007a3c0
Parents: 7343f6d
Author: Aravindan Vijayan <avijayan@hortonworks.com>
Authored: Tue Apr 5 19:03:26 2016 -0700
Committer: Aravindan Vijayan <avijayan@hortonworks.com>
Committed: Tue Apr 5 19:03:26 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/dc366dbe/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/dc366dbe/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 cb4fae7..6a16ee6 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(prevMetric.getTimestamp(), 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/dc366dbe/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 b4b3062..c8cef27 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";
 


Mime
View raw message