Dennis-Mircea opened a new pull request, #1099:
URL: https://github.com/apache/flink-kubernetes-operator/pull/1099
<!--
*Thank you very much for contributing to the Apache Flink Kubernetes
Operator - we are happy that you want to help us improve the project. To help
the community review your contribution in the best possible way, please go
through the checklist below, which will get the contribution into a shape in
which it can be best reviewed.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA
issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are
made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "[FLINK-XXXX] [component] Title of the
pull request", where *FLINK-XXXX* should be replaced by the actual issue
number. Skip *component* if you are unsure about which is the best component.
Typo fixes that have no associated JIRA issue should be named following
this pattern: `[hotfix][docs] Fix typo in event time introduction` or
`[hotfix][javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
- Fill out the template below to describe the changes contributed by the
pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests, i.e., `mvn clean
verify` passes. You can read more on how we use GitHub Actions for CI
[here](https://nightlies.apache.org/flink/flink-kubernetes-operator-docs-main/docs/development/guide/#cicd).
- Each pull request should address only one issue, not mix up code from
multiple issues.
- Each commit in the pull request has a meaningful commit message
(including the JIRA id)
- Once all items of the checklist are addressed, remove the above text and
this checklist, leaving only the filled out template below.
**(The sections below can be removed for hotfixes of typos)**
-->
## What is the purpose of the change
This PR implements the
[FLIP-514](https://cwiki.apache.org/confluence/display/FLINK/FLIP-514%3A+Custom+Evaluator+plugin+for+Flink+Autoscaler)
and is a continuation of the work done as part of
https://github.com/apache/flink-kubernetes-operator/pull/953 PR.
It introduces a pluggable `FlinkAutoscalerEvaluator` SPI that lets users
provide custom scaling-metric evaluation logic on top of the metrics evaluated
internally by the autoscaler, both in the Flink Kubernetes Operator (via the
Flink Plugins mechanism) and in `flink-autoscaler-standalone` (via the standard
Java `ServiceLoader`). The evaluator returned map is merged on top of the
internally-evaluated metrics for each job vertex, so users can override or
augment specific `ScalingMetric` values (e.g. `TARGET_DATA_RATE`,
`TRUE_PROCESSING_RATE`, `CATCH_UP_DATA_RATE`) without forking the autoscaler.
## Brief change log
- Introduced the `FlinkAutoscalerEvaluator` SPI (`flink-autoscaler`) with
`getName()`, `evaluateVertexMetrics(vertex, evaluatedMetrics, Context)` and a
`Context` exposing an un-modifiable view of `jobConf`, `metricsHistory`,
previously evaluated vertex metrics, `topology`, `processingBacklog`,
`restartTime` and the evaluator-specific `customEvaluatorConf`.
- Added the `job.autoscaler.metrics.custom-evaluator.name` config option and
`AutoScalerOptions#forCustomEvaluator(conf, name)` helper, which builds a
`DelegatingConfiguration` scoped to
`job.autoscaler.metrics.custom-evaluator.<name>.` for the evaluator.
- Wired custom-evaluator resolution into
`JobAutoScalerImpl#getCustomEvaluatorIfRequired` and passed the resolved
`Tuple2<FlinkAutoscalerEvaluator, Configuration>` down to
`ScalingMetricEvaluator`, which now calls the evaluator per vertex in
topological order and merges the returned metrics on top of the internally
evaluated ones.
- Added operator-side discovery in
`org.apache.flink.kubernetes.operator.autoscaler.AutoscalerUtils#discoverCustomEvaluators(Configuration)`
using the Flink `PluginManager` (`/opt/flink/plugins`). The discovered
evaluators are injected into `JobAutoScalerImpl` from `FlinkOperator`.
- Added standalone-side discovery in
`org.apache.flink.autoscaler.standalone.AutoscalerUtils#discoverCustomEvaluators()`
using `ServiceLoader.load(FlinkAutoscalerEvaluator.class)` and wired it into
`StandaloneAutoscalerEntrypoint#createJobAutoscaler`.
- Documented the new plugin in both language variants of
`docs/.../operations/plugins.md` under a new *Custom Flink Autoscaler
Evaluator* section, including a warning hint that a single custom evaluator is
supported per pipeline today.
## Verifying this change
<!--
Please make sure both new and modified tests in this PR follows the
conventions defined in our code quality guide:
https://flink.apache.org/contributing/code-style-and-quality-common.html#testing
-->
This change added tests and can be verified as follows:
- **Evaluator resolution and override semantics** (`flink-autoscaler`):
- `JobAutoScalerImplTest#testGetCustomEvaluatorIfRequired` covers the
registry lookup (configured name present / absent / unknown) and the
per-evaluator `DelegatingConfiguration` built by
`AutoScalerOptions.forCustomEvaluator`.
- `MetricsCollectionAndEvaluationTest` exercises end-to-end evaluation
with a `TestCustomEvaluator` override on `TARGET_DATA_RATE` for source vertices
and asserts that the custom value wins over the internally computed one while
the rest of the metrics remain untouched.
- **Operator-side plugin discovery** (`flink-kubernetes-operator`):
- `TestingFlinkDeploymentController` / `FlinkOperator` wiring verified by
existing controller tests loading the `TestCustomEvaluator` via
`META-INF/services`.
- **Standalone-side SPI discovery** (`flink-autoscaler-standalone`):
- New `AutoscalerUtilsTest#testDiscoverCustomEvaluators` registers
`TestCustomEvaluator` through
`META-INF/services/org.apache.flink.autoscaler.metrics.FlinkAutoscalerEvaluator`
and asserts that `AutoscalerUtils.discoverCustomEvaluators()` finds it keyed
by `getName()`.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changes to the `CustomResourceDescriptors`:
no
- Core observer or reconciler logic that is regularly executed: no
## Documentation
- Does this pull request introduce a new feature? yes
- If yes, how is the feature documented? docs & JavaDocs
--
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]