Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/containers/Tenant/Diagnostics/Diagnostics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {Partitions} from './Partitions/Partitions';
import {TopQueries} from './TopQueries';
import {TopShards} from './TopShards';
import {TopicData} from './TopicData/TopicData';
import i18n from './i18n';

import './Diagnostics.scss';

Expand All @@ -60,7 +61,7 @@ function Diagnostics(props: DiagnosticsProps) {

const tenantName = isDatabaseEntityType(type) ? path : database;

const {controlPlane} = useTenantBaseInfo(isDatabaseEntityType(type) ? path : '');
const {controlPlane, databaseType} = useTenantBaseInfo(isDatabaseEntityType(type) ? path : '');

const hasFeatureFlags = useFeatureFlagsAvailable();
const hasTopicData = useTopicDataAvailable();
Expand All @@ -72,6 +73,7 @@ function Diagnostics(props: DiagnosticsProps) {
hasBackups: typeof uiFactory.renderBackups === 'function' && Boolean(controlPlane),
hasConfigs: isViewerUser,
hasAccess: uiFactory.hasAccess,
isServerless: databaseType === 'Serverless',
});
let activeTab = pages.find((el) => el.id === diagnosticsTab);
if (!activeTab) {
Expand Down Expand Up @@ -176,7 +178,7 @@ function Diagnostics(props: DiagnosticsProps) {
});
}
default: {
return <div>No data...</div>;
return <div>{i18n('no-data')}</div>;
}
}
};
Expand All @@ -187,10 +189,10 @@ function Diagnostics(props: DiagnosticsProps) {
<TabProvider value={activeTab?.id}>
<TabList size="l">
{pages.map(({id, title}) => {
const path = getDiagnosticsPageLink(id);
const linkPath = getDiagnosticsPageLink(id);
return (
<Tab key={id} value={id}>
<InternalLink to={path} as="tab">
<InternalLink to={linkPath} as="tab">
{title}
</InternalLink>
</Tab>
Expand Down
85 changes: 58 additions & 27 deletions src/containers/Tenant/Diagnostics/DiagnosticsPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ type Page = {
title: string;
};

interface GetPagesOptions {
hasFeatureFlags?: boolean;
hasTopicData?: boolean;
isTopLevel?: boolean;
hasBackups?: boolean;
hasConfigs?: boolean;
hasAccess?: boolean;
isServerless?: boolean;
}

const overview = {
id: TENANT_DIAGNOSTICS_TABS_IDS.overview,
title: 'Info',
Expand Down Expand Up @@ -118,6 +128,16 @@ const DATABASE_PAGES = [
backups,
];

const SERVERLESS_DATABASE_PAGES = [
overview,
topQueries,
topShards,
tablets,
describe,
configs,
operations,
];

const TABLE_PAGES = [overview, schema, topShards, nodes, graph, tablets, hotKeys, describe, access];
const COLUMN_TABLE_PAGES = [overview, schema, topShards, nodes, tablets, describe, access];

Expand Down Expand Up @@ -168,41 +188,52 @@ const pathSubTypeToPages: Record<EPathSubType, Page[] | undefined> = {
[EPathSubType.EPathSubTypeEmpty]: undefined,
};

export const getPagesByType = (
type?: EPathType,
subType?: EPathSubType,
options?: {
hasFeatureFlags?: boolean;
hasTopicData?: boolean;
isTopLevel?: boolean;
hasBackups?: boolean;
hasConfigs?: boolean;
hasAccess?: boolean;
},
) => {
function computeInitialPages(type?: EPathType, subType?: EPathSubType) {
const subTypePages = subType ? pathSubTypeToPages[subType] : undefined;
const typePages = type ? pathTypeToPages[type] : undefined;
let pages = subTypePages || typePages || DIR_PAGES;
return subTypePages || typePages || DIR_PAGES;
}

function getDatabasePages(isServerless?: boolean) {
return isServerless ? SERVERLESS_DATABASE_PAGES : DATABASE_PAGES;
}

function applyFilters(pages: Page[], type?: EPathType, options: GetPagesOptions = {}) {
let result = pages;

if (isTopicEntityType(type) && !options?.hasTopicData) {
pages = pages?.filter((item) => item.id !== TENANT_DIAGNOSTICS_TABS_IDS.topicData);
if (isTopicEntityType(type) && !options.hasTopicData) {
result = result.filter((p) => p.id !== TENANT_DIAGNOSTICS_TABS_IDS.topicData);
}
if (isDatabaseEntityType(type) || options?.isTopLevel) {
pages = DATABASE_PAGES;
if (!options?.hasFeatureFlags) {
pages = pages.filter((item) => item.id !== TENANT_DIAGNOSTICS_TABS_IDS.configs);
}

const removals: TenantDiagnosticsTab[] = [];
if (!options.hasBackups) {
removals.push(TENANT_DIAGNOSTICS_TABS_IDS.backups);
}
if (!options?.hasBackups) {
pages = pages.filter((item) => item.id !== TENANT_DIAGNOSTICS_TABS_IDS.backups);
if (!options.hasConfigs) {
removals.push(TENANT_DIAGNOSTICS_TABS_IDS.configs);
}
if (!options?.hasConfigs) {
pages = pages.filter((item) => item.id !== TENANT_DIAGNOSTICS_TABS_IDS.configs);
if (!options.hasAccess) {
removals.push(TENANT_DIAGNOSTICS_TABS_IDS.access);
}
if (!options?.hasAccess) {
pages = pages.filter((item) => item.id !== TENANT_DIAGNOSTICS_TABS_IDS.access);

return result.filter((p) => !removals.includes(p.id));
}

export const getPagesByType = (
type?: EPathType,
subType?: EPathSubType,
options?: GetPagesOptions,
) => {
const base = computeInitialPages(type, subType);
const dbContext = isDatabaseEntityType(type) || options?.isTopLevel;
const seeded = dbContext ? getDatabasePages(options?.isServerless) : base;

let withFlags = seeded;
if (!options?.hasFeatureFlags) {
withFlags = seeded.filter((p) => p.id !== TENANT_DIAGNOSTICS_TABS_IDS.configs);
}
return pages;

return applyFilters(withFlags, type, options);
};

export const useDiagnosticsPageLinkGetter = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {useMemo} from 'react';
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing React import. The component uses React.memo and React.useMemo which require the React import to be present.

Copilot generated this review using guidance from repository custom instructions.

import {Flex} from '@gravity-ui/uikit';
import {Link, useLocation} from 'react-router-dom';

Expand All @@ -11,7 +13,7 @@ import type {
} from '../../../../../store/reducers/tenants/utils';
import {cn} from '../../../../../utils/cn';
import {SHOW_NETWORK_UTILIZATION} from '../../../../../utils/constants';
import {useSetting, useTypedSelector} from '../../../../../utils/hooks';
import {useSetting} from '../../../../../utils/hooks';
import {calculateMetricAggregates} from '../../../../../utils/metrics';
import {
formatCoresLegend,
Expand All @@ -22,6 +24,8 @@ import {TenantTabsGroups, getTenantPath} from '../../../TenantPages';
import {TabCard} from '../TabCard/TabCard';
import i18n from '../i18n';

import {ServerlessPlaceholderTabs} from './ServerlessPlaceholderTabs';

import './MetricsTabs.scss';

const b = cn('tenant-metrics-tabs');
Expand All @@ -33,6 +37,8 @@ interface MetricsTabsProps {
tabletStorageStats?: TenantStorageStats[];
networkStats?: TenantMetricStats[];
storageGroupsCount?: number;
isServerless?: boolean;
activeTab: TenantMetricsTab;
}

export function MetricsTabs({
Expand All @@ -42,9 +48,10 @@ export function MetricsTabs({
tabletStorageStats,
networkStats,
storageGroupsCount,
isServerless,
activeTab,
}: MetricsTabsProps) {
const location = useLocation();
const {metricsTab} = useTypedSelector((state) => state.tenant);
const queryParams = parseQuery(location);

const tabLinks: Record<TenantMetricsTab, string> = {
Expand All @@ -67,27 +74,37 @@ export function MetricsTabs({
};

// Use only pools that directly indicate resources available to perform user queries
const cpuPools = (poolsCpuStats || []).filter(
(pool) => !(pool.name === 'Batch' || pool.name === 'IO'),
const cpuPools = useMemo(
() =>
(poolsCpuStats || []).filter((pool) => !(pool.name === 'Batch' || pool.name === 'IO')),
[poolsCpuStats],
);
const cpuMetrics = calculateMetricAggregates(cpuPools);
const cpuMetrics = useMemo(() => calculateMetricAggregates(cpuPools), [cpuPools]);

// Calculate storage metrics using utility
const storageStats = tabletStorageStats || blobStorageStats || [];
const storageMetrics = calculateMetricAggregates(storageStats);
const storageStats = useMemo(
() => tabletStorageStats || blobStorageStats || [],
[tabletStorageStats, blobStorageStats],
);
const storageMetrics = useMemo(() => calculateMetricAggregates(storageStats), [storageStats]);

// Calculate memory metrics using utility
const memoryMetrics = calculateMetricAggregates(memoryStats);
const memoryMetrics = useMemo(() => calculateMetricAggregates(memoryStats), [memoryStats]);

// Calculate network metrics using utility
const [showNetworkUtilization] = useSetting<boolean>(SHOW_NETWORK_UTILIZATION);
const networkMetrics = networkStats ? calculateMetricAggregates(networkStats) : null;
const networkMetrics = useMemo(
() => (networkStats ? calculateMetricAggregates(networkStats) : null),
[networkStats],
);

const cardVariant = isServerless ? 'serverless' : 'default';

return (
<Flex className={b()} alignItems="center">
<Flex className={b({serverless: Boolean(isServerless)})} alignItems="center">
<div
className={b('link-container', {
active: metricsTab === TENANT_METRICS_TABS_IDS.cpu,
active: activeTab === TENANT_METRICS_TABS_IDS.cpu,
})}
>
<Link to={tabLinks.cpu} className={b('link')}>
Expand All @@ -96,64 +113,80 @@ export function MetricsTabs({
value={cpuMetrics.totalUsed}
limit={cpuMetrics.totalLimit}
legendFormatter={formatCoresLegend}
active={metricsTab === TENANT_METRICS_TABS_IDS.cpu}
active={activeTab === TENANT_METRICS_TABS_IDS.cpu}
helpText={i18n('context_cpu-description')}
variant={cardVariant}
subtitle={isServerless ? i18n('serverless.autoscaled') : undefined}
/>
</Link>
</div>
<div
className={b('link-container', {
active: metricsTab === TENANT_METRICS_TABS_IDS.storage,
active: activeTab === TENANT_METRICS_TABS_IDS.storage,
})}
>
<Link to={tabLinks.storage} className={b('link')}>
<TabCard
text={
storageGroupsCount === undefined
? i18n('cards.storage-label')
: i18n('context_storage-groups', {count: storageGroupsCount})
}
text={i18n('cards.storage-label')}
value={storageMetrics.totalUsed}
limit={storageMetrics.totalLimit}
legendFormatter={formatStorageLegend}
active={metricsTab === TENANT_METRICS_TABS_IDS.storage}
active={activeTab === TENANT_METRICS_TABS_IDS.storage}
helpText={i18n('context_storage-description')}
variant={cardVariant}
subtitle={
isServerless && storageMetrics.totalLimit
? i18n('serverless.storage-subtitle', {
groups: String(storageGroupsCount ?? 0),
legend: formatStorageLegend({
value: storageMetrics.totalUsed,
capacity: storageMetrics.totalLimit,
}),
})
: undefined
}
/>
</Link>
</div>
<div
className={b('link-container', {
active: metricsTab === TENANT_METRICS_TABS_IDS.memory,
})}
>
<Link to={tabLinks.memory} className={b('link')}>
<TabCard
text={i18n('context_memory-used')}
value={memoryMetrics.totalUsed}
limit={memoryMetrics.totalLimit}
legendFormatter={formatStorageLegend}
active={metricsTab === TENANT_METRICS_TABS_IDS.memory}
helpText={i18n('context_memory-description')}
/>
</Link>
</div>
{showNetworkUtilization && networkStats && networkMetrics && (
<div
className={b('link-container', {
active: metricsTab === TENANT_METRICS_TABS_IDS.network,
})}
>
<Link to={tabLinks.network} className={b('link')}>
<TabCard
text={i18n('context_network-usage')}
value={networkMetrics.totalUsed}
limit={networkMetrics.totalLimit}
legendFormatter={formatSpeedLegend}
active={metricsTab === TENANT_METRICS_TABS_IDS.network}
helpText={i18n('context_network-description')}
/>
</Link>
</div>
{isServerless ? (
<ServerlessPlaceholderTabs />
) : (
<>
<div
className={b('link-container', {
active: activeTab === TENANT_METRICS_TABS_IDS.memory,
})}
>
<Link to={tabLinks.memory} className={b('link')}>
<TabCard
text={i18n('context_memory-used')}
value={memoryMetrics.totalUsed}
limit={memoryMetrics.totalLimit}
legendFormatter={formatStorageLegend}
active={activeTab === TENANT_METRICS_TABS_IDS.memory}
helpText={i18n('context_memory-description')}
/>
</Link>
</div>
{showNetworkUtilization && networkStats && networkMetrics && (
<div
className={b('link-container', {
active: activeTab === TENANT_METRICS_TABS_IDS.network,
})}
>
<Link to={tabLinks.network} className={b('link')}>
<TabCard
text={i18n('context_network-usage')}
value={networkMetrics.totalUsed}
limit={networkMetrics.totalLimit}
legendFormatter={formatSpeedLegend}
active={activeTab === TENANT_METRICS_TABS_IDS.network}
helpText={i18n('context_network-description')}
/>
</Link>
</div>
)}
</>
)}
</Flex>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.tenant-metrics-tabs_serverless {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bem notation doesn't allow modifiers as top level classes. Let's move this to MetricsTabs.scss

.tenant-metrics-tabs__link-container_placeholder {
pointer-events: none;

.tenant-tab-card__card-container {
opacity: 0;
}
}
}
Loading
Loading