-
Notifications
You must be signed in to change notification settings - Fork 17
feat: serverless database view #2836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
ca9986a
5947cad
f0b8ec9
a336c9d
9c92d12
65574d0
e78f7ec
610df88
cfb0d28
044b80e
d75bd92
bea42b4
fc7df32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| import {useMemo} from 'react'; | ||
|
||
|
|
||
| import {Flex} from '@gravity-ui/uikit'; | ||
| import {Link, useLocation} from 'react-router-dom'; | ||
|
|
||
|
|
@@ -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, | ||
|
|
@@ -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'); | ||
|
|
@@ -33,6 +37,8 @@ interface MetricsTabsProps { | |
| tabletStorageStats?: TenantStorageStats[]; | ||
| networkStats?: TenantMetricStats[]; | ||
| storageGroupsCount?: number; | ||
| isServerless?: boolean; | ||
| activeTab: TenantMetricsTab; | ||
| } | ||
|
|
||
| export function MetricsTabs({ | ||
|
|
@@ -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> = { | ||
|
|
@@ -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')), | ||
astandrik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [poolsCpuStats], | ||
| ); | ||
astandrik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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')}> | ||
|
|
@@ -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')} | ||
astandrik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| .tenant-metrics-tabs_serverless { | ||
|
||
| .tenant-metrics-tabs__link-container_placeholder { | ||
| pointer-events: none; | ||
|
|
||
| .tenant-tab-card__card-container { | ||
| opacity: 0; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.