Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).
Motivation
FLIP-274: Introduce metric group for OperatorCoordinator introduced a new metric group for source enumerators to emit metrics. However, there is no way from the Flink REST API to fetch these metrics.
The current metric related REST APIs are the following:
/jobmanager/metrics /taskmanagers/<taskmanagerid>/metrics /jobs/<jobid>/metrics /jobs/<jobid>/vertices/<vertexid>/subtasks/<subtaskindex> Request metrics aggregated across all entities of the respective type: /taskmanagers/metrics /jobs/metrics /jobs/<jobid>/vertices/<vertexid>/subtasks/metrics
These APIs allow external services to fetch, for example, subtask metrics to do analysis. The coordinator metrics are also an essential set of metrics for jobs that expose how a job is behaving. Currently, the main clients of these REST APIs are the Web UI and the Kubernetes Operator.
Public Interfaces
The REST API needs to add an endpoint and adds a new config option, metrics.scope.coordinator.
Proposed Changes
Thus, I propose a new REST API
/jobs/<jobid>/vertices/<vertexid>/coordinator-metrics
with the query parameter get
that accepts comma separated metric names, like the other APIs. This path is based on https://github.com/apache/flink/blob/7bebd2d9fac517c28afc24c0c034d77cfe2b43a6/flink-runtime/src/main/java/org/apache/flink/runtime/metrics/dump/QueryScopeInfo.java#L234.
`coordinator-metrics` makes it obvious that the metrics are from the OperatorCoordinator, not to be confused with something like `operator-metrics` (which operator is it?). This endpoint should also be integrated with the Flink UI.
In addition, I also propose to fix the metric scope [1]:
metrics.scope.operator
- Default: <host>.taskmanager.<tm_id>.<job_name>.<operator_name>.<subtask_index>
- Applied to all metrics that were scoped to an operator.
The default should not contain the subtask index, since the coordinator does not correspond to a subtask index. In addition, this configuration could be renamed to `metrics.scope.coordinator` since `operator` is vague. While we will point to the new config in the docs, backward compatibility will be provided for the old config key.
[1] https://nightlies.apache.org/flink/flink-docs-master/docs/ops/metrics/#system-scope
Compatibility, Deprecation, and Migration Plan
No compatibility concerns as this is introducing a new API without modifying older APIs. The code modifications are otherwise to internal code.
The changes to the QueryScopeInfo is internal and is not expected to be breaking because we don't expose a method to query these metrics yet. There is no backward incompatibility for the metric scope config.
Test Plan
Unit tests.
Rejected Alternatives
1. Exposing the operator id in the API. e.g. /jobs/<jobid>/vertices/<vertexid>/operators/<operatorid>/metrics
.
2 considerations:
1. Integrate Flink UI to show source coordinator metrics
The Flink UI currently doesn't expose per operator metrics, only task metrics. For operator metrics, metric reporters provide that extensibility to expose operator granularity metrics. So, the operator id is unnecessary for this case.
2. Integrate Flink Kubernetes Operator to read autoscaling metrics from source enumerator
The K8s operator currently reads vertex metrics from the Flink Metric REST API to perform autoscaling. In this situation, the operator id is unnecessary as well and in fact, a vertex can only contain 1 source. Therefore, we don't need a parameter for the operator id.