Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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,
databaseType,
});
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
86 changes: 59 additions & 27 deletions src/containers/Tenant/Diagnostics/DiagnosticsPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {StringParam, useQueryParams} from 'use-query-params';
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../store/reducers/tenant/constants';
import type {TenantDiagnosticsTab} from '../../../store/reducers/tenant/types';
import {EPathSubType, EPathType} from '../../../types/api/schema';
import type {ETenantType} from '../../../types/api/tenant';
import type {TenantQuery} from '../TenantPages';
import {TenantTabsGroups, getTenantPath} from '../TenantPages';
import {isDatabaseEntityType, isTopicEntityType} from '../utils/schema';
Expand All @@ -14,6 +15,16 @@ type Page = {
title: string;
};

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

const overview = {
id: TENANT_DIAGNOSTICS_TABS_IDS.overview,
title: 'Info',
Expand Down Expand Up @@ -118,6 +129,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 +189,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(databaseType?: ETenantType) {
return databaseType === 'Serverless' ? 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?.databaseType) : 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
@@ -0,0 +1,89 @@
import {Link} from 'react-router-dom';

import {TENANT_METRICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
import type {TenantMetricsTab} from '../../../../../store/reducers/tenant/types';
import type {ETenantType} from '../../../../../types/api/tenant';
import {cn} from '../../../../../utils/cn';
import {
formatCoresLegend,
formatStorageLegend,
} from '../../../../../utils/metrics/formatMetricLegend';
import {TabCard} from '../TabCard/TabCard';
import i18n from '../i18n';

const b = cn('tenant-metrics-tabs');

interface CommonMetricsTabsProps {
activeTab: TenantMetricsTab;
tabLinks: Record<TenantMetricsTab, string>;
cpu: {totalUsed: number; totalLimit: number};
storage: {totalUsed: number; totalLimit: number};
storageGroupsCount?: number;
databaseType?: ETenantType;
}

export function CommonMetricsTabs({
activeTab,
tabLinks,
cpu,
storage,
storageGroupsCount,
databaseType,
}: CommonMetricsTabsProps) {
const isServerless = databaseType === 'Serverless';

return (
<>
<div
className={b('link-container', {
active: activeTab === TENANT_METRICS_TABS_IDS.cpu,
})}
>
<Link to={tabLinks.cpu} className={b('link')}>
<TabCard
text={i18n('context_cpu-load')}
value={cpu.totalUsed}
limit={cpu.totalLimit}
legendFormatter={formatCoresLegend}
active={activeTab === TENANT_METRICS_TABS_IDS.cpu}
helpText={i18n('context_cpu-description')}
databaseType={databaseType}
subtitle={isServerless ? i18n('context_serverless-autoscaled') : undefined}
/>
</Link>
</div>
<div
className={b('link-container', {
active: activeTab === TENANT_METRICS_TABS_IDS.storage,
})}
>
<Link to={tabLinks.storage} className={b('link')}>
<TabCard
text={
storageGroupsCount === undefined || isServerless
? i18n('cards.storage-label')
: i18n('context_storage-groups', {count: storageGroupsCount})
}
value={storage.totalUsed}
limit={storage.totalLimit}
legendFormatter={formatStorageLegend}
active={activeTab === TENANT_METRICS_TABS_IDS.storage}
helpText={i18n('context_storage-description')}
databaseType={databaseType}
subtitle={
isServerless && storage.totalLimit
? i18n('context_serverless-storage-subtitle', {
groups: String(storageGroupsCount ?? 0),
legend: formatStorageLegend({
value: storage.totalUsed,
capacity: storage.totalLimit,
}),
})
: undefined
}
/>
</Link>
</div>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {Link} from 'react-router-dom';

import {TENANT_METRICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
import type {TenantMetricsTab} from '../../../../../store/reducers/tenant/types';
import {cn} from '../../../../../utils/cn';
import {
formatSpeedLegend,
formatStorageLegend,
} from '../../../../../utils/metrics/formatMetricLegend';
import {TabCard} from '../TabCard/TabCard';
import i18n from '../i18n';

const b = cn('tenant-metrics-tabs');

interface DedicatedMetricsTabsProps {
activeTab: TenantMetricsTab;
tabLinks: Record<TenantMetricsTab, string>;
memory: {totalUsed: number; totalLimit: number};
network: {totalUsed: number; totalLimit: number} | null;
showNetwork: boolean;
}

export function DedicatedMetricsTabs({
activeTab,
tabLinks,
memory,
network,
showNetwork,
}: DedicatedMetricsTabsProps) {
return (
<>
<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={memory.totalUsed}
limit={memory.totalLimit}
legendFormatter={formatStorageLegend}
active={activeTab === TENANT_METRICS_TABS_IDS.memory}
helpText={i18n('context_memory-description')}
databaseType="Dedicated"
/>
</Link>
</div>
{showNetwork && network && (
<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={network.totalUsed}
limit={network.totalLimit}
legendFormatter={formatSpeedLegend}
active={activeTab === TENANT_METRICS_TABS_IDS.network}
helpText={i18n('context_network-description')}
databaseType="Dedicated"
/>
</Link>
</div>
)}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,13 @@
padding-right: 0;
}
}

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

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