1fanwang opened a new pull request, #29933:
URL: https://github.com/apache/flink/pull/29933
<!--
*Thank you very much for contributing to Apache Flink - we are happy that
you want to help us improve Flink. 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.*
-->
<!--
*Please understand that we do not do this to make contributions to Flink a
hassle. In order to uphold a high standard of quality for code contributions,
while at the same time managing a large number of contributions, we need
contributors to prepare the contributions well, and give reviewers enough
contextual information for the review. Please also understand that
contributions that do not follow this guide will take longer to review and thus
typically be picked up with lower priority by the community.*
-->
<!--
## 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 set up Azure Pipelines CI to do that following [this
guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
-->
<!--
- 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
After opening a TaskManager that is no longer registered, navigating to
another TaskManager keeps showing "TaskManager not available" instead of
loading the selected manager. Its metrics tab also retains the old ID.
[FLINK-41418](https://issues.apache.org/jira/browse/FLINK-41418) tracks this
route-reuse bug.
Both views now load the selected TaskManager without a page reload. A 404
still stops polling for the missing TaskManager, as intended by
https://github.com/apache/flink/pull/28735.
## Brief change log
Scope polling to the route ID and clear the previous view state when it
changes. Keep metrics requests inside that subscription so navigation cancels
them too.
## Verifying this change
Please make sure both new and modified tests in this PR follow [the
conventions for tests defined in our code quality
guide](https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing).
This change added tests and can be verified as follows:
### Testing Done
I ran the production-built dashboard in a browser against the local HTTP
fixture below, not a running Flink cluster. The fixture returns 404 for tm-gone
and 200 for tm-live. Both production builds passed; I did not run the full
Maven reactor.
Set REPRO_DIR to the directory containing the fixture. From the PR checkout,
extract and build the [upstream
baseline](https://github.com/apache/flink/commit/a45f19878587e24941b4fd63f54c4ef8a8d16d97):
```sh
PR_CHECKOUT=$(git rev-parse --show-toplevel)
mkdir -p "$REPRO_DIR/baseline"
git archive a45f19878587e24941b4fd63f54c4ef8a8d16d97
flink-runtime-web/web-dashboard | tar -x -C "$REPRO_DIR/baseline"
cd "$REPRO_DIR/baseline/flink-runtime-web/web-dashboard"
npm ci --no-audit --no-fund
npm run build -- --output-path="$REPRO_DIR/dashboard-before"
```
Build the changed dashboard from the PR checkout:
```sh
cd "$PR_CHECKOUT/flink-runtime-web/web-dashboard"
npm ci --no-audit --no-fund
npm run build -- --output-path="$REPRO_DIR/dashboard-after"
```
Serve one build at a time:
```sh
python3 "$REPRO_DIR/taskmanager_fixture.py"
"$REPRO_DIR/dashboard-before/browser" --port 41418
python3 "$REPRO_DIR/taskmanager_fixture.py"
"$REPRO_DIR/dashboard-after/browser" --port 41418
```
Open http://127.0.0.1:41418/#/task-manager/tm-gone/metrics and wait for
"TaskManager not available". Paste the browser probe function below into the
console, then invoke it without reloading the page:
```js
await probeTaskManagerNavigation();
```
Before:
```json
{
"route": "#/task-manager/tm-live/metrics",
"beforeNotice": true,
"reusedStatusComponent": true,
"reusedMetricsComponent": true,
"notFoundNotice": true,
"liveIdVisible": false,
"metricsVisible": false,
"goneRequests": 1,
"liveDetailRequests": 0,
"liveMetricsRequests": 0
}
```
After:
```json
{
"route": "#/task-manager/tm-live/metrics",
"beforeNotice": true,
"reusedStatusComponent": true,
"reusedMetricsComponent": true,
"notFoundNotice": false,
"liveIdVisible": true,
"metricsVisible": true,
"goneRequests": 1,
"liveDetailRequests": 3,
"liveMetricsRequests": 3
}
```
<details>
<summary>Reproducer source: browser_probe.js</summary>
```js
async function probeTaskManagerNavigation() {
const status = document.querySelector('flink-task-manager-status');
const metrics = document.querySelector('flink-task-manager-metrics');
const beforeNotice = document.body.textContent.includes('TaskManager not
available');
window.location.hash = '/task-manager/tm-live/metrics';
await new Promise(resolve => setTimeout(resolve, 2000));
const requests = await (await fetch('/_requests')).json();
return {
route: window.location.hash,
beforeNotice,
reusedStatusComponent: status ===
document.querySelector('flink-task-manager-status'),
reusedMetricsComponent: metrics ===
document.querySelector('flink-task-manager-metrics'),
notFoundNotice: document.body.textContent.includes('TaskManager not
available'),
liveIdVisible:
document.querySelector('flink-task-manager-status').textContent.includes('tm-live'),
metricsVisible:
document.querySelector('flink-task-manager-metrics').textContent.includes('Flink
Memory Model'),
goneRequests: requests.filter(request => request.path ===
'/taskmanagers/tm-gone').length,
liveDetailRequests: requests.filter(request => request.path ===
'/taskmanagers/tm-live/metrics').length,
liveMetricsRequests: requests.filter(request => request.path ===
'/taskmanagers/tm-live/metrics').length
};
}
```
</details>
<details>
<summary>Reproducer source: taskmanager_fixture.py</summary>
```python
#!/usr/bin/env python3
import argparse
import json
from functools import partial
from http import HTTPStatus
from http.server import HTTPServer, SimpleHTTPRequestHandler
from pathlib import Path
from urllib.parse import parse_qs, urlparse
REQUESTS: list[dict[str, object]] = []
METRICS: dict[str, int] = {
"Status.JVM.Memory.Heap.Used": 100,
"Status.JVM.Memory.Heap.Max": 400,
"Status.Shuffle.Netty.UsedMemory": 10,
"Status.Shuffle.Netty.TotalMemory": 100,
"Status.Flink.Memory.Managed.Used": 200,
"Status.Flink.Memory.Managed.Total": 500,
"Status.JVM.Memory.Metaspace.Used": 50,
"Status.JVM.Memory.Metaspace.Max": 250,
}
DETAIL: dict[str, object] = {
"path": "pekko.tcp://flink@localhost:6122/user/rpc/taskmanager_0",
"dataPort": 6121,
"timeSinceLastHeartbeat": 1_700_000_000_000,
"slotsNumber": 4,
"freeSlots": 4,
"assignedTasks": 0,
"hardware": {
"cpuCores": 8,
"physicalMemory": 17_179_869_184,
"freeMemory": 536_870_912,
"managedMemory": 536_870_912,
},
"memoryConfiguration": {
"frameworkHeap": 134_217_728,
"frameworkOffHeap": 134_217_728,
"jvmMetaspace": 268_435_456,
"jvmOverhead": 201_326_592,
"managedMemory": 536_870_912,
"networkMemory": 134_217_728,
"taskHeap": 402_653_184,
"taskOffHeap": 0,
"totalFlinkMemory": 1_476_395_008,
"totalProcessMemory": 1_728_053_248,
},
"metrics": {
"heapUsed": 100,
"heapCommitted": 200,
"heapMax": 400,
"nonHeapUsed": 40,
"nonHeapCommitted": 60,
"nonHeapMax": 300,
"directCount": 5,
"directUsed": 10,
"directMax": 10,
"mappedCount": 0,
"mappedUsed": 0,
"mappedMax": 0,
"nettyShuffleMemorySegmentsAvailable": 1234,
"nettyShuffleMemorySegmentsTotal": 5678,
"garbageCollectors": [],
},
"freeResource": {
"cpuCores": 4,
"taskHeapMemory": 100,
"taskOffHeapMemory": 0,
"managedMemory": 200,
"networkMemory": 50,
},
"totalResource": {
"cpuCores": 8,
"taskHeapMemory": 400,
"taskOffHeapMemory": 0,
"managedMemory": 500,
"networkMemory": 100,
},
"allocatedSlots": [],
}
class FixtureHandler(SimpleHTTPRequestHandler):
def reply(self, *, status: HTTPStatus, body: object) -> None:
payload: bytes = json.dumps(body).encode("utf-8")
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(payload)))
self.send_header("Cache-Control", "no-store")
self.end_headers()
self.wfile.write(payload)
def do_GET(self) -> None:
path: str = urlparse(self.path).path
if path == "/_requests":
self.reply(status=HTTPStatus.OK, body=REQUESTS)
elif path == "/config":
self.reply(
status=HTTPStatus.OK,
body={
"refresh-interval": 500,
"timezone-name": "UTC",
"timezone-offset": 0,
"flink-version": "2.5-SNAPSHOT",
"flink-revision": "local fixture",
"features": {
"web-history": False,
"web-submit": False,
"web-cancel": True,
"web-rescale": False,
},
},
)
elif path.startswith("/taskmanagers/"):
task_manager_id: str = path.split("/")[2]
status: HTTPStatus = (
HTTPStatus.OK
if task_manager_id in ("tm-live", "tm-next")
else HTTPStatus.NOT_FOUND
)
REQUESTS.append({"path": path, "status": status.value})
if status == HTTPStatus.NOT_FOUND:
self.reply(status=status, body={"errors": ["Unknown
TaskManager"]})
elif path.endswith("/metrics"):
query: dict[str, list[str]] =
parse_qs(urlparse(self.path).query)
self.reply(
status=status,
body=[
{"id": name, "value": str(METRICS[name])}
for name in query["get"][0].split(",")
],
)
else:
self.reply(status=status, body={**DETAIL, "id":
task_manager_id})
else:
super().do_GET()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("directory", type=Path)
parser.add_argument("--port", type=int, default=41418)
args = parser.parse_args()
with HTTPServer(
server_address=("127.0.0.1", args.port),
RequestHandlerClass=partial(FixtureHandler,
directory=str(args.directory)),
) as server:
print(f"Dashboard fixture: http://127.0.0.1:{args.port}", flush=True)
server.serve_forever()
```
</details>
## 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 changed class annotated with
@Public(Evolving): no
- The serializers: no
- The runtime per-record code paths (performance sensitive): no
- Anything that affects deployment or recovery: JobManager (and its
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented? not applicable
---
##### Was generative AI tooling used to co-author this PR?
<!--
If AI tooling has been used in the process of authoring this PR, please
change the checkbox below to `[X]` and replace the placeholder in the
"Generated-by"
line with the tool name and version. Otherwise remove the "Generated-by"
line.
See the ASF Generative Tooling Guidance for details:
https://www.apache.org/legal/generative-tooling.html
You are responsible for the quality and correctness of every change in this
PR
regardless of the tooling used. Low-effort AI-generated PRs will be closed.
See
AGENTS.md for the full guidance.
-->
- [X] Yes (please specify the tool below)
Generated-by: GitHub Copilot CLI 1.0.102-0.unstable.r40949665530.gab1eef5
(Auto)
--
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]