Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit c1830f8

Browse files
authored
feat: add hot tier config to manage stream page (#286)
1 parent 5aa2505 commit c1830f8

File tree

8 files changed

+337
-47
lines changed

8 files changed

+337
-47
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,14 @@ export type StreamInfo = {
4444
}
4545

4646
export type LogStreamRetention = Array<action>;
47+
48+
export type HotTierConfig = {
49+
size: string;
50+
used_size: string;
51+
available_size: string;
52+
oldest_date_time_entry: string;
53+
} | {};
54+
55+
export type UpdateHotTierConfig = {
56+
size: string;
57+
}

src/api/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const LOG_STREAMS_STATS_URL = (streamName: string) => `${LOG_STREAM_LIST_
1414
export const LOG_STREAMS_INFO_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/info`;
1515
export const DELETE_STREAMS_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}`;
1616
export const CREATE_STREAM_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}`;
17+
export const LOG_STREAM_HOT_TIER = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/hottier`;
1718

1819
// About Parsable Instance
1920
export const ABOUT_URL = `${API_V1}/about`;

src/api/logStream.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import {
1212
LIST_SAVED_FILTERS_URL,
1313
UPDATE_SAVED_FILTERS_URL,
1414
DELETE_SAVED_FILTERS_URL,
15-
CREATE_SAVED_FILTERS_URL
15+
CREATE_SAVED_FILTERS_URL,
16+
LOG_STREAM_HOT_TIER
1617
} from './constants';
17-
import { LogStreamData, LogStreamSchemaData } from '@/@types/parseable/api/stream';
18+
import { HotTierConfig, LogStreamData, LogStreamSchemaData } from '@/@types/parseable/api/stream';
1819

1920
export const getLogStreamList = () => {
2021
return Axios().get<LogStreamData>(LOG_STREAM_LIST_URL);
@@ -75,3 +76,15 @@ export const updateLogStream = (streamName: string, data: any, headers: any) =>
7576
export const getLogStreamInfo = (streamName: string) => {
7677
return Axios().get(LOG_STREAMS_INFO_URL(streamName));
7778
};
79+
80+
export const getHotTierInfo = (streamName: string) => {
81+
return Axios().get<HotTierConfig>(LOG_STREAM_HOT_TIER(streamName));
82+
}
83+
84+
export const updateHotTierInfo = (streamName: string, data: any) => {
85+
return Axios().put(LOG_STREAM_HOT_TIER(streamName), data);
86+
};
87+
88+
export const deleteHotTierInfo = (streamName: string) => {
89+
return Axios().delete(LOG_STREAM_HOT_TIER(streamName));
90+
};

src/hooks/useHotTier.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { useMutation, useQuery } from 'react-query';
2+
import { notifyError, notifySuccess } from '@/utils/notification';
3+
import { useStreamStore, streamStoreReducers } from '@/pages/Stream/providers/StreamProvider';
4+
import { deleteHotTierInfo, getHotTierInfo, updateHotTierInfo } from '@/api/logStream';
5+
import { AxiosError, isAxiosError } from 'axios';
6+
7+
const { setHotTier } = streamStoreReducers;
8+
9+
export const useHotTier = (streamName: string) => {
10+
const [, setStreamStore] = useStreamStore((_store) => null);
11+
const {
12+
refetch: refetchHotTierInfo,
13+
isError: getHotTierInfoError,
14+
isLoading: getHotTierInfoLoading,
15+
} = useQuery(['fetch-hot-tier-info', streamName], () => getHotTierInfo(streamName), {
16+
retry: false,
17+
enabled: streamName !== '',
18+
refetchOnWindowFocus: false,
19+
onSuccess: (data) => {
20+
setStreamStore((store) => setHotTier(store, data.data));
21+
},
22+
onError: () => setStreamStore((store) => setHotTier(store, {})),
23+
});
24+
25+
const { mutate: updateHotTier, isLoading: isUpdating } = useMutation(
26+
({ size }: { size: string; onSuccess?: () => void }) => updateHotTierInfo(streamName, { size }),
27+
{
28+
onSuccess: (_data, variables) => {
29+
notifySuccess({ message: `Hot tier size modified successfully` });
30+
refetchHotTierInfo();
31+
variables.onSuccess && variables.onSuccess();
32+
},
33+
onError: (data: AxiosError) => {
34+
if (isAxiosError(data) && data.response) {
35+
const error = data.response?.data as string;
36+
typeof error === 'string' && notifyError({ message: error });
37+
} else if (data.message && typeof data.message === 'string') {
38+
notifyError({ message: data.message, autoClose: 5000 });
39+
}
40+
},
41+
},
42+
);
43+
44+
const { mutate: deleteHotTier, isLoading: isDeleting } = useMutation(
45+
(_opts: { onSuccess?: () => void }) => deleteHotTierInfo(streamName),
46+
{
47+
onSuccess: (_data, variables) => {
48+
notifySuccess({ message: `Hot tier config deleted successfully` });
49+
refetchHotTierInfo();
50+
variables.onSuccess && variables.onSuccess();
51+
},
52+
onError: (data: AxiosError) => {
53+
if (isAxiosError(data) && data.response) {
54+
const error = data.response?.data as string;
55+
typeof error === 'string' && notifyError({ message: error });
56+
} else if (data.message && typeof data.message === 'string') {
57+
notifyError({ message: data.message, autoClose: 5000 });
58+
}
59+
},
60+
},
61+
);
62+
63+
return {
64+
getHotTierInfoError,
65+
getHotTierInfoLoading,
66+
updateHotTier,
67+
deleteHotTier,
68+
isDeleting,
69+
isUpdating,
70+
};
71+
};

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ import { useLogStreamStats } from '@/hooks/useLogStreamStats';
88
import Info from './Info';
99
import DeleteStreamModal from '../../components/DeleteStreamModal';
1010
import { useRetentionQuery } from '@/hooks/useRetentionEditor';
11-
import { useCacheToggle } from '@/hooks/useCacheToggle';
1211
import { useGetStreamInfo } from '@/hooks/useGetStreamInfo';
12+
import { useHotTier } from '@/hooks/useHotTier';
1313

1414
const Management = (props: { schemaLoading: boolean }) => {
1515
const [currentStream] = useAppStore((store) => store.currentStream);
1616
const [instanceConfig] = useAppStore((store) => store.instanceConfig);
1717
const getStreamAlertsConfig = useAlertsQuery(currentStream || '');
1818
const getStreamStats = useLogStreamStats(currentStream || '');
1919
const getRetentionConfig = useRetentionQuery(currentStream || '');
20-
const { getCacheError, updateCacheStatus } = useCacheToggle(currentStream || '');
2120
const getStreamInfo = useGetStreamInfo(currentStream || '');
21+
const hotTierFetch = useHotTier(currentStream || '')
2222

2323
// todo - handle loading and error states separately
2424
const isStatsLoading = getStreamStats.getLogStreamStatsDataIsLoading || getStreamStats.getLogStreamStatsDataIsError;
2525
const isAlertsLoading = getStreamAlertsConfig.isError || getStreamAlertsConfig.isLoading;
26-
const isSettingsLoading = getRetentionConfig.getLogRetentionIsLoading || getRetentionConfig.getLogRetentionIsError || instanceConfig === null;
26+
const isRetentionLoading = getRetentionConfig.getLogRetentionIsLoading || getRetentionConfig.getLogRetentionIsError || instanceConfig === null;
2727
const isStreamInfoLoading = getStreamInfo.getStreamInfoLoading || getStreamInfo.getStreamInfoError;
28+
const isHotTierLoading = hotTierFetch.getHotTierInfoLoading;
29+
2830
return (
2931
<Stack style={{ padding: '1rem', paddingTop: '0', height: '90%'}}>
3032
<DeleteStreamModal />
@@ -35,10 +37,12 @@ const Management = (props: { schemaLoading: boolean }) => {
3537
<Stack style={{ flexDirection: 'row', height: '57%' }} gap={24}>
3638
<Stack w="49.4%">
3739
<Settings
38-
isLoading={isSettingsLoading}
39-
getCacheError={getCacheError}
40-
updateCacheStatus={updateCacheStatus}
40+
isLoading={isHotTierLoading || isRetentionLoading}
4141
updateRetentionConfig={getRetentionConfig.updateLogStreamRetention}
42+
updateHotTierInfo={hotTierFetch.updateHotTier}
43+
deleteHotTierInfo={hotTierFetch.deleteHotTier}
44+
isDeleting={hotTierFetch.isDeleting}
45+
isUpdating={hotTierFetch.isUpdating}
4246
/>
4347
</Stack>
4448
<Alerts

0 commit comments

Comments
 (0)