mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-06-22 03:31:46 +08:00
Fix: live tail memory (#2033)
* feat: react is updated to v18 * feat: logs card is updated
This commit is contained in:
parent
cd9768c738
commit
3632208d45
@ -80,6 +80,7 @@
|
|||||||
"react-redux": "^7.2.2",
|
"react-redux": "^7.2.2",
|
||||||
"react-router-dom": "^5.2.0",
|
"react-router-dom": "^5.2.0",
|
||||||
"react-use": "^17.3.2",
|
"react-use": "^17.3.2",
|
||||||
|
"react-virtuoso": "4.0.3",
|
||||||
"react-vis": "^1.11.7",
|
"react-vis": "^1.11.7",
|
||||||
"redux": "^4.0.5",
|
"redux": "^4.0.5",
|
||||||
"redux-thunk": "^2.3.0",
|
"redux-thunk": "^2.3.0",
|
||||||
|
@ -55,22 +55,25 @@ function LogLiveTail(): JSX.Element {
|
|||||||
|
|
||||||
const batchedEventsRef = useRef<Record<string, unknown>[]>([]);
|
const batchedEventsRef = useRef<Record<string, unknown>[]>([]);
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
const pushLiveLog = useCallback(() => {
|
||||||
const pushLiveLog = useCallback(
|
dispatch({
|
||||||
throttle(() => {
|
type: PUSH_LIVE_TAIL_EVENT,
|
||||||
dispatch({
|
payload: batchedEventsRef.current.reverse(),
|
||||||
type: PUSH_LIVE_TAIL_EVENT,
|
});
|
||||||
payload: batchedEventsRef.current.reverse(),
|
batchedEventsRef.current = [];
|
||||||
});
|
}, [dispatch]);
|
||||||
batchedEventsRef.current = [];
|
|
||||||
}, 1500),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
const batchLiveLog = (e: { data: string }): void => {
|
const pushLiveLogThrottled = useMemo(() => throttle(pushLiveLog, 1000), [
|
||||||
batchedEventsRef.current.push(JSON.parse(e.data as string) as never);
|
pushLiveLog,
|
||||||
pushLiveLog();
|
]);
|
||||||
};
|
|
||||||
|
const batchLiveLog = useCallback(
|
||||||
|
(e: { data: string }): void => {
|
||||||
|
batchedEventsRef.current.push(JSON.parse(e.data as string) as never);
|
||||||
|
pushLiveLogThrottled();
|
||||||
|
},
|
||||||
|
[pushLiveLogThrottled],
|
||||||
|
);
|
||||||
|
|
||||||
// This ref depicts thats whether the live tail is played from paused state or not.
|
// This ref depicts thats whether the live tail is played from paused state or not.
|
||||||
const liveTailSourceRef = useRef<EventSource | null>(null);
|
const liveTailSourceRef = useRef<EventSource | null>(null);
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
/* eslint-disable no-nested-ternary */
|
|
||||||
import { Typography } from 'antd';
|
import { Typography } from 'antd';
|
||||||
import LogItem from 'components/Logs/LogItem';
|
import LogItem from 'components/Logs/LogItem';
|
||||||
import Spinner from 'components/Spinner';
|
import Spinner from 'components/Spinner';
|
||||||
import map from 'lodash-es/map';
|
import React, { memo, useCallback, useMemo } from 'react';
|
||||||
import React, { memo } from 'react';
|
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
|
import { Virtuoso } from 'react-virtuoso';
|
||||||
import { AppState } from 'store/reducers';
|
import { AppState } from 'store/reducers';
|
||||||
import { ILogsReducer } from 'types/reducer/logs';
|
import { ILogsReducer } from 'types/reducer/logs';
|
||||||
|
|
||||||
@ -15,6 +14,24 @@ function LogsTable(): JSX.Element {
|
|||||||
(state) => state.logs,
|
(state) => state.logs,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isLiveTail = useMemo(() => logs.length === 0 && liveTail === 'PLAYING', [
|
||||||
|
logs?.length,
|
||||||
|
liveTail,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const isNoLogs = useMemo(() => logs.length === 0 && liveTail === 'STOPPED', [
|
||||||
|
logs?.length,
|
||||||
|
liveTail,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const getItemContent = useCallback(
|
||||||
|
(index: number): JSX.Element => {
|
||||||
|
const log = logs[index];
|
||||||
|
return <LogItem key={log.id} logData={log} />;
|
||||||
|
},
|
||||||
|
[logs],
|
||||||
|
);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <Spinner height={20} tip="Getting Logs" />;
|
return <Spinner height={20} tip="Getting Logs" />;
|
||||||
}
|
}
|
||||||
@ -24,13 +41,15 @@ function LogsTable(): JSX.Element {
|
|||||||
<Heading>
|
<Heading>
|
||||||
<Typography.Text>Event</Typography.Text>
|
<Typography.Text>Event</Typography.Text>
|
||||||
</Heading>
|
</Heading>
|
||||||
{Array.isArray(logs) && logs.length > 0 ? (
|
{isLiveTail && <Typography>Getting live logs...</Typography>}
|
||||||
map(logs, (log) => <LogItem key={log.id} logData={log} />)
|
|
||||||
) : liveTail === 'PLAYING' ? (
|
{isNoLogs && <Typography>No log lines found</Typography>}
|
||||||
<span>Getting live logs...</span>
|
|
||||||
) : (
|
<Virtuoso
|
||||||
<span>No log lines found</span>
|
useWindowScroll
|
||||||
)}
|
totalCount={logs.length}
|
||||||
|
itemContent={getItemContent}
|
||||||
|
/>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -11223,6 +11223,11 @@ react-use@^17.3.2:
|
|||||||
ts-easing "^0.2.0"
|
ts-easing "^0.2.0"
|
||||||
tslib "^2.1.0"
|
tslib "^2.1.0"
|
||||||
|
|
||||||
|
react-virtuoso@4.0.3:
|
||||||
|
version "4.0.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/react-virtuoso/-/react-virtuoso-4.0.3.tgz#0dc8b10978095852d985b064157639b9fb9d9b1e"
|
||||||
|
integrity sha512-tyqt8FBWxO+smve/kUgJbhCI2MEOvH2hHgFYPKWBMA2cJmV+cHIDDh1BL/6w4pg/dcCdlHCNVwi6aiztPxWttw==
|
||||||
|
|
||||||
react-vis@^1.11.7:
|
react-vis@^1.11.7:
|
||||||
version "1.11.7"
|
version "1.11.7"
|
||||||
resolved "https://registry.yarnpkg.com/react-vis/-/react-vis-1.11.7.tgz#909902af00158895d14da1adfe1d0dc0045228ff"
|
resolved "https://registry.yarnpkg.com/react-vis/-/react-vis-1.11.7.tgz#909902af00158895d14da1adfe1d0dc0045228ff"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user