Dennis-Mircea commented on code in PR #1099: URL: https://github.com/apache/flink-kubernetes-operator/pull/1099#discussion_r3426456075
########## flink-autoscaler/src/main/java/org/apache/flink/autoscaler/metrics/FlinkAutoscalerEvaluator.java: ########## @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.autoscaler.metrics; + +import org.apache.flink.autoscaler.topology.JobTopology; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.runtime.jobgraph.JobVertexID; + +import java.time.Duration; +import java.time.Instant; +import java.util.Map; +import java.util.SortedMap; + +/** + * A pluggable plugin that allows users to provide custom scaling-metric evaluation logic on top of + * the metrics evaluated internally by the autoscaler. Implementations are invoked once per job + * vertex during each evaluation cycle, and the metrics they return are merged on top of the + * internally evaluated metrics, allowing users to override or augment specific {@link + * ScalingMetric} values. + * + * <p>Only one custom metric evaluator per pipeline is supported for now. If multiple instances are + * configured, the autoscaler logs a warning and falls back to the first entry, ignoring the rest. + * Registering multiple implementations via {@code META-INF/services} is fine as they form a + * registry that different jobs can select from by class FQN, but a single job cannot chain or + * compose more than one evaluator. + * + * <p>This was introduced as part of <a + * href="https://cwiki.apache.org/confluence/display/FLINK/FLIP-514%3A+Custom+Evaluator+plugin+for+Flink+Autoscaler">FLIP-514: + * Custom Evaluator plugin for Flink Autoscaler</a> and is complementary to <a + * href="https://cwiki.apache.org/confluence/display/FLINK/FLIP-575%3A+Scaling+Executor+Plugin+SPI+for+Flink+Autoscaler">FLIP-575: + * Scaling Executor Plugin SPI for Flink Autoscaler</a> which provides extensibility at the scaling + * decision execution layer. + * + * <p>Implementations are discovered via Java's {@link java.util.ServiceLoader} mechanism. To + * register a custom metric evaluator, add the fully qualified class name of the implementation to + * {@code META-INF/services/org.apache.flink.autoscaler.metrics.FlinkAutoscalerEvaluator}. + */ +public interface FlinkAutoscalerEvaluator { + + /** + * Evaluates scaling metrics for a given job vertex based on the internally evaluated metrics + * and context. + * + * @param vertex The {@link JobVertexID} identifying the vertex whose metrics are being + * evaluated. + * @param evaluatedMetrics An un-modifiable view of current vertex internally evaluated metrics. + * @param evaluationContext The evaluation context providing job-related configurations and + * historical metrics. + * @return A map of evaluated scaling metrics for the vertex which would get merged with + * internally evaluated metrics. + * @throws UnsupportedOperationException if an attempt is made to modify the {@code + * evaluatedMetrics}, {@code Context.jobConf}, {@code Context.metricsHistory}, {@code + * Context.evaluatedVertexMetrics}. + */ + Map<ScalingMetric, EvaluatedScalingMetric> evaluateVertexMetrics( + JobVertexID vertex, + Map<ScalingMetric, EvaluatedScalingMetric> evaluatedMetrics, + Context evaluationContext); + + /** + * Context providing relevant job and metric information to assist in custom metric evaluation. + */ + class Context { + private final Configuration jobConf; Review Comment: `customEvaluatorConf` is already derived from `jobConf`: `AutoScalerOptions.customEvaluatorConfiguration(conf, name)` takes the `job.autoscaler.metrics.custom-evaluator.<name>.` subtree and strips the prefix, so evaluator-specific keys are handed over ready to read by their short name. Merging the two back into one map would re-introduce exactly the prefix-handling boilerplate this helper removes, and authors would have to re-derive their own scope. `jobConf` is still there (unmodifiable) for evaluators that need the full job view, so both use cases are covered. -- 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]
