Skip to content

Commit 31dcf49

Browse files
committed
Stats response changes
1 parent 1241439 commit 31dcf49

File tree

5 files changed

+35
-48
lines changed

5 files changed

+35
-48
lines changed

src/@types/parseable/api/stream.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ export type LogStreamStat = {
1111
ingestion: {
1212
count: number;
1313
format: string;
14-
size: string;
14+
size: number;
1515
lifetime_count: number;
16-
lifetime_size: string;
16+
lifetime_size: number;
1717
deleted_count: number;
18-
deleted_size: string;
18+
deleted_size: number;
1919
};
2020
storage: {
2121
format: string;
22-
size: string;
23-
lifetime_size: string;
24-
deleted_size: string;
22+
size: number;
23+
lifetime_size: number;
24+
deleted_size: number;
2525
};
2626
stream: string;
2727
time: string;

src/pages/Home/index.tsx

+1-9
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,8 @@ const BigNumber = (props: { label: string; value: any; color?: string }) => {
225225
);
226226
};
227227

228-
const bytesStringToInteger = (str: string) => {
229-
if (!str || typeof str !== 'string') return null;
230-
231-
const strChuncks = str?.split(' ');
232-
return Array.isArray(strChuncks) && !isNaN(Number(strChuncks[0])) ? parseInt(strChuncks[0]) : null;
233-
};
234-
235228
const sanitizeBytes = (str: any) => {
236-
const size = bytesStringToInteger(str);
237-
return size ? formatBytes(size) : '–';
229+
return formatBytes(str) || '–';
238230
};
239231

240232
type StreamInfoProps = {

src/pages/Stream/Views/Manage/Stats.tsx

+19-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Loader, Stack, Text } from '@mantine/core';
22
import classes from '../../styles/Management.module.css';
33
import { useStreamStore } from '../../providers/StreamProvider';
44
import _ from 'lodash';
5-
import { calcCompressionRate, sanitizeBytes, sanitizeEventsCount } from '@/utils/formatBytes';
5+
import { calcCompressionRate, formatBytes, HumanizeNumber } from '@/utils/formatBytes';
66
import { IconArrowDown } from '@tabler/icons-react';
77
import ErrorView from './ErrorView';
88

@@ -41,9 +41,9 @@ const StatsTableHeaderRow = () => {
4141
};
4242

4343
const defaultEventCountData = {
44-
count: '-',
45-
lifetime_count: '-',
46-
deleted_count: '-',
44+
count: 0,
45+
lifetime_count: 0,
46+
deleted_count: 0,
4747
};
4848

4949
const EventsCountRow = () => {
@@ -60,27 +60,27 @@ const EventsCountRow = () => {
6060
</Stack>
6161
<Stack w={bigNoWidth}>
6262
<Text ta="center" className={classes.bigNoText}>
63-
{sanitizeEventsCount(eventsData.count)}
63+
{HumanizeNumber(eventsData.count)}
6464
</Text>
6565
</Stack>
6666
<Stack w={bigNoWidth}>
6767
<Text ta="center" className={classes.bigNoText}>
68-
{sanitizeEventsCount(eventsData.lifetime_count)}
68+
{HumanizeNumber(eventsData.lifetime_count)}
6969
</Text>
7070
</Stack>
7171
<Stack w={bigNoWidth}>
7272
<Text ta="center" className={classes.bigNoText}>
73-
{sanitizeEventsCount(eventsData.deleted_count)}
73+
{HumanizeNumber(eventsData.deleted_count)}
7474
</Text>
7575
</Stack>
7676
</Stack>
7777
);
7878
};
7979

8080
const defaultIngestedSizeData = {
81-
size: '-',
82-
lifetime_size: '-',
83-
deleted_size: '-',
81+
size: 0,
82+
lifetime_size: 0,
83+
deleted_size: 0,
8484
};
8585

8686
const IngestedSizeRow = () => {
@@ -97,27 +97,27 @@ const IngestedSizeRow = () => {
9797
</Stack>
9898
<Stack w={bigNoWidth}>
9999
<Text ta="center" className={classes.bigNoText}>
100-
{sanitizeBytes(ingestionData.size)}
100+
{formatBytes(ingestionData.size)}
101101
</Text>
102102
</Stack>
103103
<Stack w={bigNoWidth}>
104104
<Text ta="center" className={classes.bigNoText}>
105-
{sanitizeBytes(ingestionData.lifetime_size)}
105+
{formatBytes(ingestionData.lifetime_size)}
106106
</Text>
107107
</Stack>
108108
<Stack w={bigNoWidth}>
109109
<Text ta="center" className={classes.bigNoText}>
110-
{sanitizeBytes(ingestionData.deleted_size)}
110+
{formatBytes(ingestionData.deleted_size)}
111111
</Text>
112112
</Stack>
113113
</Stack>
114114
);
115115
};
116116

