mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 19:39:02 +08:00
feat: send last log line time stamp for timestamp order-by desc (#5968)
* feat: send last log line time stamp for timestamp orderby desc * chore: little cleanup
This commit is contained in:
parent
a023a7514e
commit
e77a6f4d7a
@ -133,6 +133,9 @@ function LogsExplorerViews({
|
|||||||
// State
|
// State
|
||||||
const [page, setPage] = useState<number>(1);
|
const [page, setPage] = useState<number>(1);
|
||||||
const [logs, setLogs] = useState<ILog[]>([]);
|
const [logs, setLogs] = useState<ILog[]>([]);
|
||||||
|
const [lastLogLineTimestamp, setLastLogLineTimestamp] = useState<
|
||||||
|
number | string | null
|
||||||
|
>();
|
||||||
const [requestData, setRequestData] = useState<Query | null>(null);
|
const [requestData, setRequestData] = useState<Query | null>(null);
|
||||||
const [showFormatMenuItems, setShowFormatMenuItems] = useState(false);
|
const [showFormatMenuItems, setShowFormatMenuItems] = useState(false);
|
||||||
const [queryId, setQueryId] = useState<string>(v4());
|
const [queryId, setQueryId] = useState<string>(v4());
|
||||||
@ -270,6 +273,14 @@ function LogsExplorerViews({
|
|||||||
start: minTime,
|
start: minTime,
|
||||||
end: maxTime,
|
end: maxTime,
|
||||||
}),
|
}),
|
||||||
|
// send the lastLogTimeStamp only when the panel type is list and the orderBy is timestamp and the order is desc
|
||||||
|
lastLogLineTimestamp:
|
||||||
|
panelType === PANEL_TYPES.LIST &&
|
||||||
|
requestData?.builder?.queryData?.[0]?.orderBy?.[0]?.columnName ===
|
||||||
|
'timestamp' &&
|
||||||
|
requestData?.builder?.queryData?.[0]?.orderBy?.[0]?.order === 'desc'
|
||||||
|
? lastLogLineTimestamp
|
||||||
|
: undefined,
|
||||||
},
|
},
|
||||||
undefined,
|
undefined,
|
||||||
listQueryKeyRef,
|
listQueryKeyRef,
|
||||||
@ -347,6 +358,10 @@ function LogsExplorerViews({
|
|||||||
pageSize: nextPageSize,
|
pageSize: nextPageSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// initialise the last log timestamp to null as we don't have the logs.
|
||||||
|
// as soon as we scroll to the end of the logs we set the lastLogLineTimestamp to the last log timestamp.
|
||||||
|
setLastLogLineTimestamp(lastLog.timestamp);
|
||||||
|
|
||||||
setPage((prevPage) => prevPage + 1);
|
setPage((prevPage) => prevPage + 1);
|
||||||
|
|
||||||
setRequestData(newRequestData);
|
setRequestData(newRequestData);
|
||||||
@ -539,6 +554,11 @@ function LogsExplorerViews({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// clear the lastLogLineTimestamp when the data changes
|
||||||
|
setLastLogLineTimestamp(null);
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
requestData?.id !== stagedQuery?.id ||
|
requestData?.id !== stagedQuery?.id ||
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import getStartEndRangeTime from 'lib/getStartEndRangeTime';
|
import getStartEndRangeTime from 'lib/getStartEndRangeTime';
|
||||||
import getStep from 'lib/getStep';
|
import getStep from 'lib/getStep';
|
||||||
import { mapQueryDataToApi } from 'lib/newQueryBuilder/queryBuilderMappers/mapQueryDataToApi';
|
import { mapQueryDataToApi } from 'lib/newQueryBuilder/queryBuilderMappers/mapQueryDataToApi';
|
||||||
|
import { isUndefined } from 'lodash-es';
|
||||||
import store from 'store';
|
import store from 'store';
|
||||||
import { QueryRangePayload } from 'types/api/metrics/getQueryRange';
|
import { QueryRangePayload } from 'types/api/metrics/getQueryRange';
|
||||||
import { EQueryType } from 'types/common/dashboard';
|
import { EQueryType } from 'types/common/dashboard';
|
||||||
@ -24,7 +25,11 @@ export const prepareQueryRangePayload = ({
|
|||||||
fillGaps = false,
|
fillGaps = false,
|
||||||
}: GetQueryResultsProps): PrepareQueryRangePayload => {
|
}: GetQueryResultsProps): PrepareQueryRangePayload => {
|
||||||
let legendMap: Record<string, string> = {};
|
let legendMap: Record<string, string> = {};
|
||||||
const { allowSelectedIntervalForStepGen, ...restParams } = params;
|
const {
|
||||||
|
allowSelectedIntervalForStepGen,
|
||||||
|
lastLogLineTimestamp,
|
||||||
|
...restParams
|
||||||
|
} = params;
|
||||||
|
|
||||||
const compositeQuery: QueryRangePayload['compositeQuery'] = {
|
const compositeQuery: QueryRangePayload['compositeQuery'] = {
|
||||||
queryType: query.queryType,
|
queryType: query.queryType,
|
||||||
@ -90,9 +95,13 @@ export const prepareQueryRangePayload = ({
|
|||||||
interval: globalSelectedInterval,
|
interval: globalSelectedInterval,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const endLogTimeStamp = !isUndefined(lastLogLineTimestamp)
|
||||||
|
? new Date(lastLogLineTimestamp as string | number)?.getTime() || undefined
|
||||||
|
: undefined;
|
||||||
|
|
||||||
const queryPayload: QueryRangePayload = {
|
const queryPayload: QueryRangePayload = {
|
||||||
start: parseInt(start, 10) * 1e3,
|
start: parseInt(start, 10) * 1e3,
|
||||||
end: parseInt(end, 10) * 1e3,
|
end: endLogTimeStamp || parseInt(end, 10) * 1e3,
|
||||||
step: getStep({
|
step: getStep({
|
||||||
start: allowSelectedIntervalForStepGen
|
start: allowSelectedIntervalForStepGen
|
||||||
? start
|
? start
|
||||||
|
Loading…
x
Reference in New Issue
Block a user