Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
~ limitations under the License.
-->

<nz-card nzTitle="Memory" nzSize="small" class="flink-memory-model">
<nz-card *ngIf="taskManagerDetail" nzTitle="Memory" nzSize="small" class="flink-memory-model">
<nz-table
nzBordered
*ngIf="metrics"
Expand Down Expand Up @@ -164,7 +164,7 @@
</tbody>
</nz-table>
</nz-card>
<nz-card nzTitle="Advanced" nzSize="small" class="flink-memory-model">
<nz-card *ngIf="taskManagerDetail" nzTitle="Advanced" nzSize="small" class="flink-memory-model">
<div nz-row [nzGutter]="16">
<div nz-col [nzSpan]="12">
<nz-table
Expand Down Expand Up @@ -318,7 +318,7 @@
</tr>
</ng-template>

<nz-card nzTitle="Resources" nzSize="small" class="flink-memory-model">
<nz-card *ngIf="taskManagerDetail" nzTitle="Resources" nzSize="small" class="flink-memory-model">
<nz-table
nzBordered
nzTitle="Unassigned resources"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 { HttpErrorResponse } from '@angular/common/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { of, throwError } from 'rxjs';

import { TaskManagerDetail } from '@flink-runtime-web/interfaces';
import { StatusService, TaskManagerService } from '@flink-runtime-web/services';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { TaskManagerMetricsComponent } from './task-manager-metrics.component';

const mockDetail = { id: 'tm-container-7' } as unknown as TaskManagerDetail;

