From c915ccf77fbbd17d44b130579352121a074f9e09 Mon Sep 17 00:00:00 2001 From: X-czh Date: Sat, 18 Dec 2021 23:56:59 +0800 Subject: [PATCH] [FLINK-25372] Add thread dump feature for jobmanager on Web UI This closes #18148 --- .../src/app/interfaces/job-manager.ts | 8 ++ .../job-manager/job-manager-routing.module.ts | 8 ++ .../job-manager/job-manager.component.ts | 3 +- .../pages/job-manager/job-manager.module.ts | 4 +- .../job-manager-thread-dump.component.html | 30 ++++++++ .../job-manager-thread-dump.component.less | 30 ++++++++ .../job-manager-thread-dump.component.ts | 73 +++++++++++++++++++ .../src/app/services/job-manager.service.ts | 10 ++- 8 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.html create mode 100644 flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.less create mode 100644 flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.ts diff --git a/flink-runtime-web/web-dashboard/src/app/interfaces/job-manager.ts b/flink-runtime-web/web-dashboard/src/app/interfaces/job-manager.ts index 058108e843fbd..e7749fa6da381 100644 --- a/flink-runtime-web/web-dashboard/src/app/interfaces/job-manager.ts +++ b/flink-runtime-web/web-dashboard/src/app/interfaces/job-manager.ts @@ -21,3 +21,11 @@ export interface JobManagerLogItem { size: number; mtime: number; } +export interface JobManagerThreadDump { + threadInfos: JobManagerThreadInfo[]; +} + +interface JobManagerThreadInfo { + threadName: string; + stringifiedThreadInfo: string; +} diff --git a/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager-routing.module.ts b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager-routing.module.ts index 7ffb5fa87bcf2..70db781572365 100644 --- a/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager-routing.module.ts +++ b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager-routing.module.ts @@ -26,6 +26,7 @@ import { JobManagerLogListComponent } from './log-list/job-manager-log-list.comp import { JobManagerLogsComponent } from './logs/job-manager-logs.component'; import { JobManagerMetricsComponent } from './metrics/job-manager-metrics.component'; import { JobManagerStdoutComponent } from './stdout/job-manager-stdout.component'; +import { JobManagerThreadDumpComponent } from './thread-dump/job-manager-thread-dump.component'; const routes: Routes = [ { @@ -74,6 +75,13 @@ const routes: Routes = [ path: 'log' } }, + { + path: 'thread-dump', + component: JobManagerThreadDumpComponent, + data: { + path: 'thread-dump' + } + }, { path: '**', redirectTo: 'metrics', diff --git a/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager.component.ts b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager.component.ts index 9d455b13d150e..d96a0f0c6d655 100644 --- a/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager.component.ts +++ b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager.component.ts @@ -30,6 +30,7 @@ export class JobManagerComponent { { path: 'config', title: 'Configuration' }, { path: 'logs', title: 'Logs' }, { path: 'stdout', title: 'Stdout' }, - { path: 'log', title: 'Log List' } + { path: 'log', title: 'Log List' }, + { path: 'thread-dump', title: 'Thread Dump' } ]; } diff --git a/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager.module.ts b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager.module.ts index 92537b02c3493..62ea6f4af51c5 100644 --- a/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager.module.ts +++ b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/job-manager.module.ts @@ -38,6 +38,7 @@ import { JobManagerLogListComponent } from './log-list/job-manager-log-list.comp import { JobManagerLogsComponent } from './logs/job-manager-logs.component'; import { JobManagerMetricsComponent } from './metrics/job-manager-metrics.component'; import { JobManagerStdoutComponent } from './stdout/job-manager-stdout.component'; +import { JobManagerThreadDumpComponent } from './thread-dump/job-manager-thread-dump.component'; @NgModule({ imports: [ @@ -61,7 +62,8 @@ import { JobManagerStdoutComponent } from './stdout/job-manager-stdout.component JobManagerLogListComponent, JobManagerLogDetailComponent, JobManagerLogsComponent, - JobManagerStdoutComponent + JobManagerStdoutComponent, + JobManagerThreadDumpComponent ] }) export class JobManagerModule {} diff --git a/flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.html b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.html new file mode 100644 index 0000000000000..10713ac143ad5 --- /dev/null +++ b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.html @@ -0,0 +1,30 @@ + + + + diff --git a/flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.less b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.less new file mode 100644 index 0000000000000..fb011b9457dca --- /dev/null +++ b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.less @@ -0,0 +1,30 @@ +/* + * 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. + */ + +:host { + position: relative; + flex: 1; + + nz-code-editor { + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; + } +} diff --git a/flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.ts b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.ts new file mode 100644 index 0000000000000..28088f259187e --- /dev/null +++ b/flink-runtime-web/web-dashboard/src/app/pages/job-manager/thread-dump/job-manager-thread-dump.component.ts @@ -0,0 +1,73 @@ +/* + * 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. + */ + +import { ChangeDetectorRef, Component, OnInit, ChangeDetectionStrategy, OnDestroy } from '@angular/core'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; + +import { EditorOptions } from 'ng-zorro-antd/code-editor/typings'; +import { flinkEditorOptions } from 'share/common/editor/editor-config'; + +import { JobManagerService } from 'services'; + +@Component({ + selector: 'flink-job-manager-thread-dump', + templateUrl: './job-manager-thread-dump.component.html', + styleUrls: ['./job-manager-thread-dump.component.less'], + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class JobManagerThreadDumpComponent implements OnInit, OnDestroy { + public readonly editorOptions: EditorOptions = flinkEditorOptions; + + public dump = ''; + public loading = true; + + private readonly destroy$ = new Subject(); + + constructor(private readonly jobManagerService: JobManagerService, private readonly cdr: ChangeDetectorRef) {} + + public ngOnInit(): void { + this.reload(); + } + + public ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } + + public reload(): void { + this.loading = true; + this.cdr.markForCheck(); + if (this.jobManagerService) { + this.jobManagerService + .loadThreadDump() + .pipe(takeUntil(this.destroy$)) + .subscribe( + data => { + this.loading = false; + this.dump = data; + this.cdr.markForCheck(); + }, + () => { + this.loading = false; + this.cdr.markForCheck(); + } + ); + } + } +} diff --git a/flink-runtime-web/web-dashboard/src/app/services/job-manager.service.ts b/flink-runtime-web/web-dashboard/src/app/services/job-manager.service.ts index 1a3d665e22512..7ee8f2d5fd8da 100644 --- a/flink-runtime-web/web-dashboard/src/app/services/job-manager.service.ts +++ b/flink-runtime-web/web-dashboard/src/app/services/job-manager.service.ts @@ -22,7 +22,7 @@ import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { BASE_URL } from 'config'; -import { JobManagerLogItem } from 'interfaces'; +import { JobManagerLogItem, JobManagerThreadDump } from 'interfaces'; @Injectable({ providedIn: 'root' @@ -68,6 +68,14 @@ export class JobManagerService { ); } + public loadThreadDump(): Observable { + return this.httpClient.get(`${BASE_URL}/jobmanager/thread-dump`).pipe( + map(JobManagerThreadDump => { + return JobManagerThreadDump.threadInfos.map(threadInfo => threadInfo.stringifiedThreadInfo).join(''); + }) + ); + } + public getMetricsName(): Observable { return this.httpClient .get>(`${BASE_URL}/jobmanager/metrics`)