Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/@types/parseable/api/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ export type StreamInfo = {
}

export type LogStreamRetention = Array<action>;

export type HotTierConfig = {
size: string;
used_size: string;
available_size: string;
oldest_date_time_entry: string;
} | {};

export type UpdateHotTierConfig = {
size: string;
}
1 change: 1 addition & 0 deletions src/api/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const LOG_STREAMS_STATS_URL = (streamName: string) => `${LOG_STREAM_LIST_
export const LOG_STREAMS_INFO_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/info`;
export const DELETE_STREAMS_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}`;
export const CREATE_STREAM_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}`;
export const LOG_STREAM_HOT_TIER = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/hottier`;

// About Parsable Instance
export const ABOUT_URL = `${API_V1}/about`;
Expand Down
17 changes: 15 additions & 2 deletions src/api/logStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import {
LIST_SAVED_FILTERS_URL,
UPDATE_SAVED_FILTERS_URL,
DELETE_SAVED_FILTERS_URL,
CREATE_SAVED_FILTERS_URL
CREATE_SAVED_FILTERS_URL,
LOG_STREAM_HOT_TIER
} from './constants';
import { LogStreamData, LogStreamSchemaData } from '@/@types/parseable/api/stream';
import { HotTierConfig, LogStreamData, LogStreamSchemaData } from '@/@types/parseable/api/stream';

export const getLogStreamList = () => {
return Axios().get<LogStreamData>(LOG_STREAM_LIST_URL);
Expand Down Expand Up @@ -75,3 +76,15 @@ export const updateLogStream = (streamName: string, data: any, headers: any) =>
export const getLogStreamInfo = (streamName: string) => {
return Axios().get(LOG_STREAMS_INFO_URL(streamName));
};

export const getHotTierInfo = (streamName: string) => {
return Axios().get<HotTierConfig>(LOG_STREAM_HOT_TIER(streamName));
}

export const updateHotTierInfo = (streamName: string, data: any) => {
return Axios().put(LOG_STREAM_HOT_TIER(streamName), data);
};

export const deleteHotTierInfo = (streamName: string) => {
return Axios().delete(LOG_STREAM_HOT_TIER(streamName));
};
71 changes: 71 additions & 0 deletions src/hooks/useHotTier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { useMutation, useQuery } from 'react-query';
import { notifyError, notifySuccess } from '@/utils/notification';
import { useStreamStore, streamStoreReducers } from '@/pages/Stream/providers/StreamProvider';
import { deleteHotTierInfo, getHotTierInfo, updateHotTierInfo } from '@/api/logStream';
import { AxiosError, isAxiosError } from 'axios';

const { setHotTier } = streamStoreReducers;

export const useHotTier = (streamName: string) => {
const [, setStreamStore] = useStreamStore((_store) => null);
const {
refetch: refetchHotTierInfo,
isError: getHotTierInfoError,
isLoading: getHotTierInfoLoading,
} = useQuery(['fetch-hot-tier-info', streamName], () => getHotTierInfo(streamName), {
retry: false,
enabled: streamName !== '',
refetchOnWindowFocus: false,
onSuccess: (data) => {
setStreamStore((store) => setHotTier(store, data.data));
},
onError: () => setStreamStore((store) => setHotTier(store, {})),
});

const { mutate: updateHotTier, isLoading: isUpdating } = useMutation(
({ size }: { size: string; onSuccess?: () => void }) => updateHotTierInfo(streamName, { size }),
{
onSuccess: (_data, variables) => {
notifySuccess({ message: `Hot tier size modified successfully` });
refetchHotTierInfo();
variables.onSuccess && variables.onSuccess();
},
onError: (data: AxiosError) => {
if (isAxiosError(data) && data.response) {
const error = data.response?.data as string;
typeof error === 'string' && notifyError({ message: error });
} else if (data.message && typeof data.message === 'string') {
notifyError({ message: data.message, autoClose: 5000 });
}
},
},
);

const { mutate: deleteHotTier, isLoading: isDeleting } = useMutation(
(_opts: { onSuccess?: () => void }) => deleteHotTierInfo(streamName),
{
onSuccess: (_data, variables) => {
notifySuccess({ message: `Hot tier config deleted successfully` });
refetchHotTierInfo();
variables.onSuccess && variables.onSuccess();
},
onError: (data: AxiosError) => {
if (isAxiosError(data) && data.response) {
const error = data.response?.data as string;
typeof error === 'string' && notifyError({ message: error });
} else if (data.message && typeof data.message === 'string') {
notifyError({ message: data.message, autoClose: 5000 });
}
},
},
);

return {
getHotTierInfoError,
getHotTierInfoLoading,
updateHotTier,
deleteHotTier,
isDeleting,
isUpdating,
};
};
16 changes: 10 additions & 6 deletions src/pages/Stream/Views/Manage/Management.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ import { useLogStreamStats } from '@/hooks/useLogStreamStats';
import Info from './Info';
import DeleteStreamModal from '../../components/DeleteStreamModal';
import { useRetentionQuery } from '@/hooks/useRetentionEditor';
import { useCacheToggle } from '@/hooks/useCacheToggle';
import { useGetStreamInfo } from '@/hooks/useGetStreamInfo';
import { useHotTier } from '@/hooks/useHotTier';

const Management = (props: { schemaLoading: boolean }) => {
const [currentStream] = useAppStore((store) => store.currentStream);
const [instanceConfig] = useAppStore((store) => store.instanceConfig);
const getStreamAlertsConfig = useAlertsQuery(currentStream || '');
const getStreamStats = useLogStreamStats(currentStream || '');
const getRetentionConfig = useRetentionQuery(currentStream || '');
const { getCacheError, updateCacheStatus } = useCacheToggle(currentStream || '');
const getStreamInfo = useGetStreamInfo(currentStream || '');
const hotTierFetch = useHotTier(currentStream || '')

// todo - handle loading and error states separately
const isStatsLoading = getStreamStats.getLogStreamStatsDataIsLoading || getStreamStats.getLogStreamStatsDataIsError;
const isAlertsLoading = getStreamAlertsConfig.isError || getStreamAlertsConfig.isLoading;
const isSettingsLoading = getRetentionConfig.getLogRetentionIsLoading || getRetentionConfig.getLogRetentionIsError || instanceConfig === null;
const isRetentionLoading = getRetentionConfig.getLogRetentionIsLoading || getRetentionConfig.getLogRetentionIsError || instanceConfig === null;
const isStreamInfoLoading = getStreamInfo.getStreamInfoLoading || getStreamInfo.getStreamInfoError;
const isHotTierLoading = hotTierFetch.getHotTierInfoLoading;

return (
<Stack style={{ padding: '1rem', paddingTop: '0', height: '90%'}}>
<DeleteStreamModal />
Expand All @@ -35,10 +37,12 @@ const Management = (props: { schemaLoading: boolean }) => {
<Stack style={{ flexDirection: 'row', height: '57%' }} gap={24}>
<Stack w="49.4%">
<Settings
isLoading={isSettingsLoading}
getCacheError={getCacheError}
updateCacheStatus={updateCacheStatus}
isLoading={isHotTierLoading || isRetentionLoading}
updateRetentionConfig={getRetentionConfig.updateLogStreamRetention}
updateHotTierInfo={hotTierFetch.updateHotTier}
deleteHotTierInfo={hotTierFetch.deleteHotTier}
isDeleting={hotTierFetch.isDeleting}
isUpdating={hotTierFetch.isUpdating}
/>
</Stack>
<Alerts
Expand Down
Loading