117117
const defaultStorageData = {
118-
size: '-',
119-
lifetime_size: '-',
120-
deleted_size: '-',
118+
size: 0,
119+
lifetime_size: 0,
120+
deleted_size: 0,
121121
};
122122

123123
const StorageSizeRow = () => {
@@ -138,7 +138,7 @@ const StorageSizeRow = () => {
138138
</Stack>
139139
<Stack w={bigNoWidth} gap={0} style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'center' }}>
140140
<Text ta="center" className={classes.bigNoText}>
141-
{sanitizeBytes(storageData.size)}
141+
{formatBytes(storageData.size)}
142142
</Text>
143143
<Stack
144144
gap={0}
@@ -156,12 +156,12 @@ const StorageSizeRow = () => {
156156
</Stack>
157157
<Stack w={bigNoWidth}>
158158
<Text ta="center" className={classes.bigNoText}>
159-
{sanitizeBytes(storageData.lifetime_size)}
159+
{formatBytes(storageData.lifetime_size)}
160160
</Text>
161161
</Stack>
162162
<Stack w={bigNoWidth}>
163163
<Text ta="center" className={classes.bigNoText}>
164-
{sanitizeBytes(storageData.deleted_size)}
164+
{formatBytes(storageData.deleted_size)}
165165
</Text>
166166
</Stack>
167167
</Stack>

src/pages/Systems/StorageSection.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ const StorageSection = () => {
147147
};
148148

149149
const makeOverallStorageSectionProps = (record: IngestorQueryRecord | null) => {
150-
const storageSize = formatBytes(_.get(record, 'parseable_storage_size_data', 0));
151-
const lifetimeStorageSize = formatBytes(_.get(record, 'parseable_lifetime_storage_size_data', 0));
152-
const deletedStorageSize = formatBytes(_.get(record, 'parseable_deleted_storage_size_data', 0));
153-
const ingestedSize = formatBytes(_.get(record, 'parseable_events_ingested_size', 0));
154-
const lifetimeIngestedSize = formatBytes(_.get(record, 'parseable_lifetime_events_ingested_size', 0));
150+
const storageSize = _.get(record, 'parseable_storage_size_data', 0);
151+
const lifetimeStorageSize = _.get(record, 'parseable_lifetime_storage_size.data', 0);
152+
const deletedStorageSize = _.get(record, 'parseable_deleted_storage_size.data', 0);
153+
const ingestedSize = _.get(record, 'parseable_events_ingested_size', 0);
154+
const lifetimeIngestedSize = _.get(record, 'parseable_lifetime_events_ingested_size', 0);
155155
const lifetimeCompressionRate = calcCompressionRate(lifetimeStorageSize, lifetimeIngestedSize);
156156
const activeCompressionRate = calcCompressionRate(storageSize, ingestedSize);
157157

src/utils/formatBytes.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,12 @@ export const sanitizeBytes = (str: any) => {
4747
return size ? formatBytes(size) : '0 bytes';
4848
};
4949

50-
export const calcCompressionRate = (storageSize: string, ingestionSize: string) => {
51-
const parsedStorageSize = bytesStringToInteger(storageSize);
52-
const parsedIngestionSize = bytesStringToInteger(ingestionSize);
50+
export const calcCompressionRate = (storageSize: number, ingestionSize: number): string => {
51+
if (ingestionSize === 0) return '0%';
5352

54-
if (parsedIngestionSize === null || parsedStorageSize === null) return '–';
55-
56-
if (parsedIngestionSize === 0) return '0%';
57-
58-
const rate = 100 - (parsedStorageSize / parsedIngestionSize) * 100;
53+
const rate = 100 - (storageSize / ingestionSize) * 100;
5954

6055
if (rate <= 0) return '0%';
6156

62-
return `${rate.toPrecision(4)}%`;
57+
return `${rate.toFixed(2)}%`;
6358
};

0 commit comments

Comments
 (0)