Skip to content

Commit 7c1afad

Browse files
committed
fix: incorrect storage group count
1 parent ac8b3dd commit 7c1afad

File tree

3 files changed

+42
-22
lines changed

3 files changed

+42
-22
lines changed

src/containers/Tenant/Diagnostics/TenantOverview/MetricsTabs/MetricsTabs.tsx

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import {Flex} from '@gravity-ui/uikit';
22
import {Link, useLocation} from 'react-router-dom';
33

44
import {parseQuery} from '../../../../../routes';
5+
import {
6+
useCapabilitiesLoaded,
7+
useStorageGroupsHandlerAvailable,
8+
} from '../../../../../store/reducers/capabilities/hooks';
9+
import {storageApi} from '../../../../../store/reducers/storage/storage';
510
import {TENANT_METRICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
611
import type {TenantMetricsTab} from '../../../../../store/reducers/tenant/types';
712
import type {
@@ -11,7 +16,7 @@ import type {
1116
} from '../../../../../store/reducers/tenants/utils';
1217
import {cn} from '../../../../../utils/cn';
1318
import {SHOW_NETWORK_UTILIZATION} from '../../../../../utils/constants';
14-
import {useSetting, useTypedSelector} from '../../../../../utils/hooks';
19+
import {useAutoRefreshInterval, useSetting, useTypedSelector} from '../../../../../utils/hooks';
1520
import {calculateMetricAggregates} from '../../../../../utils/metrics';
1621
import {
1722
formatCoresLegend,
@@ -27,6 +32,7 @@ import './MetricsTabs.scss';
2732
const b = cn('tenant-metrics-tabs');
2833

2934
interface MetricsTabsProps {
35+
tenantName: string;
3036
poolsCpuStats?: TenantPoolsStats[];
3137
memoryStats?: TenantMetricStats[];
3238
blobStorageStats?: TenantStorageStats[];
@@ -35,6 +41,7 @@ interface MetricsTabsProps {
3541
}
3642

3743
export function MetricsTabs({
44+
tenantName,
3845
poolsCpuStats,
3946
memoryStats,
4047
blobStorageStats,
@@ -45,6 +52,25 @@ export function MetricsTabs({
4552
const {metricsTab} = useTypedSelector((state) => state.tenant);
4653
const queryParams = parseQuery(location);
4754

55+
// Fetch storage groups data to get correct count (only if groups handler available)
56+
const capabilitiesLoaded = useCapabilitiesLoaded();
57+
const groupsHandlerAvailable = useStorageGroupsHandlerAvailable();
58+
const [autoRefreshInterval] = useAutoRefreshInterval();
59+
60+
const {currentData: storageGroupsData} = storageApi.useGetStorageGroupsInfoQuery(
61+
{
62+
tenant: tenantName,
63+
shouldUseGroupsHandler: groupsHandlerAvailable,
64+
with: 'all',
65+
limit: 0,
66+
fieldsRequired: [],
67+
},
68+
{
69+
pollingInterval: autoRefreshInterval,
70+
skip: !capabilitiesLoaded || !groupsHandlerAvailable,
71+
},
72+
);
73+
4874
const tabLinks: Record<TenantMetricsTab, string> = {
4975
[TENANT_METRICS_TABS_IDS.cpu]: getTenantPath({
5076
...queryParams,
@@ -73,7 +99,9 @@ export function MetricsTabs({
7399
// Calculate storage metrics using utility
74100
const storageStats = tabletStorageStats || blobStorageStats || [];
75101
const storageMetrics = calculateMetricAggregates(storageStats);
76-
const storageGroupCount = storageStats.length;
102+
103+
// Get correct storage groups count from API (only if groups handler available)
104+
const storageGroupCount = groupsHandlerAvailable ? (storageGroupsData?.total ?? 0) : undefined;
77105

78106
// Calculate memory metrics using utility
79107
const memoryMetrics = calculateMetricAggregates(memoryStats);
@@ -91,8 +119,7 @@ export function MetricsTabs({
91119
>
92120
<Link to={tabLinks.cpu} className={b('link')}>
93121
<TabCard
94-
label={i18n('cards.cpu-label')}
95-
sublabel={i18n('context_cpu-load')}
122+
text={i18n('context_cpu-load')}
96123
value={cpuMetrics.totalUsed}
97124
limit={cpuMetrics.totalLimit}
98125
legendFormatter={formatCoresLegend}
@@ -108,8 +135,11 @@ export function MetricsTabs({
108135
>
109136
<Link to={tabLinks.storage} className={b('link')}>
110137
<TabCard
111-
label={i18n('cards.storage-label')}
112-
sublabel={i18n('context_storage-groups', {count: storageGroupCount})}
138+
text={
139+
storageGroupCount === undefined
140+
? i18n('cards.storage-label')
141+
: i18n('context_storage-groups', {count: storageGroupCount})
142+
}
113143
value={storageMetrics.totalUsed}
114144
limit={storageMetrics.totalLimit}
115145
legendFormatter={formatStorageLegend}
@@ -125,8 +155,7 @@ export function MetricsTabs({
125155
>
126156
<Link to={tabLinks.memory} className={b('link')}>
127157
<TabCard
128-
label={i18n('cards.memory-label')}
129-
sublabel={i18n('context_memory-used')}
158+
text={i18n('context_memory-used')}
130159
value={memoryMetrics.totalUsed}
131160
limit={memoryMetrics.totalLimit}
132161
legendFormatter={formatStorageLegend}
@@ -143,8 +172,7 @@ export function MetricsTabs({
143172
>
144173
<Link to={tabLinks.network} className={b('link')}>
145174
<TabCard
146-
label={i18n('cards.network-label')}
147-
sublabel={i18n('context_network-usage')}
175+
text={i18n('context_network-usage')}
148176
value={networkMetrics.totalUsed}
149177
limit={networkMetrics.totalLimit}
150178
legendFormatter={formatSpeedLegend}

src/containers/Tenant/Diagnostics/TenantOverview/TabCard/TabCard.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,15 @@ import './TabCard.scss';
99
const b = cn('tenant-tab-card');
1010

1111
interface TabCardProps {
12-
label: string;
13-
sublabel?: string;
12+
text: string;
1413
value: number;
1514
limit: number;
1615
active?: boolean;
1716
helpText?: string;
1817
legendFormatter: (params: {value: number; capacity: number}) => string;
1918
}
2019

21-
export function TabCard({
22-
label,
23-
sublabel,
24-
value,
25-
limit,
26-
active,
27-
helpText,
28-
legendFormatter,
29-
}: TabCardProps) {
20+
export function TabCard({text, value, limit, active, helpText, legendFormatter}: TabCardProps) {
3021
const {status, percents, legend, fill} = getDiagramValues({
3122
value,
3223
capacity: limit,
@@ -61,7 +52,7 @@ export function TabCard({
6152
note={helpText}
6253
noteIconSize="s"
6354
>
64-
{sublabel || label}
55+
{text}
6556
</DoughnutMetrics.Legend>
6657
</div>
6758
</Flex>

src/containers/Tenant/Diagnostics/TenantOverview/TenantOverview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export function TenantOverview({
173173
<HealthcheckPreview tenantName={tenantName} />
174174
<QueriesActivityBar tenantName={tenantName} />
175175
<MetricsTabs
176+
tenantName={tenantName}
176177
poolsCpuStats={poolsStats}
177178
memoryStats={memoryStats}
178179
blobStorageStats={blobStorageStats}

0 commit comments

Comments
 (0)