describe('TaskManagerMetricsComponent', () => {
let fixture: ComponentFixture<TaskManagerMetricsComponent>;
let element: HTMLElement;
const loadManager = vi.fn();
const loadMetrics = vi.fn();

beforeEach(async () => {
loadManager.mockReset().mockReturnValue(of(mockDetail));
loadMetrics.mockReset().mockReturnValue(of({ 'Status.JVM.Memory.Heap.Used': 1, 'Status.JVM.Memory.Heap.Max': 2 }));
await TestBed.configureTestingModule({
imports: [TaskManagerMetricsComponent],
providers: [
{ provide: StatusService, useValue: { refresh$: of(true) } },
{ provide: TaskManagerService, useValue: { loadManager, loadMetrics } },
{ provide: ActivatedRoute, useValue: { parent: { snapshot: { params: { taskManagerId: 'tm-container-7' } } } } }
]
}).compileComponents();
fixture = TestBed.createComponent(TaskManagerMetricsComponent);
element = fixture.nativeElement as HTMLElement;
});

it('loads the metrics when the TaskManager is available', () => {
// Drive the load path without a full DOM render: the metric cards bind
// taskManagerDetail.metrics.*, so rendering needs a complete metrics fixture
// (the production build covers that). Here we assert the wiring.
fixture.componentInstance.ngOnInit();

expect(fixture.componentInstance.taskManagerDetail).toBe(mockDetail);
expect(loadMetrics).toHaveBeenCalled();
});

it('hides the metric cards (no NaN) when the TaskManager is gone (404)', () => {
loadManager.mockReturnValue(throwError(() => new HttpErrorResponse({ status: 404 })));

fixture.detectChanges();

expect(fixture.componentInstance.taskManagerDetail).toBeUndefined();
expect(element.textContent).not.toContain('Flink Memory Model');
expect(element.textContent).not.toContain('Advanced');
expect(element.textContent).not.toContain('NaN');
expect(loadMetrics).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { DecimalPipe, NgForOf, NgIf, NgTemplateOutlet } from '@angular/common';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { of, Subject } from 'rxjs';
import { catchError, mergeMap, startWith, takeUntil } from 'rxjs/operators';
import { catchError, takeUntil } from 'rxjs/operators';

import { HumanizeBytesPipe } from '@flink-runtime-web/components/humanize-bytes.pipe';
import { MetricMap, TaskManagerDetail } from '@flink-runtime-web/interfaces';
Expand All @@ -32,6 +32,8 @@ import { NzProgressModule } from 'ng-zorro-antd/progress';
import { NzTableModule } from 'ng-zorro-antd/table';
import { NzTooltipModule } from 'ng-zorro-antd/tooltip';

import { pollTaskManagerDetail } from '../task-manager-detail-poll';

@Component({
selector: 'flink-task-manager-metrics',
templateUrl: './task-manager-metrics.component.html',
Expand Down Expand Up @@ -66,17 +68,13 @@ export class TaskManagerMetricsComponent implements OnInit, OnDestroy {

public ngOnInit(): void {
const taskManagerId = this.activatedRoute.parent!.snapshot.params.taskManagerId;
this.statusService.refresh$
.pipe(
startWith(true),
mergeMap(() => this.taskManagerService.loadManager(taskManagerId).pipe(catchError(() => of(undefined)))),
takeUntil(this.destroy$)
)
.subscribe(data => {
if (data) {
this.reload(data.id);
pollTaskManagerDetail(this.statusService.refresh$, () => this.taskManagerService.loadManager(taskManagerId))
.pipe(takeUntil(this.destroy$))
.subscribe(({ detail }) => {
if (detail) {
this.reload(detail.id);
}
this.taskManagerDetail = data;
this.taskManagerDetail = detail;
this.cdr.markForCheck();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,49 @@
-->

<ng-container *ngIf="!loading; else loadingContent">
<div class="title-wrapper" [attr.title]="taskManagerDetail?.id">
<span class="title">{{ taskManagerDetail?.id }}</span>
<flink-blocked-badge *ngIf="taskManagerDetail?.blocked"></flink-blocked-badge>
</div>
<nz-descriptions *ngIf="taskManagerDetail" nzBordered nzSize="small">
<nz-descriptions-item [nzSpan]="1" nzTitle="Path">
{{ taskManagerDetail.path }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Free/All Slots">
{{ taskManagerDetail.freeSlots }} / {{ taskManagerDetail.slotsNumber }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Assigned Tasks">
{{ taskManagerDetail.assignedTasks }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Last Heartbeat">
{{ taskManagerDetail.timeSinceLastHeartbeat | date: 'yyyy-MM-dd HH:mm:ss' }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Data Port">
{{ taskManagerDetail.dataPort }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="CPU Cores">
{{ taskManagerDetail.hardware.cpuCores }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Physical Memory">
{{ taskManagerDetail.hardware.physicalMemory | humanizeBytes }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="JVM Heap Size">
{{ taskManagerDetail.hardware.freeMemory | humanizeBytes }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Flink Managed Memory">
{{ taskManagerDetail.hardware.managedMemory | humanizeBytes }}
</nz-descriptions-item>
</nz-descriptions>
<flink-navigation [listOfNavigation]="listOfNavigation"></flink-navigation>
<nz-alert
*ngIf="notFound; else detailContent"
nzType="warning"
nzShowIcon
nzMessage="TaskManager not available"
nzDescription="This TaskManager is no longer registered. It may have been shut down or lost."
></nz-alert>
<ng-template #detailContent>
<div class="title-wrapper" [attr.title]="taskManagerDetail?.id">
<span class="title">{{ taskManagerDetail?.id }}</span>
<flink-blocked-badge *ngIf="taskManagerDetail?.blocked"></flink-blocked-badge>
</div>
<nz-descriptions *ngIf="taskManagerDetail" nzBordered nzSize="small">
<nz-descriptions-item [nzSpan]="1" nzTitle="Path">
{{ taskManagerDetail.path }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Free/All Slots">
{{ taskManagerDetail.freeSlots }} / {{ taskManagerDetail.slotsNumber }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Assigned Tasks">
{{ taskManagerDetail.assignedTasks }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Last Heartbeat">
{{ taskManagerDetail.timeSinceLastHeartbeat | date: 'yyyy-MM-dd HH:mm:ss' }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Data Port">
{{ taskManagerDetail.dataPort }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="CPU Cores">
{{ taskManagerDetail.hardware.cpuCores }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Physical Memory">
{{ taskManagerDetail.hardware.physicalMemory | humanizeBytes }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="JVM Heap Size">
{{ taskManagerDetail.hardware.freeMemory | humanizeBytes }}
</nz-descriptions-item>
<nz-descriptions-item [nzSpan]="1" nzTitle="Flink Managed Memory">
{{ taskManagerDetail.hardware.managedMemory | humanizeBytes }}
</nz-descriptions-item>
</nz-descriptions>
<flink-navigation [listOfNavigation]="listOfNavigation"></flink-navigation>
</ng-template>
</ng-container>

<ng-template #loadingContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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 { HttpErrorResponse } from '@angular/common/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { of, throwError } from 'rxjs';

import { TaskManagerDetail } from '@flink-runtime-web/interfaces';
import { StatusService, TaskManagerService } from '@flink-runtime-web/services';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { TaskManagerStatusComponent } from './task-manager-status.component';

const mockDetail = {
id: 'tm-container-7',
path: 'pekko.tcp://flink@10.0.0.7:6122/user/rpc/taskmanager',
dataPort: 43210,
timeSinceLastHeartbeat: 1_781_000_000_000,
slotsNumber: 4,
freeSlots: 2,
assignedTasks: 2,
hardware: { cpuCores: 8, physicalMemory: 16_000_000_000, freeMemory: 8_000_000_000, managedMemory: 4_000_000_000 },
blocked: false
} as unknown as TaskManagerDetail;

describe('TaskManagerStatusComponent', () => {
let fixture: ComponentFixture<TaskManagerStatusComponent>;
let element: HTMLElement;
const loadManager = vi.fn();

beforeEach(async () => {
loadManager.mockReset().mockReturnValue(of(mockDetail));
await TestBed.configureTestingModule({
imports: [TaskManagerStatusComponent],
providers: [
{ provide: StatusService, useValue: { refresh$: of(true) } },
{ provide: TaskManagerService, useValue: { loadManager } },
{ provide: ActivatedRoute, useValue: { snapshot: { params: { taskManagerId: 'tm-container-7' } } } }
]
}).compileComponents();
fixture = TestBed.createComponent(TaskManagerStatusComponent);
element = fixture.nativeElement as HTMLElement;
});

it('renders the TaskManager detail when it is available', () => {
fixture.detectChanges();

expect(fixture.componentInstance.notFound).toBe(false);
expect(element.textContent).toContain('tm-container-7');
expect(element.textContent).toContain('43210');
expect(element.textContent).not.toContain('no longer registered');
});

it('shows a not-available notice when the TaskManager is gone (404)', () => {
loadManager.mockReturnValue(throwError(() => new HttpErrorResponse({ status: 404 })));

fixture.detectChanges();

expect(fixture.componentInstance.notFound).toBe(true);
expect(fixture.componentInstance.taskManagerDetail).toBeUndefined();
expect(element.textContent).toContain('TaskManager not available');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@
import { DatePipe, NgIf } from '@angular/common';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { of, Subject } from 'rxjs';
import { catchError, mergeMap, takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

import { BlockedBadgeComponent } from '@flink-runtime-web/components/blocked-badge/blocked-badge.component';
import { HumanizeBytesPipe } from '@flink-runtime-web/components/humanize-bytes.pipe';
import { NavigationComponent } from '@flink-runtime-web/components/navigation/navigation.component';
import { TaskManagerDetail } from '@flink-runtime-web/interfaces';
import { StatusService, TaskManagerService } from '@flink-runtime-web/services';
import { NzAlertModule } from 'ng-zorro-antd/alert';
import { NzDescriptionsModule } from 'ng-zorro-antd/descriptions';
import { NzSkeletonModule } from 'ng-zorro-antd/skeleton';

import { pollTaskManagerDetail } from '../task-manager-detail-poll';

@Component({
selector: 'flink-task-manager-status',
templateUrl: './task-manager-status.component.html',
Expand All @@ -38,6 +41,7 @@ import { NzSkeletonModule } from 'ng-zorro-antd/skeleton';
imports: [
NgIf,
BlockedBadgeComponent,
NzAlertModule,
NzDescriptionsModule,
DatePipe,
HumanizeBytesPipe,
Expand All @@ -56,6 +60,7 @@ export class TaskManagerStatusComponent implements OnInit, OnDestroy {
];
public taskManagerDetail?: TaskManagerDetail;
public loading = true;
public notFound = false;

private readonly destroy$ = new Subject<void>();

Expand All @@ -67,17 +72,13 @@ export class TaskManagerStatusComponent implements OnInit, OnDestroy {
) {}

public ngOnInit(): void {
this.statusService.refresh$
.pipe(
mergeMap(() =>
this.taskManagerService
.loadManager(this.activatedRoute.snapshot.params.taskManagerId)
.pipe(catchError(() => of(undefined)))
),
takeUntil(this.destroy$)
)
.subscribe(data => {
this.taskManagerDetail = data;
pollTaskManagerDetail(this.statusService.refresh$, () =>
this.taskManagerService.loadManager(this.activatedRoute.snapshot.params.taskManagerId)
)
.pipe(takeUntil(this.destroy$))
.subscribe(({ detail, notFound }) => {
this.taskManagerDetail = detail;
this.notFound = notFound;
this.loading = false;
this.cdr.markForCheck();
});
Expand Down
Loading