You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`ScalingMetricsEvaluatorPlugin` is a pluggable component that allows users to provide custom scaling-metric evaluation logic on top of the metrics evaluated internally by the autoscaler. Custom metric evaluators are discovered through the [Plugins](https://nightlies.apache.org/flink/flink-docs-master/docs/deployment/filesystems/plugins) mechanism when running inside the Kubernetes operator, and through the standard Java `ServiceLoader` mechanism when running with `flink-autoscaler-standalone`. In both cases the implementation class must be registered in `META-INF/services`.
192
+
193
+
For each evaluation cycle, the autoscaler invokes the custom metric evaluator selected via the `job.autoscaler.metrics.custom-evaluators` configuration option once per job vertex. The metrics returned by the custom evaluator are merged on top of the internally evaluated metrics, allowing users to override or augment specific `ScalingMetric` values (e.g. `TARGET_DATA_RATE`, `TRUE_PROCESSING_RATE`, `CATCH_UP_DATA_RATE`).
194
+
195
+
All `job.autoscaler.*` keys related to custom metric evaluators also support the legacy `kubernetes.operator.`-prefixed form as a fallback (for example, `kubernetes.operator.job.autoscaler.metrics.custom-evaluators`). The canonical key takes precedence on overlap.
196
+
197
+
The following steps demonstrate how to develop and use a custom metric evaluator.
198
+
199
+
1. Implement the `ScalingMetricsEvaluatorPlugin` interface:
if (target > 0 && context.getTopology().isSource(vertex)) {
224
+
overrides.put(
225
+
ScalingMetric.TARGET_DATA_RATE,
226
+
EvaluatedScalingMetric.avg(target));
227
+
}
228
+
return overrides;
229
+
}
230
+
}
231
+
```
232
+
233
+
The `Context` object exposes an un-modifiable view of the configuration, the metrics history, previously evaluated vertex metrics (evaluation happens topologically), the job topology, backlog status, and max restart time. The configuration is the job configuration with the evaluator-specific options (prefix stripped) merged on top, so an evaluator-specific key overrides the job-level value of the same key.
234
+
235
+
2. Create the service definition file `org.apache.flink.autoscaler.metrics.ScalingMetricsEvaluatorPlugin` in `META-INF/services` with the fully-qualified class name of your implementation:
3. Use the Maven tool to package the project and generate the custom metric evaluator JAR.
241
+
242
+
4. Select the custom metric evaluator via configuration. The evaluator whose implementation class FQN matches the configured `job.autoscaler.metrics.custom-evaluator.<name>.class` value will be invoked, and any other `job.autoscaler.metrics.custom-evaluator.<name>.*` entries are merged on top of the job configuration with the `job.autoscaler.metrics.custom-evaluator.<instance>.` prefix stripped, and exposed via `Context.getConfig()`, taking precedence over the job-level value of the same key. The configuration shape mirrors Flink's metric-reporter idiom: a list of named instances, plus a `.class` and free-form options under each instance namespace. Selection is purely by classFQN.
**Only one custom metric evaluator per pipeline is supported for now**.Currently, `job.autoscaler.metrics.custom-evaluators` is parsed as a list, but if more than one entry is configured the autoscaler logs a warning and falls back to the first entry, ignoring the rest. Registering multiple implementations via `META-INF/services` is fine as they form a registry that different jobs can select from by classFQN, but a single job cannot chain or compose more than one evaluator. Multi-instance support, including a priority/ordering contract aligned with [FLIP-575](https://cwiki.apache.org/confluence/display/FLINK/FLIP-575%3A+Scaling+Executor+Plugin+SPI+for+Flink+Autoscaler) (`ScalingExecutorPlugin`), will be added as a follow-up.
250
+
{{</hint >}}
251
+
252
+
5.Deploy the evaluator.
253
+
254
+
-**Operator deployment**- create a Dockerfile to build a custom image from the `apache/flink-kubernetes-operator` official image and copy the generated JAR to a custom metric evaluator plugin directory under `/opt/flink/plugins` (the value of the `FLINK_PLUGINS_DIR` environment variable in the flink-kubernetes-operator helm chart).The structure of the custom evaluator directory under `/opt/flink/plugins` is as follows:
255
+
```text
256
+
/opt/flink/plugins
257
+
├── custom-evaluator
258
+
│ ├── custom-evaluator.jar
259
+
└── ...
260
+
```
261
+
262
+
With the custom metric evaluator directory location, the Dockerfile is defined as follows:
263
+
```shell script
264
+
FROM apache/flink-kubernetes-operator
265
+
ENVFLINK_PLUGINS_DIR=/opt/flink/plugins
266
+
ENVCUSTOM_EVALUATOR_DIR=custom-evaluator
267
+
RUN mkdir $FLINK_PLUGINS_DIR/$CUSTOM_EVALUATOR_DIR
Install the flink-kubernetes-operator helm chart with the custom image and verify the `deploy/flink-kubernetes-operator` log has:
272
+
```text
273
+
o.a.f.k.o.a.AutoscalerUtils [INFO ] Discovered custom metric evaluator from plugin directory[/opt/flink/plugins]:org.apache.flink.autoscaler.custom.CustomEvaluator.
274
+
```
275
+
276
+
-**Standalone autoscaler**- simply place the custom metric evaluator JAR on the classpath of the `flink-autoscaler-standalone` process. It will be picked up automatically via Java's `ServiceLoader` and discovery will be logged:
277
+
```text
278
+
o.a.f.a.s.AutoscalerUtils [INFO ] Discovered custom metric evaluator via ServiceLoader: org.apache.flink.autoscaler.custom.CustomEvaluator.
`ScalingMetricsEvaluatorPlugin` is a pluggable component that allows users to provide custom scaling-metric evaluation logic on top of the metrics evaluated internally by the autoscaler. Custom metric evaluators are discovered through the [Plugins](https://nightlies.apache.org/flink/flink-docs-master/docs/deployment/filesystems/plugins) mechanism when running inside the Kubernetes operator, and through the standard Java `ServiceLoader` mechanism when running with `flink-autoscaler-standalone`. In both cases the implementation class must be registered in `META-INF/services`.
192
+
193
+
For each evaluation cycle, the autoscaler invokes the custom metric evaluator selected via the `job.autoscaler.metrics.custom-evaluators` configuration option once per job vertex. The metrics returned by the custom evaluator are merged on top of the internally evaluated metrics, allowing users to override or augment specific `ScalingMetric` values (e.g. `TARGET_DATA_RATE`, `TRUE_PROCESSING_RATE`, `CATCH_UP_DATA_RATE`).
194
+
195
+
All `job.autoscaler.*` keys related to custom metric evaluators also support the legacy `kubernetes.operator.`-prefixed form as a fallback (for example, `kubernetes.operator.job.autoscaler.metrics.custom-evaluators`). The canonical key takes precedence on overlap.
196
+
197
+
The following steps demonstrate how to develop and use a custom metric evaluator.
198
+
199
+
1. Implement the `ScalingMetricsEvaluatorPlugin` interface:
if (target > 0 && context.getTopology().isSource(vertex)) {
224
+
overrides.put(
225
+
ScalingMetric.TARGET_DATA_RATE,
226
+
EvaluatedScalingMetric.avg(target));
227
+
}
228
+
return overrides;
229
+
}
230
+
}
231
+
```
232
+
233
+
The `Context` object exposes an un-modifiable view of the configuration, the metrics history, previously evaluated vertex metrics (evaluation happens topologically), the job topology, backlog status, and max restart time. The configuration is the job configuration with the evaluator-specific options (prefix stripped) merged on top, so an evaluator-specific key overrides the job-level value of the same key.
234
+
235
+
2. Create the service definition file `org.apache.flink.autoscaler.metrics.ScalingMetricsEvaluatorPlugin` in `META-INF/services` with the fully-qualified class name of your implementation:
3. Use the Maven tool to package the project and generate the custom metric evaluator JAR.
241
+
242
+
4. Select the custom metric evaluator via configuration. The evaluator whose implementation class FQN matches the configured `job.autoscaler.metrics.custom-evaluator.<name>.class` value will be invoked, and any other `job.autoscaler.metrics.custom-evaluator.<name>.*` entries are merged on top of the job configuration with the `job.autoscaler.metrics.custom-evaluator.<instance>.` prefix stripped, and exposed via `Context.getConfig()`, taking precedence over the job-level value of the same key. The configuration shape mirrors Flink's metric-reporter idiom: a list of named instances, plus a `.class` and free-form options under each instance namespace. Selection is purely by classFQN.
**Only one custom metric evaluator per pipeline is supported for now**.Currently, `job.autoscaler.metrics.custom-evaluators` is parsed as a list, but if more than one entry is configured the autoscaler logs a warning and falls back to the first entry, ignoring the rest. Registering multiple implementations via `META-INF/services` is fine as they form a registry that different jobs can select from by classFQN, but a single job cannot chain or compose more than one evaluator. Multi-instance support, including a priority/ordering contract aligned with [FLIP-575](https://cwiki.apache.org/confluence/display/FLINK/FLIP-575%3A+Scaling+Executor+Plugin+SPI+for+Flink+Autoscaler) (`ScalingExecutorPlugin`), will be added as a follow-up.
250
+
{{</hint >}}
251
+
252
+
5.Deploy the evaluator.
253
+
254
+
-**Operator deployment**- create a Dockerfile to build a custom image from the `apache/flink-kubernetes-operator` official image and copy the generated JAR to a custom metric evaluator plugin directory under `/opt/flink/plugins` (the value of the `FLINK_PLUGINS_DIR` environment variable in the flink-kubernetes-operator helm chart).The structure of the custom evaluator directory under `/opt/flink/plugins` is as follows:
255
+
```text
256
+
/opt/flink/plugins
257
+
├── custom-evaluator
258
+
│ ├── custom-evaluator.jar
259
+
└── ...
260
+
```
261
+
262
+
With the custom metric evaluator directory location, the Dockerfile is defined as follows:
263
+
```shell script
264
+
FROM apache/flink-kubernetes-operator
265
+
ENVFLINK_PLUGINS_DIR=/opt/flink/plugins
266
+
ENVCUSTOM_EVALUATOR_DIR=custom-evaluator
267
+
RUN mkdir $FLINK_PLUGINS_DIR/$CUSTOM_EVALUATOR_DIR
Install the flink-kubernetes-operator helm chart with the custom image and verify the `deploy/flink-kubernetes-operator` log has:
272
+
```text
273
+
o.a.f.k.o.a.AutoscalerUtils [INFO ] Discovered custom metric evaluator from plugin directory[/opt/flink/plugins]:org.apache.flink.autoscaler.custom.CustomEvaluator.
274
+
```
275
+
276
+
-**Standalone autoscaler**- simply place the custom metric evaluator JAR on the classpath of the `flink-autoscaler-standalone` process. It will be picked up automatically via Java's `ServiceLoader` and discovery will be logged:
277
+
```text
278
+
o.a.f.a.s.AutoscalerUtils [INFO ] Discovered custom metric evaluator via ServiceLoader: org.apache.flink.autoscaler.custom.CustomEvaluator.
Copy file name to clipboardExpand all lines: docs/layouts/shortcodes/generated/auto_scaler_configuration.html
+18Lines changed: 18 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -92,6 +92,24 @@
92
92
<td><p>Enum</p></td>
93
93
<td>Metric aggregator to use for busyTime metrics. This affects how true processing/output rate will be computed. Using max allows us to handle jobs with data skew more robustly, while avg may provide better stability when we know that the load distribution is even.<br/><br/>Possible values:<ul><li>"AVG"</li><li>"MAX"</li><li>"MIN"</li></ul></td>
<td>Free-form, evaluator-specific options for the custom metric evaluator instance <name>. All keys with this prefix are passed to the evaluator at runtime with the 'job.autoscaler.metrics.custom-evaluator.<name>.' prefix stripped.</td>
<td>Fully-qualified class name of the implementation to instantiate for the custom metric evaluator instance <name> declared in 'job.autoscaler.metrics.custom-evaluators'. The class must be discovered via the Plugin / ServiceLoader mechanism and registered under META-INF/services/org.apache.flink.autoscaler.metrics.ScalingMetricsEvaluatorPlugin.</td>
<td>List of named custom metric evaluator instances to register with the autoscaler. For each <name> entry, the implementation class to instantiate must be set via 'job.autoscaler.metrics.custom-evaluator.<name>.class', and additional per-instance options live under 'job.autoscaler.metrics.custom-evaluator.<name>.<option>'. Only a single instance is honored for now: if more than one is configured, the autoscaler logs a warning and uses the first entry, ignoring the rest. Multi-instance support, including a priority/ordering contract, will be added as a follow-up.</td>
Copy file name to clipboardExpand all lines: flink-autoscaler-standalone/src/main/java/org/apache/flink/autoscaler/standalone/StandaloneAutoscalerEntrypoint.java
0 commit comments