Skip to content

Commit 775bacf

Browse files
fix: update tenant cpu (#736)
* do not show cores used in metric card * add ic pool to cpu usage calculation * add cores to chart title
1 parent 122a006 commit 775bacf

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ interface MetricCardProps {
2121

2222
export function MetricCard({active, progress, label, status, resourcesUsed}: MetricCardProps) {
2323
const renderContent = () => {
24+
if (progress === undefined && resourcesUsed === undefined) {
25+
return <div className={b('content')}>{i18n('no-data')}</div>;
26+
}
27+
2428
return (
2529
<div className={b('content')}>
2630
{progress && <div className={b('progress')}>{formatUsage(progress)}</div>}
27-
{resourcesUsed ? (
28-
<div className={b('resources')}>{resourcesUsed}</div>
29-
) : (
30-
i18n('no-data')
31-
)}
31+
{resourcesUsed && <div className={b('resources')}>{resourcesUsed}</div>}
3232
</div>
3333
);
3434
};

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function MetricsCards({
5353
}: MetricsCardsProps) {
5454
const location = useLocation();
5555

56-
const {memoryUsed, memoryLimit, cpuUsed, cpuUsage, storageUsed, storageLimit} = metrics || {};
56+
const {memoryUsed, memoryLimit, cpuUsage, storageUsed, storageLimit} = metrics || {};
5757

5858
const {metricsTab} = useTypedSelector((state) => state.tenant);
5959

@@ -64,8 +64,7 @@ export function MetricsCards({
6464
const storageStatus = storageUsageToStatus(storageUsage);
6565
const memoryStatus = memoryUsageToStatus(memoryUsage);
6666

67-
const {cpu, storage, memory} = formatTenantMetrics({
68-
cpu: cpuUsed,
67+
const {storage, memory} = formatTenantMetrics({
6968
storage: storageUsed,
7069
memory: memoryUsed,
7170
});
@@ -107,7 +106,6 @@ export function MetricsCards({
107106
label="CPU"
108107
progress={cpuUsage}
109108
status={cpuStatus}
110-
resourcesUsed={cpu}
111109
active={metricsTab === TENANT_METRICS_TABS_IDS.cpu}
112110
/>
113111
</Link>

src/containers/Tenant/Diagnostics/TenantOverview/i18n/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
"charts.queries-per-second": "Queries per second",
2525
"charts.transaction-latency": "Transactions latencies {{percentile}}",
26-
"charts.cpu-usage": "CPU usage",
26+
"charts.cpu-usage": "CPU cores used",
2727
"charts.storage-usage": "Tablet storage usage",
2828
"charts.memory-usage": "Memory usage",
2929

src/store/reducers/tenants/utils.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {TPoolStats} from '../../../types/api/nodes';
12
import type {TTenant} from '../../../types/api/tenant';
23
import {formatBytes} from '../../../utils/bytesParsers';
34
import {formatCPUWithLabel} from '../../../utils/dataFormatters/dataFormatters';
@@ -21,6 +22,20 @@ const getTenantBackend = (tenant: TTenant) => {
2122
return node.Host ? `${node.Host}${address ? address : ''}` : undefined;
2223
};
2324

25+
const calculateCpuUsage = (poolsStats: TPoolStats[] | undefined) => {
26+
if (!poolsStats) {
27+
return undefined;
28+
}
29+
30+
const systemPoolUsage = poolsStats?.find(({Name}) => Name === 'System')?.Usage || 0;
31+
const userPoolUsage = poolsStats?.find(({Name}) => Name === 'User')?.Usage || 0;
32+
const icPoolUsage = poolsStats?.find(({Name}) => Name === 'IC')?.Usage || 0;
33+
34+
// We use max of system, user and ic pools usage to calculate cpu usage because
35+
// only these pools directly indicate resources available to perform user queries
36+
return Math.max(Number(systemPoolUsage), Number(userPoolUsage), Number(icPoolUsage)) * 100;
37+
};
38+
2439
export const calculateTenantMetrics = (tenant?: TTenant) => {
2540
const {
2641
CoresUsed,
@@ -33,20 +48,13 @@ export const calculateTenantMetrics = (tenant?: TTenant) => {
3348
DatabaseQuotas = {},
3449
} = tenant || {};
3550

36-
const systemPoolUsage = PoolStats?.find(({Name}) => Name === 'System')?.Usage;
37-
const userPoolUsage = PoolStats?.find(({Name}) => Name === 'User')?.Usage;
38-
3951
const cpu = isNumeric(CoresUsed) ? Number(CoresUsed) * 1_000_000 : undefined;
4052
const memory = isNumeric(MemoryUsed) ? Number(MemoryUsed) : undefined;
4153
const blobStorage = isNumeric(StorageAllocatedSize) ? Number(StorageAllocatedSize) : undefined;
4254
const tabletStorage = isNumeric(Metrics.Storage) ? Number(Metrics.Storage) : undefined;
4355

44-
// We use system pool usage and user pool usage to calculate cpu usage because
45-
// only these pools directly indicate resources available to perform user queries
46-
const cpuUsage =
47-
isNumeric(systemPoolUsage) || isNumeric(userPoolUsage)
48-
? Math.max(Number(systemPoolUsage), Number(userPoolUsage)) * 100
49-
: undefined;
56+
const cpuUsage = calculateCpuUsage(PoolStats);
57+
5058
const memoryLimit = isNumeric(MemoryLimit) ? Number(MemoryLimit) : undefined;
5159
const blobStorageLimit = isNumeric(StorageAllocatedLimit)
5260
? Number(StorageAllocatedLimit)

src/types/api/nodes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ export interface TSystemStateInfo {
8181
TotalSessions?: number;
8282
}
8383

84+
export type PoolName = 'System' | 'User' | 'Batch' | 'IO' | 'IC';
85+
8486
export interface TPoolStats {
85-
Name?: string;
87+
Name?: PoolName;
8688
/** double */
8789
Usage?: number;
8890
Threads?: number;

0 commit comments

Comments
 (0)