Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-132242 / 24.10.1 / Fix Missing NICs Can Cause Dashboard to Misbehave (by denysbutenko) #11060

Merged
merged 1 commit into from
Nov 18, 2024
Merged
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,10 +16,10 @@ <h3>{{ 'Interface' | translate }}</h3>
</div>
}

<div [class]="['container', size()]">
<div *ixWithLoadingState="interface() as interface" [class]="['container', size()]">
<div class="nic-info">
<div class="info-header">
<h3 *ixWithLoadingState="interface() as interface" class="info-header-title">{{ interface.name }}</h3>
<h3 class="info-header-title">{{ interface.name }}</h3>
</div>
<div class="info-body">
<div class="info-column primary">
Expand Down Expand Up @@ -70,23 +70,23 @@ <h3 *ixWithLoadingState="interface() as interface" class="info-header-title">{{
@if (!isLoading()) {
<div class="info-list-item">
<span>{{ 'Media Type' | translate }}:</span>
<span>{{ interface().value.state.active_media_type }}</span>
<span>{{ interface.state.active_media_type }}</span>
</div>
} @else {
<ngx-skeleton-loader class="skeleton"></ngx-skeleton-loader>
}
@if (!isLoading()) {
<div class="info-list-item">
<span>{{ 'Media Subtype' | translate }}:</span>
<span>{{ interface().value.state.active_media_subtype }}</span>
<span>{{ interface.state.active_media_subtype }}</span>
</div>
} @else {
<ngx-skeleton-loader class="skeleton"></ngx-skeleton-loader>
}
@if (!isLoading()) {
<div class="info-list-item">
<span>{{ 'IP' | translate }}:</span>
<span>{{ getIpAddress(interface().value) }}</span>
<span>{{ getIpAddress(interface) }}</span>
</div>
} @else {
<ngx-skeleton-loader class="skeleton"></ngx-skeleton-loader>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
@import 'scss-imports/variables';

:host ::ng-deep ix-with-loading-state-error {
align-items: center;
box-sizing: border-box;
display: flex;
flex: 1;
font-size: 20px;
height: 100%;
padding: 16px;
place-content: center center;
text-align: center;
width: 100%;
}

.card {
box-sizing: border-box;
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { of } from 'rxjs';
import { oneHourMillis, oneMinuteMillis } from 'app/constants/time.constant';
import { NetworkInterfaceType, NetworkInterfaceAliasType, LinkState } from 'app/enums/network-interface.enum';
import { InterfaceStatusIconComponent } from 'app/modules/interface-status-icon/interface-status-icon.component';
import { WithLoadingStateDirective } from 'app/modules/loader/directives/with-loading-state/with-loading-state.directive';
import { NetworkSpeedPipe } from 'app/modules/pipes/network-speed/network-speed.pipe';
import { WidgetResourcesService } from 'app/pages/dashboard/services/widget-resources.service';
import { SlotSize } from 'app/pages/dashboard/types/widget.interface';
Expand All @@ -22,6 +23,7 @@ describe('WidgetInterfaceComponent', () => {
imports: [
NgxSkeletonLoaderModule,
NetworkSpeedPipe,
WithLoadingStateDirective,
],
declarations: [
MockComponent(NetworkChartComponent),
Expand Down Expand Up @@ -100,13 +102,15 @@ describe('WidgetInterfaceComponent', () => {
});
});

it('shows widget header', () => {
it('shows widget header', fakeAsync(() => {
spectator.tick(1);
expect(spectator.query('.header')).toHaveText('Interface');
});
}));

it('shows interface name', () => {
it('shows interface name', fakeAsync(() => {
spectator.tick(1);
expect(spectator.query('.info-header-title')).toHaveText('ens1');
});
}));

it('shows interface state', fakeAsync(() => {
spectator.tick(1);
Expand Down Expand Up @@ -162,6 +166,7 @@ describe('WidgetInterfaceComponent', () => {

it('checks first entry selection when settings are null', () => {
spectator.setInput('settings', null);
spectator.detectChanges();

expect(spectator.query('.info-header-title')).toHaveText('ens1');
expect(spectator.query('.info-list-item.state')).toHaveText('LINK STATE UP');
Expand All @@ -186,9 +191,10 @@ describe('WidgetInterfaceComponent', () => {
expect(spectator.query('.header')).toBeNull();
});

it('shows interface name', () => {
it('shows interface name', fakeAsync(() => {
spectator.tick(1);
expect(spectator.query('.info-header-title')).toHaveText('ens1');
});
}));

it('shows interface state', fakeAsync(() => {
spectator.tick(1);
Expand Down Expand Up @@ -259,9 +265,10 @@ describe('WidgetInterfaceComponent', () => {
expect(spectator.query('.header')).toBeNull();
});

it('shows interface name', () => {
it('shows interface name', fakeAsync(() => {
spectator.tick(1);
expect(spectator.query('.info-header-title')).toHaveText('ens1');
});
}));

it('shows interface state', fakeAsync(() => {
spectator.tick(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import {
filter, switchMap, map,
tap,
throttleTime,
catchError, of,
} from 'rxjs';
import { kb } from 'app/constants/bits.constant';
import { oneHourMillis, oneMinuteMillis } from 'app/constants/time.constant';
import { LinkState, NetworkInterfaceAliasType, linkStateLabelMap } from 'app/enums/network-interface.enum';
import { LoadingState } from 'app/helpers/operators/to-loading-state.helper';
import { BaseNetworkInterface, NetworkInterfaceAlias } from 'app/interfaces/network-interface.interface';
import { mapLoadedValue } from 'app/modules/loader/directives/with-loading-state/map-loaded-value.utils';
import { WidgetResourcesService } from 'app/pages/dashboard/services/widget-resources.service';
import { WidgetComponent } from 'app/pages/dashboard/types/widget-component.interface';
import { SlotSize } from 'app/pages/dashboard/types/widget.interface';
import { fullSizeNetworkWidgetAspectRatio, halfSizeNetworkWidgetAspectRatio } from 'app/pages/dashboard/widgets/network/widget-interface/widget-interface.const';
import { getNetworkInterface } from 'app/pages/dashboard/widgets/network/widget-interface/widget-interface.utils';
import { DashboardNetworkInterface, getNetworkInterface } from 'app/pages/dashboard/widgets/network/widget-interface/widget-interface.utils';
import { WidgetInterfaceIpSettings } from 'app/pages/dashboard/widgets/network/widget-interface-ip/widget-interface-ip.definition';
import { ThemeService } from 'app/services/theme/theme.service';

Expand All @@ -35,13 +37,22 @@ import { ThemeService } from 'app/services/theme/theme.service';
export class WidgetInterfaceComponent implements WidgetComponent<WidgetInterfaceIpSettings> {
size = input.required<SlotSize>();
settings = input.required<WidgetInterfaceIpSettings>();
private interfaces = toSignal(this.resources.networkInterfaces$, { initialValue: { isLoading: true } });

protected interfaceId = computed(() => this.settings()?.interface || '');
protected interface = computed(() => mapLoadedValue(
this.interfaces(),
(interfaces) => getNetworkInterface(interfaces, this.interfaceId()),
));
protected interfaceUsage = toSignal(toObservable(this.interface).pipe(
private interface$ = toObservable(this.interfaceId).pipe(
switchMap((interfaceId) => this.resources.networkInterfaces$.pipe(
map((interfaces) => mapLoadedValue(interfaces, (nics) => getNetworkInterface(nics, interfaceId))),
catchError((error: Error) => {
return of({ isLoading: false, error } as LoadingState<DashboardNetworkInterface>);
}),
)),
);

protected interface = toSignal(this.interface$, {
initialValue: { isLoading: true, value: null } as LoadingState<DashboardNetworkInterface>,
});

protected interfaceUsage = toSignal(this.interface$.pipe(
filter((state) => Boolean(!state.isLoading && state.value)),
map((state) => state.value.name),
switchMap((interfaceId) => this.resources.realtimeUpdates$.pipe(
Expand Down Expand Up @@ -79,7 +90,7 @@ export class WidgetInterfaceComponent implements WidgetComponent<WidgetInterface
return this.interface().isLoading || !this.initialNetworkStats() || !this.interfaceUsage() || !this.networkStats();
});

protected initialNetworkStats = toSignal(toObservable(this.interface).pipe(
protected initialNetworkStats = toSignal(this.interface$.pipe(
filter((state) => Boolean(!state.isLoading && state.value)),
map((state) => state.value.name),
switchMap((interfaceId) => this.resources.networkInterfaceLastHourStats(interfaceId)),
Expand Down
Loading