Dennis-Mircea commented on code in PR #1099:
URL:
https://github.com/apache/flink-kubernetes-operator/pull/1099#discussion_r3427233583
##########
flink-autoscaler/src/main/java/org/apache/flink/autoscaler/ScalingMetricEvaluator.java:
##########
@@ -588,4 +635,76 @@ protected static double computeEdgeDataRate(
to);
return getRate(ScalingMetric.NUM_RECORDS_OUT, from, metricsHistory);
}
+
+ /**
+ * Executes the provided custom metric evaluator for the given job vertex.
Calls {@link
+ * FlinkAutoscalerEvaluator#evaluateVertexMetrics} to evaluate scaling
metrics.
+ *
+ * @param vertex The job vertex being evaluated.
+ * @param evaluatedMetrics Current evaluated metrics.
+ * @param customEvaluationSession A tuple containing the custom metric
evaluator and evaluation
+ * context.
+ * @return A map of scaling metrics, with its corresponding evaluated
scaling metric.
+ */
+ @VisibleForTesting
+ protected static Map<ScalingMetric, EvaluatedScalingMetric>
runCustomEvaluator(
+ JobVertexID vertex,
+ Map<ScalingMetric, EvaluatedScalingMetric> evaluatedMetrics,
+ Tuple2<FlinkAutoscalerEvaluator, FlinkAutoscalerEvaluator.Context>
+ customEvaluationSession) {
+ try {
+ return customEvaluationSession.f0.evaluateVertexMetrics(
+ vertex, evaluatedMetrics, customEvaluationSession.f1);
+ } catch (UnsupportedOperationException e) {
+ LOG.warn(
+ "Custom metric evaluator {} tried accessing an
un-modifiable view.",
+ customEvaluationSession.f0.getClass(),
+ e);
+ } catch (Exception e) {
+ LOG.warn(
+ "Custom metric evaluator {} threw an exception.",
+ customEvaluationSession.f0.getClass(),
+ e);
+ }
+
+ return Collections.emptyMap();
+ }
+
+ /**
+ * Merges the incoming evaluated metrics into actual evaluated metrics.
+ *
+ * @param actual The target evaluated metrics map to merge into.
+ * @param incoming The incoming map containing new evaluated metrics map
to be merged
+ * (nullable).
+ */
Review Comment:
Fixed!
##########
flink-autoscaler/src/main/java/org/apache/flink/autoscaler/ScalingMetricEvaluator.java:
##########
@@ -588,4 +635,76 @@ protected static double computeEdgeDataRate(
to);
return getRate(ScalingMetric.NUM_RECORDS_OUT, from, metricsHistory);
}
+
+ /**
+ * Executes the provided custom metric evaluator for the given job vertex.
Calls {@link
+ * FlinkAutoscalerEvaluator#evaluateVertexMetrics} to evaluate scaling
metrics.
+ *
+ * @param vertex The job vertex being evaluated.
+ * @param evaluatedMetrics Current evaluated metrics.
+ * @param customEvaluationSession A tuple containing the custom metric
evaluator and evaluation
+ * context.
+ * @return A map of scaling metrics, with its corresponding evaluated
scaling metric.
+ */
+ @VisibleForTesting
+ protected static Map<ScalingMetric, EvaluatedScalingMetric>
runCustomEvaluator(
+ JobVertexID vertex,
+ Map<ScalingMetric, EvaluatedScalingMetric> evaluatedMetrics,
+ Tuple2<FlinkAutoscalerEvaluator, FlinkAutoscalerEvaluator.Context>
+ customEvaluationSession) {
+ try {
+ return customEvaluationSession.f0.evaluateVertexMetrics(
+ vertex, evaluatedMetrics, customEvaluationSession.f1);
+ } catch (UnsupportedOperationException e) {
+ LOG.warn(
+ "Custom metric evaluator {} tried accessing an
un-modifiable view.",
+ customEvaluationSession.f0.getClass(),
+ e);
+ } catch (Exception e) {
+ LOG.warn(
+ "Custom metric evaluator {} threw an exception.",
+ customEvaluationSession.f0.getClass(),
+ e);
+ }
+
+ return Collections.emptyMap();
+ }
+
+ /**
+ * Merges the incoming evaluated metrics into actual evaluated metrics.
+ *
+ * @param actual The target evaluated metrics map to merge into.
+ * @param incoming The incoming map containing new evaluated metrics map
to be merged
+ * (nullable).
+ */
+ @VisibleForTesting
+ protected static void mergeEvaluatedMetricsMaps(
+ Map<ScalingMetric, EvaluatedScalingMetric> actual,
+ @Nullable Map<ScalingMetric, EvaluatedScalingMetric> incoming) {
+ Optional.ofNullable(incoming)
+ .ifPresent(
+ customEvaluatedMetric ->
+ customEvaluatedMetric.forEach(
+ (scalingMetric,
evaluatedScalingMetric) ->
+ actual.merge(
+ scalingMetric,
+ evaluatedScalingMetric,
+ ScalingMetricEvaluator
+
::mergeEvaluatedScalingMetric)));
+ }
+
+ /**
+ * Merges two {@link EvaluatedScalingMetric} instances.
+ *
+ * @param actual The existing evaluated scaling metric.
+ * @param incoming The incoming evaluated scaling metric.
+ * @return A new {@link EvaluatedScalingMetric} instance with merged
values.
+ */
Review Comment:
Fixed!
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]