Skip to content

Commit f0742ab

Browse files
RaubzeugValeraS
andauthored
feat: use new /viewer/cluster handler format (#1272)
Co-authored-by: Valerii Sidorenko <balepas@nebius.com>
1 parent da9d465 commit f0742ab

File tree

22 files changed

+510
-295
lines changed

22 files changed

+510
-295
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/DiskStateProgressBar/DiskStateProgressBar.scss

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
@import '../../styles/mixins';
2+
13
.storage-disk-progress-bar {
24
$block: &;
35

46
$border-width: 1px;
57
$outer-border-radius: 4px;
68
$inner-border-radius: $outer-border-radius - $border-width;
79

8-
--progress-bar-border-color: var(--g-color-base-misc-heavy);
9-
--progress-bar-background-color: var(--g-color-base-misc-light);
10-
--progress-bar-fill-color: var(--g-color-base-misc-medium);
1110
--progress-bar-full-height: var(--g-text-body-3-line-height);
1211
--progress-bar-compact-height: 12px;
1312

@@ -20,9 +19,10 @@
2019
text-align: center;
2120

2221
color: var(--g-color-text-primary);
23-
border: $border-width solid var(--progress-bar-border-color);
22+
border: $border-width solid var(--entity-state-border-color);
2423
border-radius: $outer-border-radius;
25-
background-color: var(--progress-bar-background-color);
24+
background-color: var(--entity-state-background-color);
25+
@include entity-state-colors();
2626

2727
&_compact {
2828
min-width: 0;
@@ -31,35 +31,6 @@
3131
border-radius: 2px;
3232
}
3333

34-
&_green {
35-
--progress-bar-border-color: var(--g-color-base-positive-heavy);
36-
--progress-bar-background-color: var(--g-color-base-positive-light);
37-
--progress-bar-fill-color: var(--g-color-base-positive-medium);
38-
}
39-
40-
&_blue {
41-
--progress-bar-border-color: var(--g-color-base-info-heavy);
42-
--progress-bar-background-color: var(--g-color-base-info-light);
43-
--progress-bar-fill-color: var(--g-color-base-info-medium);
44-
}
45-
46-
&_yellow {
47-
--progress-bar-border-color: var(--g-color-base-warning-heavy);
48-
--progress-bar-background-color: var(--g-color-base-yellow-light);
49-
--progress-bar-fill-color: var(--g-color-base-yellow-medium);
50-
}
51-
52-
&_orange {
53-
--progress-bar-border-color: var(--ydb-color-status-orange);
54-
--progress-bar-background-color: var(--g-color-base-warning-light);
55-
--progress-bar-fill-color: var(--g-color-base-warning-medium);
56-
}
57-
&_red {
58-
--progress-bar-border-color: var(--g-color-base-danger-heavy);
59-
--progress-bar-background-color: var(--g-color-base-danger-light);
60-
--progress-bar-fill-color: var(--g-color-base-danger-medium);
61-
}
62-
6334
&_faded {
6435
background-color: unset;
6536
}
@@ -78,11 +49,11 @@
7849
height: 100%;
7950

8051
border-radius: $inner-border-radius 0 0 $inner-border-radius;
81-
background-color: var(--progress-bar-fill-color);
52+
background-color: var(--entity-state-fill-color);
8253

8354
&_faded {
8455
// Bg color is light variant, use it to make bar less bright
85-
background-color: var(--progress-bar-background-color);
56+
background-color: var(--entity-state-background-color);
8657
}
8758

8859
&_compact {

src/components/Tag/Tag.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import React from 'react';
2+
13
import {cn} from '../../utils/cn';
24

35
import './Tag.scss';
@@ -7,7 +9,7 @@ const b = cn('tag');
79
export type TagType = 'blue';
810

911
interface TagProps {
10-
text: string;
12+
text: React.ReactNode;
1113
type?: TagType;
1214
}
1315

src/components/Tags/Tags.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import React from 'react';
2+
13
import {cn} from '../../utils/cn';
24
import type {TagType} from '../Tag';
35
import {Tag} from '../Tag';
@@ -7,7 +9,7 @@ import './Tags.scss';
79
const b = cn('tags');
810

911
interface TagsProps {
10-
tags: string[];
12+
tags: React.ReactNode[];
1113
tagsType?: TagType;
1214
className?: string;
1315
}

src/containers/Cluster/ClusterInfo/ClusterInfo.scss

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,17 @@
4747
gap: var(--g-spacing-2);
4848
}
4949

50-
&__storage-groups-stats {
51-
display: flex;
52-
flex-direction: column;
53-
gap: 11px;
54-
}
55-
56-
&__groups-stats-bar {
57-
cursor: pointer;
58-
}
59-
60-
&__groups-stats-popup-content {
61-
padding: 12px;
62-
}
63-
6450
&__clipboard-button {
6551
display: flex;
6652
align-items: center;
6753

6854
margin-left: 5px;
6955
}
56+
&__dc-count {
57+
text-transform: lowercase;
58+
}
59+
&__nodes-states {
60+
display: flex;
61+
gap: var(--g-spacing-half);
62+
}
7063
}

src/containers/Cluster/ClusterInfo/ClusterInfo.tsx

Lines changed: 6 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -1,198 +1,20 @@
1-
import React from 'react';
2-
3-
import {ContentWithPopup} from '../../../components/ContentWithPopup/ContentWithPopup';
41
import {ResponseError} from '../../../components/Errors/ResponseError';
5-
import type {InfoViewerItem} from '../../../components/InfoViewer/InfoViewer';
62
import {InfoViewer} from '../../../components/InfoViewer/InfoViewer';
73
import {InfoViewerSkeleton} from '../../../components/InfoViewerSkeleton/InfoViewerSkeleton';
8-
import {LinkWithIcon} from '../../../components/LinkWithIcon/LinkWithIcon';
9-
import {ProgressViewer} from '../../../components/ProgressViewer/ProgressViewer';
10-
import {Tablet} from '../../../components/Tablet';
11-
import {Tags} from '../../../components/Tags';
124
import {backend, customBackend} from '../../../store';
13-
import type {
14-
ClusterGroupsStats,
15-
DiskErasureGroupsStats,
16-
DiskGroupsStats,
17-
} from '../../../store/reducers/cluster/types';
18-
import {nodesApi} from '../../../store/reducers/nodes/nodes';
19-
import type {AdditionalClusterProps, ClusterLink} from '../../../types/additionalProps';
5+
import type {ClusterGroupsStats} from '../../../store/reducers/cluster/types';
6+
import type {AdditionalClusterProps} from '../../../types/additionalProps';
207
import type {TClusterInfo} from '../../../types/api/cluster';
218
import type {IResponseError} from '../../../types/api/error';
22-
import type {VersionToColorMap, VersionValue} from '../../../types/versions';
23-
import {formatBytes, getSizeWithSignificantDigits} from '../../../utils/bytesParsers';
24-
import {cn} from '../../../utils/cn';
9+
import type {VersionToColorMap} from '../../../types/versions';
2510
import {DEVELOPER_UI_TITLE} from '../../../utils/constants';
26-
import {formatStorageValues} from '../../../utils/dataFormatters/dataFormatters';
2711
import {useTypedSelector} from '../../../utils/hooks';
28-
import {parseNodeGroupsToVersionsValues, parseNodesToVersionsValues} from '../../../utils/versions';
29-
import {VersionsBar} from '../VersionsBar/VersionsBar';
30-
import i18n from '../i18n';
3112

32-
import {compareTablets} from './utils';
13+
import {b} from './shared';
14+
import {getInfo, useGetVersionValues} from './utils';
3315

3416
import './ClusterInfo.scss';
3517

36-
const b = cn('cluster-info');
37-
38-
interface GroupsStatsPopupContentProps {
39-
stats: DiskErasureGroupsStats;
40-
}
41-
42-
const GroupsStatsPopupContent = ({stats}: GroupsStatsPopupContentProps) => {
43-
const {diskType, erasure, allocatedSize, availableSize} = stats;
44-
45-
const sizeToConvert = getSizeWithSignificantDigits(Math.max(allocatedSize, availableSize), 2);
46-
47-
const convertedAllocatedSize = formatBytes({value: allocatedSize, size: sizeToConvert});
48-
const convertedAvailableSize = formatBytes({value: availableSize, size: sizeToConvert});
49-
50-
const usage = Math.round((allocatedSize / (allocatedSize + availableSize)) * 100);
51-
52-
const info = [
53-
{
54-
label: i18n('disk-type'),
55-
value: diskType,
56-
},
57-
{
58-
label: i18n('erasure'),
59-
value: erasure,
60-
},
61-
{
62-
label: i18n('allocated'),
63-
value: convertedAllocatedSize,
64-
},
65-
{
66-
label: i18n('available'),
67-
value: convertedAvailableSize,
68-
},
69-
{
70-
label: i18n('usage'),
71-
value: usage + '%',
72-
},
73-
];
74-
75-
return (
76-
<InfoViewer dots={true} info={info} className={b('groups-stats-popup-content')} size="s" />
77-
);
78-
};
79-
80-
interface DiskGroupsStatsProps {
81-
stats: DiskGroupsStats;
82-
}
83-
84-
const DiskGroupsStatsBars = ({stats}: DiskGroupsStatsProps) => {
85-
return (
86-
<div className={b('storage-groups-stats')}>
87-
{Object.values(stats).map((erasureStats) => (
88-
<ContentWithPopup
89-
placement={['right']}
90-
key={erasureStats.erasure}
91-
content={<GroupsStatsPopupContent stats={erasureStats} />}
92-
>
93-
<ProgressViewer
94-
className={b('groups-stats-bar')}
95-
value={erasureStats.createdGroups}
96-
capacity={erasureStats.totalGroups}
97-
/>
98-
</ContentWithPopup>
99-
))}
100-
</div>
101-
);
102-
};
103-
104-
const getGroupsStatsFields = (groupsStats: ClusterGroupsStats) => {
105-
return Object.keys(groupsStats).map((diskType) => {
106-
return {
107-
label: i18n('storage-groups', {diskType}),
108-
value: <DiskGroupsStatsBars stats={groupsStats[diskType]} />,
109-
};
110-
});
111-
};
112-
113-
const getInfo = (
114-
cluster: TClusterInfo,
115-
versionsValues: VersionValue[],
116-
groupsStats: ClusterGroupsStats,
117-
additionalInfo: InfoViewerItem[],
118-
links: ClusterLink[],
119-
) => {
120-
const info: InfoViewerItem[] = [];
121-
122-
if (cluster.DataCenters) {
123-
info.push({
124-
label: i18n('dc'),
125-
value: <Tags tags={cluster.DataCenters} />,
126-
});
127-
}
128-
129-
if (cluster.SystemTablets) {
130-
const tablets = cluster.SystemTablets.slice(0).sort(compareTablets);
131-
info.push({
132-
label: i18n('tablets'),
133-
value: (
134-
<div className={b('system-tablets')}>
135-
{tablets.map((tablet, tabletIndex) => (
136-
<Tablet key={tabletIndex} tablet={tablet} />
137-
))}
138-
</div>
139-
),
140-
});
141-
}
142-
143-
if (cluster.Tenants) {
144-
info.push({
145-
label: i18n('databases'),
146-
value: cluster.Tenants,
147-
});
148-
}
149-
150-
info.push(
151-
{
152-
label: i18n('nodes'),
153-
value: <ProgressViewer value={cluster?.NodesAlive} capacity={cluster?.NodesTotal} />,
154-
},
155-
{
156-
label: i18n('load'),
157-
value: <ProgressViewer value={cluster?.LoadAverage} capacity={cluster?.NumberOfCpus} />,
158-
},
159-
{
160-
label: i18n('storage-size'),
161-
value: (
162-
<ProgressViewer
163-
value={cluster?.StorageUsed}
164-
capacity={cluster?.StorageTotal}
165-
formatValues={formatStorageValues}
166-
/>
167-
),
168-
},
169-
);
170-
171-
if (Object.keys(groupsStats).length) {
172-
info.push(...getGroupsStatsFields(groupsStats));
173-
}
174-
175-
info.push(
176-
...additionalInfo,
177-
{
178-
label: i18n('links'),
179-
value: (
180-
<div className={b('links')}>
181-
{links.map(({title, url}) => (
182-
<LinkWithIcon key={title} title={title} url={url} />
183-
))}
184-
</div>
185-
),
186-
},
187-
{
188-
label: i18n('versions'),
189-
value: <VersionsBar versionsValues={versionsValues} />,
190-
},
191-
);
192-
193-
return info;
194-
};
195-
19618
interface ClusterInfoProps {
19719
cluster?: TClusterInfo;
19820
versionToColor?: VersionToColorMap;
@@ -212,20 +34,7 @@ export const ClusterInfo = ({
21234
}: ClusterInfoProps) => {
21335
const singleClusterMode = useTypedSelector((state) => state.singleClusterMode);
21436

215-
const {currentData} = nodesApi.useGetNodesQuery({
216-
tablets: false,
217-
group: 'Version',
218-
});
219-
220-
const versionsValues = React.useMemo(() => {
221-
if (!currentData) {
222-
return [];
223-
}
224-
if (Array.isArray(currentData.NodeGroups)) {
225-
return parseNodeGroupsToVersionsValues(currentData.NodeGroups, versionToColor);
226-
}
227-
return parseNodesToVersionsValues(currentData.Nodes, versionToColor);
228-
}, [currentData, versionToColor]);
37+
const versionsValues = useGetVersionValues(cluster, versionToColor);
22938

23039
let internalLink = backend + '/internal';
23140

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.ydb-disk-groups-stats {
2+
display: flex;
3+
flex-direction: column;
4+
gap: var(--g-spacing-3);
5+
&__bar {
6+
cursor: pointer;
7+
}
8+
&__popup-content {
9+
padding: var(--g-spacing-3);
10+
}
11+
}

0 commit comments

Comments
 (0)