Skip to content

Commit f24e5e4

Browse files
authored
fix(ClusterDashboard): hide dashboard if /cluster handler version less 5 (#1535)
1 parent 6a99452 commit f24e5e4

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

src/containers/Cluster/ClusterDashboard/ClusterDashboard.tsx

+22-15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {Flex, Text} from '@gravity-ui/uikit';
33
import {ResponseError} from '../../../components/Errors/ResponseError';
44
import {Tags} from '../../../components/Tags';
55
import type {ClusterGroupsStats} from '../../../store/reducers/cluster/types';
6-
import {isClusterInfoV2} from '../../../types/api/cluster';
7-
import type {TClusterInfo} from '../../../types/api/cluster';
6+
import type {TClusterInfo, TClusterInfoV2} from '../../../types/api/cluster';
87
import type {IResponseError} from '../../../types/api/error';
98
import {valueIsDefined} from '../../../utils';
109
import {formatNumber} from '../../../utils/dataFormatters/dataFormatters';
@@ -24,6 +23,13 @@ import {
2423

2524
import './ClusterDashboard.scss';
2625

26+
// fixed CPU calculation
27+
export function isClusterInfoV5(info?: TClusterInfo): info is TClusterInfoV2 {
28+
return info
29+
? 'Version' in info && typeof info.Version === 'number' && info.Version >= 5
30+
: false;
31+
}
32+
2733
interface AmountProps {
2834
value?: number | string;
2935
}
@@ -39,43 +45,44 @@ function Amount({value}: AmountProps) {
3945
);
4046
}
4147

42-
interface ClusterDashboardProps {
43-
cluster: TClusterInfo;
48+
interface ClusterDashboardProps<T = TClusterInfo> {
49+
cluster: T;
4450
groupStats?: ClusterGroupsStats;
4551
loading?: boolean;
4652
error?: IResponseError | string;
4753
}
4854

49-
export function ClusterDashboard(props: ClusterDashboardProps) {
55+
export function ClusterDashboard({cluster, ...props}: ClusterDashboardProps) {
56+
const isSupportedClusterResponse = isClusterInfoV5(cluster);
57+
if (!isSupportedClusterResponse) {
58+
return null;
59+
}
5060
if (props.error) {
5161
return <ResponseError error={props.error} className={b('error')} />;
5262
}
5363
return (
5464
<div className={b()}>
5565
<Flex gap={4} wrap>
5666
<Flex gap={4} wrap="nowrap">
57-
<ClusterDoughnuts {...props} />
67+
<ClusterDoughnuts {...props} cluster={cluster} />
5868
</Flex>
5969
<div className={b('cards-container')}>
60-
<ClusterDashboardCards {...props} />
70+
<ClusterDashboardCards {...props} cluster={cluster} />
6171
</div>
6272
</Flex>
6373
</div>
6474
);
6575
}
6676

67-
function ClusterDoughnuts({cluster, loading}: ClusterDashboardProps) {
77+
function ClusterDoughnuts({cluster, loading}: ClusterDashboardProps<TClusterInfoV2>) {
6878
if (loading) {
6979
return <ClusterDashboardSkeleton />;
7080
}
7181
const metricsCards = [];
72-
if (isClusterInfoV2(cluster)) {
73-
const {CoresUsed, NumberOfCpus} = cluster;
74-
if (valueIsDefined(CoresUsed) && valueIsDefined(NumberOfCpus)) {
75-
metricsCards.push(
76-
<ClusterMetricsCores value={CoresUsed} capacity={NumberOfCpus} key="cores" />,
77-
);
78-
}
82+
const {CoresUsed, NumberOfCpus, CoresTotal} = cluster;
83+
const total = CoresTotal ?? NumberOfCpus;
84+
if (valueIsDefined(CoresUsed) && valueIsDefined(total)) {
85+
metricsCards.push(<ClusterMetricsCores value={CoresUsed} capacity={total} key="cores" />);
7986
}
8087
const {StorageTotal, StorageUsed} = cluster;
8188
if (valueIsDefined(StorageTotal) && valueIsDefined(StorageUsed)) {

src/containers/Cluster/ClusterInfo/utils.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const getInfo = (
6363
const nodesStates = arrayNodesStates.map(([state, count]) => {
6464
return (
6565
<NodesState state={state as EFlag} key={state}>
66-
{count}
66+
{formatNumber(count)}
6767
</NodesState>
6868
);
6969
});

src/types/api/cluster.ts

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export interface TClusterInfoV2 extends TClusterInfoV1 {
7777
Version?: number;
7878
/** value is uint64 */
7979
CoresUsed?: string;
80+
CoresTotal?: number;
8081
}
8182

8283
export type TClusterInfo = TClusterInfoV1 | TClusterInfoV2;

0 commit comments

Comments
 (0)