Skip to content

Commit 6d2f450

Browse files
authored
fix(healthcheck): all fields may be undefined (#2410)
1 parent 7876ecb commit 6d2f450

File tree

7 files changed

+85
-81
lines changed

7 files changed

+85
-81
lines changed

src/containers/Tenant/Healthcheck/components/HealthcheckIssueDetails/HealthcheckIssueDetails.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ interface HealthcheckIssueDetailsProps {
2323

2424
export function IssueDetails({issue}: HealthcheckIssueDetailsProps) {
2525
const {database} = useTenantQueryParams();
26-
const {location} = issue;
2726

2827
const {detailsFields, hiddenStorageFields, hiddenComputeFields} = React.useMemo(() => {
2928
const hiddenStorageFields: LocationFieldStorage[] = [];
@@ -75,17 +74,19 @@ export function IssueDetails({issue}: HealthcheckIssueDetailsProps) {
7574
return {detailsFields: fields, hiddenComputeFields, hiddenStorageFields};
7675
}, [issue, database]);
7776

77+
const {location} = issue;
78+
7879
return (
7980
<Flex direction="column" gap={4}>
8081
<LocationDetails
8182
title={i18n('label_details')}
8283
fields={detailsFields}
8384
titleVariant="subheader-2"
8485
/>
85-
<StorageLocation location={location.storage} hiddenFields={hiddenStorageFields} />
86-
<ComputeLocation location={location.compute} hiddenFields={hiddenComputeFields} />
87-
<NodeLocation location={location.node} />
88-
<PeerLocation location={location.peer} />
86+
<StorageLocation location={location?.storage} hiddenFields={hiddenStorageFields} />
87+
<ComputeLocation location={location?.compute} hiddenFields={hiddenComputeFields} />
88+
<NodeLocation location={location?.node} />
89+
<PeerLocation location={location?.peer} />
8990
</Flex>
9091
);
9192
}

src/containers/Tenant/Healthcheck/components/HealthcheckIssueDetails/StorageLocation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ function PDiskInfo({location}: StorageSectionProps) {
143143
return null;
144144
}
145145

146-
return pdisk.map((disk: {id: string; path: string}) => (
146+
return pdisk.map((disk) => (
147147
<LocationDetails
148-
key={disk.id}
148+
key={disk.id || disk.path}
149149
fields={[
150150
{
151151
value:

src/containers/Tenant/Healthcheck/components/HealthcheckIssueTabs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export function HealthcheckIssueTabs({
3838
onClick={() => setSelectedTab(parent.id)}
3939
>
4040
<Flex gap={2} wrap="nowrap" alignItems="center">
41-
<TabStatus status={parent.status} />
42-
{getTypeText(parent.type)}
41+
{parent.status && <TabStatus status={parent.status} />}
42+
{parent.type && getTypeText(parent.type)}
4343
</Flex>
4444
</HealthcjeckIssueTab>
4545
{index !== parents.length - 1 && <Text color="secondary">/</Text>}

src/containers/Tenant/Healthcheck/components/HealthcheckIssues.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function Issues({issues}: IssuesProps) {
4141
view
4242
? filteredIssues.filter((issue) => {
4343
const type = issue.firstParentType || issue.type;
44-
return type.toLowerCase().startsWith(view);
44+
return type?.toLowerCase().startsWith(view);
4545
})
4646
: [],
4747
[filteredIssues, view],

src/containers/Tenant/Healthcheck/shared.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export function countHealthcheckIssuesByType(
3636

3737
for (const issue of issueTrees) {
3838
const type = issue.firstParentType ?? issue.type;
39+
if (!type) {
40+
continue;
41+
}
3942
if (type.startsWith('STORAGE')) {
4043
result.storage++;
4144
} else if (type.startsWith('COMPUTE')) {

src/store/reducers/healthcheckInfo/healthcheckInfo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const mapStatusToPriority: Partial<Record<StatusFlag, number>> = {
4141

4242
const sortIssues = (data: IssueLog[]): IssueLog[] => {
4343
return data.sort((a, b) => {
44-
const aPriority = mapStatusToPriority[a.status] || 0;
45-
const bPriority = mapStatusToPriority[b.status] || 0;
44+
const aPriority = a.status ? mapStatusToPriority[a.status] || 0 : 0;
45+
const bPriority = b.status ? mapStatusToPriority[b.status] || 0 : 0;
4646

4747
return aPriority - bPriority;
4848
});

src/types/api/healthcheck.ts

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -18,60 +18,60 @@ export enum StatusFlag {
1818
}
1919

2020
interface LocationNode {
21-
id: number;
22-
host: string;
23-
port: number;
21+
id?: number;
22+
host?: string;
23+
port?: number;
2424
}
2525

2626
interface LocationStoragePDisk {
27-
id: string;
28-
path: string;
27+
id?: string;
28+
path?: string;
2929
}
3030

3131
interface LocationStorageVDisk {
32-
id: string[];
33-
pdisk: LocationStoragePDisk[];
32+
id?: string[];
33+
pdisk?: LocationStoragePDisk[];
3434
}
3535

3636
interface LocationStorageGroup {
37-
id: string[];
38-
vdisk: LocationStorageVDisk;
37+
id?: string[];
38+
vdisk?: LocationStorageVDisk;
3939
}
4040

4141
interface LocationStoragePool {
42-
name: string;
43-
group: LocationStorageGroup;
42+
name?: string;
43+
group?: LocationStorageGroup;
4444
}
4545

4646
interface LocationStorage {
47-
node: LocationNode;
48-
pool: LocationStoragePool;
47+
node?: LocationNode;
48+
pool?: LocationStoragePool;
4949
}
5050

5151
interface LocationComputePool {
52-
name: string;
52+
name?: string;
5353
}
5454

5555
interface LocationComputeTablet {
56-
type: string;
57-
id: string[];
58-
count: number;
56+
type?: string;
57+
id?: string[];
58+
count?: number;
5959
}
6060

6161
interface LocationComputeSchema {
62-
type: string;
63-
path: string;
62+
type?: string;
63+
path?: string;
6464
}
6565

6666
interface LocationCompute {
67-
node: LocationNode;
68-
pool: LocationComputePool;
69-
tablet: LocationComputeTablet;
70-
schema: LocationComputeSchema;
67+
node?: LocationNode;
68+
pool?: LocationComputePool;
69+
tablet?: LocationComputeTablet;
70+
schema?: LocationComputeSchema;
7171
}
7272

7373
interface LocationDatabase {
74-
name: string;
74+
name?: string;
7575
}
7676

7777
export interface Location {
@@ -84,91 +84,91 @@ export interface Location {
8484

8585
export interface IssueLog {
8686
id: string;
87-
status: StatusFlag;
88-
message: string;
89-
location: Location;
87+
status?: StatusFlag;
88+
message?: string;
89+
location?: Location;
9090
reason?: string[];
91-
type: string;
92-
level: number;
91+
type?: string;
92+
level?: number;
9393
listed?: number;
9494
count?: number;
9595
}
9696

9797
interface StoragePDiskStatus {
98-
id: string;
99-
overall: StatusFlag;
98+
id?: string;
99+
overall?: StatusFlag;
100100
}
101101

102102
interface StorageVDiskStatus {
103-
id: string;
104-
overall: StatusFlag;
105-
vdisk_status: StatusFlag;
106-
pdisk: StoragePDiskStatus;
103+
id?: string;
104+
overall?: StatusFlag;
105+
vdisk_status?: StatusFlag;
106+
pdisk?: StoragePDiskStatus;
107107
}
108108

109109
interface StorageGroupStatus {
110-
id: string;
111-
overall: StatusFlag;
112-
vdisks: StorageVDiskStatus[];
110+
id?: string;
111+
overall?: StatusFlag;
112+
vdisks?: StorageVDiskStatus[];
113113
}
114114

115115
interface StoragePoolStatus {
116-
id: string;
117-
overall: StatusFlag;
118-
groups: StorageGroupStatus[];
116+
id?: string;
117+
overall?: StatusFlag;
118+
groups?: StorageGroupStatus[];
119119
}
120120

121121
interface StorageStatus {
122-
overall: StatusFlag;
123-
pools: StoragePoolStatus[];
122+
overall?: StatusFlag;
123+
pools?: StoragePoolStatus[];
124124
}
125125

126126
interface ComputeTabletStatus {
127-
overall: StatusFlag;
128-
type: string;
129-
state: string;
130-
count: number;
131-
id: string[];
127+
overall?: StatusFlag;
128+
type?: string;
129+
state?: string;
130+
count?: number;
131+
id?: string[];
132132
}
133133

134134
interface ThreadPoolStatus {
135-
overall: StatusFlag;
136-
name: string;
137-
usage: number;
135+
overall?: StatusFlag;
136+
name?: string;
137+
usage?: number;
138138
}
139139

140140
interface LoadAverageStatus {
141-
overall: StatusFlag;
142-
load: number;
143-
cores: number;
141+
overall?: StatusFlag;
142+
load?: number;
143+
cores?: number;
144144
}
145145

146146
interface ComputeNodeStatus {
147-
id: string;
148-
overall: StatusFlag;
149-
tablets: ComputeTabletStatus[];
150-
pools: ThreadPoolStatus[];
151-
load: LoadAverageStatus;
147+
id?: string;
148+
overall?: StatusFlag;
149+
tablets?: ComputeTabletStatus[];
150+
pools?: ThreadPoolStatus[];
151+
load?: LoadAverageStatus;
152152
}
153153

154154
interface ComputeStatus {
155-
overall: StatusFlag;
156-
nodes: ComputeNodeStatus[];
157-
tablets: ComputeTabletStatus[];
158-
paths_quota_usage: number;
159-
shards_quota_usage: number;
155+
overall?: StatusFlag;
156+
nodes?: ComputeNodeStatus[];
157+
tablets?: ComputeTabletStatus[];
158+
paths_quota_usage?: number;
159+
shards_quota_usage?: number;
160160
}
161161

162162
interface DatabaseStatus {
163-
name: string;
164-
overall: StatusFlag;
165-
storage: StorageStatus;
166-
compute: ComputeStatus;
163+
name?: string;
164+
overall?: StatusFlag;
165+
storage?: StorageStatus;
166+
compute?: ComputeStatus;
167167
}
168168

169169
export interface HealthCheckAPIResponse {
170170
// eslint-disable-next-line camelcase
171-
self_check_result: SelfCheckResult;
171+
self_check_result?: SelfCheckResult;
172172
// eslint-disable-next-line camelcase
173173
issue_log?: IssueLog[];
174174
// eslint-disable-next-line camelcase

0 commit comments

Comments
 (0)