gyfora commented on code in PR #774: URL: https://github.com/apache/flink-kubernetes-operator/pull/774#discussion_r1489399318
########## flink-autoscaler/src/main/java/org/apache/flink/autoscaler/ScalingMetricEvaluator.java: ########## @@ -341,6 +375,37 @@ public static double getAverage( return getAverage(metric, jobVertexId, metricsHistory, 1); } + public static double getRate( + ScalingMetric metric, + @Nullable JobVertexID jobVertexId, + SortedMap<Instant, CollectedMetrics> metricsHistory) { + + Instant firstTs = null; + double first = Double.NaN; + + Instant lastTs = null; + double last = Double.NaN; + + for (var entry : metricsHistory.entrySet()) { + double value = entry.getValue().getVertexMetrics().get(jobVertexId).get(metric); + if (!Double.isNaN(value)) { + if (Double.isNaN(first)) { + first = value; + firstTs = entry.getKey(); + } else { + last = value; + lastTs = entry.getKey(); + } + } + } + if (Double.isNaN(last)) { + return Double.NaN; + } + + double diff = last - first; + return diff == 0 ? 0 : diff / Duration.between(firstTs, lastTs).toSeconds(); Review Comment: I will this, I still had to change the logic so that we compute the seconds rate using the millisecond diff otherwise we can accidentally divide by zero -- 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