diff --git a/src/containers/Cluster/ClusterDashboard/ClusterDashboard.tsx b/src/containers/Cluster/ClusterDashboard/ClusterDashboard.tsx index f7fc8f41c9..660899b751 100644 --- a/src/containers/Cluster/ClusterDashboard/ClusterDashboard.tsx +++ b/src/containers/Cluster/ClusterDashboard/ClusterDashboard.tsx @@ -3,8 +3,7 @@ import {Flex, Text} from '@gravity-ui/uikit'; import {ResponseError} from '../../../components/Errors/ResponseError'; import {Tags} from '../../../components/Tags'; import type {ClusterGroupsStats} from '../../../store/reducers/cluster/types'; -import {isClusterInfoV2} from '../../../types/api/cluster'; -import type {TClusterInfo} from '../../../types/api/cluster'; +import type {TClusterInfo, TClusterInfoV2} from '../../../types/api/cluster'; import type {IResponseError} from '../../../types/api/error'; import {valueIsDefined} from '../../../utils'; import {formatNumber} from '../../../utils/dataFormatters/dataFormatters'; @@ -24,6 +23,13 @@ import { import './ClusterDashboard.scss'; +// fixed CPU calculation +export function isClusterInfoV5(info?: TClusterInfo): info is TClusterInfoV2 { + return info + ? 'Version' in info && typeof info.Version === 'number' && info.Version >= 5 + : false; +} + interface AmountProps { value?: number | string; } @@ -39,14 +45,18 @@ function Amount({value}: AmountProps) { ); } -interface ClusterDashboardProps { - cluster: TClusterInfo; +interface ClusterDashboardProps { + cluster: T; groupStats?: ClusterGroupsStats; loading?: boolean; error?: IResponseError | string; } -export function ClusterDashboard(props: ClusterDashboardProps) { +export function ClusterDashboard({cluster, ...props}: ClusterDashboardProps) { + const isSupportedClusterResponse = isClusterInfoV5(cluster); + if (!isSupportedClusterResponse) { + return null; + } if (props.error) { return ; } @@ -54,28 +64,25 @@ export function ClusterDashboard(props: ClusterDashboardProps) {
- +
- +
); } -function ClusterDoughnuts({cluster, loading}: ClusterDashboardProps) { +function ClusterDoughnuts({cluster, loading}: ClusterDashboardProps) { if (loading) { return ; } const metricsCards = []; - if (isClusterInfoV2(cluster)) { - const {CoresUsed, NumberOfCpus} = cluster; - if (valueIsDefined(CoresUsed) && valueIsDefined(NumberOfCpus)) { - metricsCards.push( - , - ); - } + const {CoresUsed, NumberOfCpus, CoresTotal} = cluster; + const total = CoresTotal ?? NumberOfCpus; + if (valueIsDefined(CoresUsed) && valueIsDefined(total)) { + metricsCards.push(); } const {StorageTotal, StorageUsed} = cluster; if (valueIsDefined(StorageTotal) && valueIsDefined(StorageUsed)) { diff --git a/src/containers/Cluster/ClusterInfo/utils.tsx b/src/containers/Cluster/ClusterInfo/utils.tsx index 85fe01d5ec..d0718142ef 100644 --- a/src/containers/Cluster/ClusterInfo/utils.tsx +++ b/src/containers/Cluster/ClusterInfo/utils.tsx @@ -63,7 +63,7 @@ export const getInfo = ( const nodesStates = arrayNodesStates.map(([state, count]) => { return ( - {count} + {formatNumber(count)} ); }); diff --git a/src/types/api/cluster.ts b/src/types/api/cluster.ts index 544faf2139..178d2f68df 100644 --- a/src/types/api/cluster.ts +++ b/src/types/api/cluster.ts @@ -77,6 +77,7 @@ export interface TClusterInfoV2 extends TClusterInfoV1 { Version?: number; /** value is uint64 */ CoresUsed?: string; + CoresTotal?: number; } export type TClusterInfo = TClusterInfoV1 | TClusterInfoV2;