gyfora commented on code in PR #774:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/774#discussion_r1493771207


##########
flink-autoscaler/src/main/java/org/apache/flink/autoscaler/ScalingMetricEvaluator.java:
##########
@@ -379,22 +484,75 @@ public static double getAverage(
         return n < minElements ? Double.NaN : sum / n;
     }
 
-    private static double getAverageOutputRatio(
-            Edge edge, SortedMap<Instant, CollectedMetrics> metricsHistory) {
-        double[] metricValues =
-                metricsHistory.values().stream()
-                        .map(CollectedMetrics::getOutputRatios)
-                        .filter(m -> m.containsKey(edge))
-                        .mapToDouble(m -> m.get(edge))
-                        .filter(d -> !Double.isNaN(d))
-                        .toArray();
-        for (double metricValue : metricValues) {
-            if (Double.isInfinite(metricValue)) {
-                // As long as infinite values are present, we can't properly 
average. We need to
-                // wait until they are evicted.
-                return metricValue;
+    @VisibleForTesting
+    protected static double computeOutputRatio(
+            JobVertexID from,
+            JobVertexID to,
+            JobTopology topology,
+            SortedMap<Instant, CollectedMetrics> metricsHistory) {
+
+        double numRecordsIn = getRate(ScalingMetric.NUM_RECORDS_IN, from, 
metricsHistory);
+
+        double outputRatio = 0;
+        // If the input rate is zero, we also need to flatten the output rate.
+        // Otherwise, the OUTPUT_RATIO would be outrageously large, leading to
+        // a rapid scale up.
+        if (numRecordsIn > 0) {
+            double numRecordsOut = computeEdgeRecordsOut(topology, 
metricsHistory, from, to);

Review Comment:
   I improved the variable/method names for this part of the logic



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to