import {ResponseError} from '../../../../../components/Errors/ResponseError'; import type {InfoViewerItem} from '../../../../../components/InfoViewer'; import {InfoViewer} from '../../../../../components/InfoViewer'; import {LabelWithPopover} from '../../../../../components/LabelWithPopover'; import {LagPopoverContent} from '../../../../../components/LagPopoverContent'; import {Loader} from '../../../../../components/Loader'; import {useClusterWithProxy} from '../../../../../store/reducers/cluster/cluster'; import {selectPreparedTopicStats, topicApi} from '../../../../../store/reducers/topic/topic'; import type {IPreparedTopicStats} from '../../../../../types/store/topic'; import {cn} from '../../../../../utils/cn'; import {formatBps, formatBytes} from '../../../../../utils/dataFormatters/dataFormatters'; import {useAutoRefreshInterval, useTypedSelector} from '../../../../../utils/hooks'; import {formatDurationToShortTimeFormat} from '../../../../../utils/timeParsers'; import i18n from './i18n'; import './TopicStats.scss'; const b = cn('ydb-overview-topic-stats'); const prepareTopicInfo = (data: IPreparedTopicStats): Array => { return [ {label: 'Store size', value: formatBytes(data.storeSize)}, { label: ( } /> ), value: formatDurationToShortTimeFormat(data.partitionsIdleTime), }, { label: ( } /> ), value: formatDurationToShortTimeFormat(data.partitionsWriteLag), }, ]; }; const prepareBytesWrittenInfo = (data: IPreparedTopicStats): Array => { const writeSpeed = data.writeSpeed; return [ { label: 'per minute', value: formatBps(writeSpeed.perMinute), }, { label: 'per hour', value: formatBps(writeSpeed.perHour), }, { label: 'per day', value: formatBps(writeSpeed.perDay), }, ]; }; interface TopicStatsProps { path: string; database: string; databaseFullPath: string; } export const TopicStats = ({path, database, databaseFullPath}: TopicStatsProps) => { const useMetaProxy = useClusterWithProxy(); const [autoRefreshInterval] = useAutoRefreshInterval(); const {currentData, isFetching, error} = topicApi.useGetTopicQuery( {path, database, databaseFullPath, useMetaProxy}, {pollingInterval: autoRefreshInterval}, ); const loading = isFetching && currentData === undefined; const data = useTypedSelector((state) => selectPreparedTopicStats(state, path, database, databaseFullPath, useMetaProxy), ); if (loading) { return (
); } // If there is at least some empty data object // we initialize its fields with zero values // so no data at all is considered to be error as well const errorContent = error || !data ? : null; return (
{errorContent} {data ? (
{i18n('title_stats')}
{i18n('title_average-write-speed')}
) : null}
); };