diff --git a/src/@types/parseable/api/stream.ts b/src/@types/parseable/api/stream.ts index 908746ff..4aab3701 100644 --- a/src/@types/parseable/api/stream.ts +++ b/src/@types/parseable/api/stream.ts @@ -11,17 +11,17 @@ export type LogStreamStat = { ingestion: { count: number; format: string; - size: string; + size: number; lifetime_count: number; - lifetime_size: string; + lifetime_size: number; deleted_count: number; - deleted_size: string; + deleted_size: number; }; storage: { format: string; - size: string; - lifetime_size: string; - deleted_size: string; + size: number; + lifetime_size: number; + deleted_size: number; }; stream: string; time: string; diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index 207d8290..1c60de48 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -225,16 +225,8 @@ const BigNumber = (props: { label: string; value: any; color?: string }) => { ); }; -const bytesStringToInteger = (str: string) => { - if (!str || typeof str !== 'string') return null; - - const strChuncks = str?.split(' '); - return Array.isArray(strChuncks) && !isNaN(Number(strChuncks[0])) ? parseInt(strChuncks[0]) : null; -}; - const sanitizeBytes = (str: any) => { - const size = bytesStringToInteger(str); - return size ? formatBytes(size) : '–'; + return formatBytes(str) || '–'; }; type StreamInfoProps = { diff --git a/src/pages/Stream/Views/Manage/Stats.tsx b/src/pages/Stream/Views/Manage/Stats.tsx index c79401d5..19dfdcd7 100644 --- a/src/pages/Stream/Views/Manage/Stats.tsx +++ b/src/pages/Stream/Views/Manage/Stats.tsx @@ -2,7 +2,7 @@ import { Loader, Stack, Text } from '@mantine/core'; import classes from '../../styles/Management.module.css'; import { useStreamStore } from '../../providers/StreamProvider'; import _ from 'lodash'; -import { calcCompressionRate, sanitizeBytes, sanitizeEventsCount } from '@/utils/formatBytes'; +import { calcCompressionRate, formatBytes, HumanizeNumber } from '@/utils/formatBytes'; import { IconArrowDown } from '@tabler/icons-react'; import ErrorView from './ErrorView'; @@ -41,9 +41,9 @@ const StatsTableHeaderRow = () => { }; const defaultEventCountData = { - count: '-', - lifetime_count: '-', - deleted_count: '-', + count: 0, + lifetime_count: 0, + deleted_count: 0, }; const EventsCountRow = () => { @@ -60,17 +60,17 @@ const EventsCountRow = () => { - {sanitizeEventsCount(eventsData.count)} + {HumanizeNumber(eventsData.count)} - {sanitizeEventsCount(eventsData.lifetime_count)} + {HumanizeNumber(eventsData.lifetime_count)} - {sanitizeEventsCount(eventsData.deleted_count)} + {HumanizeNumber(eventsData.deleted_count)} @@ -78,9 +78,9 @@ const EventsCountRow = () => { }; const defaultIngestedSizeData = { - size: '-', - lifetime_size: '-', - deleted_size: '-', + size: 0, + lifetime_size: 0, + deleted_size: 0, }; const IngestedSizeRow = () => { @@ -97,17 +97,17 @@ const IngestedSizeRow = () => { - {sanitizeBytes(ingestionData.size)} + {formatBytes(ingestionData.size)} - {sanitizeBytes(ingestionData.lifetime_size)} + {formatBytes(ingestionData.lifetime_size)} - {sanitizeBytes(ingestionData.deleted_size)} + {formatBytes(ingestionData.deleted_size)} @@ -115,9 +115,9 @@ const IngestedSizeRow = () => { }; const defaultStorageData = { - size: '-', - lifetime_size: '-', - deleted_size: '-', + size: 0, + lifetime_size: 0, + deleted_size: 0, }; const StorageSizeRow = () => { @@ -138,7 +138,7 @@ const StorageSizeRow = () => { - {sanitizeBytes(storageData.size)} + {formatBytes(storageData.size)} { - {sanitizeBytes(storageData.lifetime_size)} + {formatBytes(storageData.lifetime_size)} - {sanitizeBytes(storageData.deleted_size)} + {formatBytes(storageData.deleted_size)} diff --git a/src/pages/Systems/StorageSection.tsx b/src/pages/Systems/StorageSection.tsx index 03c973f2..71dd0e63 100644 --- a/src/pages/Systems/StorageSection.tsx +++ b/src/pages/Systems/StorageSection.tsx @@ -147,20 +147,20 @@ const StorageSection = () => { }; const makeOverallStorageSectionProps = (record: IngestorQueryRecord | null) => { - const storageSize = formatBytes(_.get(record, 'parseable_storage_size_data', 0)); - const lifetimeStorageSize = formatBytes(_.get(record, 'parseable_lifetime_storage_size_data', 0)); - const deletedStorageSize = formatBytes(_.get(record, 'parseable_deleted_storage_size_data', 0)); - const ingestedSize = formatBytes(_.get(record, 'parseable_events_ingested_size', 0)); - const lifetimeIngestedSize = formatBytes(_.get(record, 'parseable_lifetime_events_ingested_size', 0)); + const storageSize = _.get(record, 'parseable_storage_size_data', 0); + const lifetimeStorageSize = _.get(record, 'parseable_lifetime_storage_size.data', 0); + const deletedStorageSize = _.get(record, 'parseable_deleted_storage_size.data', 0); + const ingestedSize = _.get(record, 'parseable_events_ingested_size', 0); + const lifetimeIngestedSize = _.get(record, 'parseable_lifetime_events_ingested_size', 0); const lifetimeCompressionRate = calcCompressionRate(lifetimeStorageSize, lifetimeIngestedSize); const activeCompressionRate = calcCompressionRate(storageSize, ingestedSize); return { - storageSize, - lifetimeIngestedSize, - lifetimeStorageSize, - deletedStorageSize, - ingestedSize, + storageSize: formatBytes(storageSize), + lifetimeIngestedSize: formatBytes(lifetimeIngestedSize), + lifetimeStorageSize: formatBytes(lifetimeStorageSize), + deletedStorageSize: formatBytes(deletedStorageSize), + ingestedSize: formatBytes(ingestedSize), lifetimeCompressionRate, activeCompressionRate, }; diff --git a/src/utils/formatBytes.ts b/src/utils/formatBytes.ts index 177ab8e9..154206e4 100644 --- a/src/utils/formatBytes.ts +++ b/src/utils/formatBytes.ts @@ -47,17 +47,12 @@ export const sanitizeBytes = (str: any) => { return size ? formatBytes(size) : '0 bytes'; }; -export const calcCompressionRate = (storageSize: string, ingestionSize: string) => { - const parsedStorageSize = bytesStringToInteger(storageSize); - const parsedIngestionSize = bytesStringToInteger(ingestionSize); +export const calcCompressionRate = (storageSize: number, ingestionSize: number): string => { + if (ingestionSize === 0) return '0%'; - if (parsedIngestionSize === null || parsedStorageSize === null) return '–'; - - if (parsedIngestionSize === 0) return '0%'; - - const rate = 100 - (parsedStorageSize / parsedIngestionSize) * 100; + const rate = 100 - (storageSize / ingestionSize) * 100; if (rate <= 0) return '0%'; - return `${rate.toPrecision(4)}%`; + return `${rate.toFixed(2)}%`; };