-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathBrokersList.tsx
268 lines (257 loc) · 8.21 KB
/
BrokersList.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import React from 'react';
import { ClusterName } from 'redux/interfaces';
import { useNavigate } from 'react-router-dom';
import PageHeading from 'components/common/PageHeading/PageHeading';
import * as Metrics from 'components/common/Metrics';
import useAppParams from 'lib/hooks/useAppParams';
import { useBrokers } from 'lib/hooks/api/brokers';
import { useClusterStats } from 'lib/hooks/api/clusters';
import Table, { LinkCell, SizeCell } from 'components/common/NewTable';
import CheckMarkRoundIcon from 'components/common/Icons/CheckMarkRoundIcon';
import { ColumnDef } from '@tanstack/react-table';
import { clusterBrokerPath } from 'lib/paths';
import Tooltip from 'components/common/Tooltip/Tooltip';
import ColoredCell from 'components/common/NewTable/ColoredCell';
import { BrokerDiskUsage } from 'generated-sources';
import SkewHeader from './SkewHeader/SkewHeader';
import * as S from './BrokersList.styled';
const NA = 'N/A' as unknown;
const BrokersList: React.FC = () => {
const navigate = useNavigate();
const { clusterName } = useAppParams<{ clusterName: ClusterName }>();
const { data: clusterStats = {} } = useClusterStats(clusterName);
const { data: brokers = [] } = useBrokers(clusterName);
const {
brokerCount,
activeControllers,
onlinePartitionCount,
offlinePartitionCount,
inSyncReplicasCount,
outOfSyncReplicasCount,
underReplicatedPartitionCount,
diskUsage,
version,
} = clusterStats;
const rows = React.useMemo(() => {
let brokersResource: BrokerDiskUsage[];
if (!diskUsage || !diskUsage?.length) {
brokersResource =
brokers?.map((broker) => {
return {
brokerId: broker.id,
segmentSize: NA as number,
segmentCount: NA as number,
};
}) || [];
} else {
brokersResource = diskUsage;
}
return brokers?.map(
({
id,
port,
host,
partitionsLeader,
partitionsSkew,
leadersSkew,
inSyncPartitions,
}) => {
const brokerResource = brokersResource.find(
({ brokerId }) => id === brokerId
);
return {
brokerId: id,
size: brokerResource?.segmentSize || NA,
count: brokerResource?.segmentCount || NA,
port,
host,
partitionsLeader,
partitionsSkew,
leadersSkew,
inSyncPartitions,
};
}
);
}, [diskUsage, brokers]);
const columns = React.useMemo<ColumnDef<(typeof rows)[number]>[]>(
() => [
{
header: 'Broker ID',
accessorKey: 'brokerId',
// eslint-disable-next-line react/no-unstable-nested-components
cell: ({ row: { id }, getValue }) => (
<S.RowCell>
<LinkCell
value={`${getValue<string | number>()}`}
to={encodeURIComponent(`${getValue<string | number>()}`)}
/>
{id === String(activeControllers) && (
<Tooltip
value={<CheckMarkRoundIcon />}
content="Active Controller"
placement="right"
/>
)}
</S.RowCell>
),
},
{
header: 'Disk usage',
accessorKey: 'size',
// eslint-disable-next-line react/no-unstable-nested-components
cell: ({ getValue, table, cell, column, renderValue, row }) =>
getValue() === NA ? (
NA
) : (
<SizeCell
table={table}
column={column}
row={row}
cell={cell}
getValue={getValue}
renderValue={renderValue}
renderSegments
precision={2}
/>
),
},
{
// eslint-disable-next-line react/no-unstable-nested-components
header: () => <SkewHeader />,
accessorKey: 'partitionsSkew',
// eslint-disable-next-line react/no-unstable-nested-components
cell: ({ getValue }) => {
const value = getValue<number>();
return (
<ColoredCell
value={value ? `${value.toFixed(2)}%` : '-'}
warn={value >= 10 && value < 20}
attention={value >= 20}
/>
);
},
},
{ header: 'Leaders', accessorKey: 'partitionsLeader' },
{
header: 'Leader skew',
accessorKey: 'leadersSkew',
// eslint-disable-next-line react/no-unstable-nested-components
cell: ({ getValue }) => {
const value = getValue<number>();
return (
<ColoredCell
value={value ? `${value.toFixed(2)}%` : '-'}
warn={value >= 10 && value < 20}
attention={value >= 20}
/>
);
},
},
{
header: 'Online partitions',
accessorKey: 'inSyncPartitions',
// eslint-disable-next-line react/no-unstable-nested-components
cell: ({ getValue, row }) => {
const value = getValue<number>();
return (
<ColoredCell
value={value}
attention={value !== row.original.count}
/>
);
},
},
{ header: 'Port', accessorKey: 'port' },
{
header: 'Host',
accessorKey: 'host',
},
],
[]
);
const replicas = (inSyncReplicasCount ?? 0) + (outOfSyncReplicasCount ?? 0);
const areAllInSync = inSyncReplicasCount && replicas === inSyncReplicasCount;
const partitionIsOffline = offlinePartitionCount && offlinePartitionCount > 0;
const isActiveControllerUnKnown = typeof activeControllers === 'undefined';
return (
<>
<PageHeading text="Brokers" />
<Metrics.Wrapper>
<Metrics.Section title="Uptime">
<Metrics.Indicator label="Broker Count">
{brokerCount}
</Metrics.Indicator>
<Metrics.Indicator
label="Active Controller"
isAlert={isActiveControllerUnKnown}
>
{isActiveControllerUnKnown ? (
<S.DangerText>No Active Controller</S.DangerText>
) : (
activeControllers
)}
</Metrics.Indicator>
<Metrics.Indicator label="Version">{version}</Metrics.Indicator>
</Metrics.Section>
<Metrics.Section title="Partitions">
<Metrics.Indicator
label="Online"
isAlert
alertType={partitionIsOffline ? 'error' : 'success'}
>
{partitionIsOffline ? (
<Metrics.RedText>{onlinePartitionCount}</Metrics.RedText>
) : (
onlinePartitionCount
)}
<Metrics.LightText>
{` of ${
(onlinePartitionCount || 0) + (offlinePartitionCount || 0)
}
`}
</Metrics.LightText>
</Metrics.Indicator>
<Metrics.Indicator
label="URP"
title="Under replicated partitions"
isAlert
alertType={!underReplicatedPartitionCount ? 'success' : 'error'}
>
{!underReplicatedPartitionCount ? (
<Metrics.LightText>
{underReplicatedPartitionCount}
</Metrics.LightText>
) : (
<Metrics.RedText>{underReplicatedPartitionCount}</Metrics.RedText>
)}
</Metrics.Indicator>
<Metrics.Indicator
label="In Sync Replicas"
isAlert
alertType={areAllInSync ? 'success' : 'error'}
>
{areAllInSync ? (
replicas
) : (
<Metrics.RedText>{inSyncReplicasCount}</Metrics.RedText>
)}
<Metrics.LightText> of {replicas}</Metrics.LightText>
</Metrics.Indicator>
<Metrics.Indicator label="Out Of Sync Replicas">
{outOfSyncReplicasCount}
</Metrics.Indicator>
</Metrics.Section>
</Metrics.Wrapper>
<Table
columns={columns}
data={rows}
enableSorting
onRowClick={({ original: { brokerId } }) =>
navigate(clusterBrokerPath(clusterName, brokerId))
}
emptyMessage="No clusters are online"
/>
</>
);
};
export default BrokersList;