[Logs UI] Ensure live stream always gets latest entries (#67935)
LogPositionState doesn't always reevaluate the value of `endTimestamp`
when live stream is on. The [dependencies][1] for it to change rely on the
scroll position to update. If there's less than one scroll page or the
previous API call didn't return any entries, the `endTimestamp` would
not update.
We force `Date.now()` as an `endTimestamp` on the API call to ensure it
always gets the latest entries possible, regardless of the state. This
introduces some inconsistency that will be fixed once work beings on #65493.
[1]: fe4c164681/x-pack/plugins/infra/public/containers/logs/log_position/log_position_state.ts (L160-L173)
This commit is contained in:
parent
ce7940adc2
commit
77e7e0bb49
|
@ -194,7 +194,10 @@ const useFetchEntriesEffect = (
|
|||
}
|
||||
};
|
||||
|
||||
const runFetchMoreEntriesRequest = async (direction: ShouldFetchMoreEntries) => {
|
||||
const runFetchMoreEntriesRequest = async (
|
||||
direction: ShouldFetchMoreEntries,
|
||||
overrides: Partial<LogEntriesProps> = {}
|
||||
) => {
|
||||
if (!props.startTimestamp || !props.endTimestamp) {
|
||||
return;
|
||||
}
|
||||
|
@ -209,10 +212,10 @@ const useFetchEntriesEffect = (
|
|||
|
||||
try {
|
||||
const commonFetchArgs: LogEntriesBaseRequest = {
|
||||
sourceId: props.sourceId,
|
||||
startTimestamp: props.startTimestamp,
|
||||
endTimestamp: props.endTimestamp,
|
||||
query: props.filterQuery,
|
||||
sourceId: overrides.sourceId || props.sourceId,
|
||||
startTimestamp: overrides.startTimestamp || props.startTimestamp,
|
||||
endTimestamp: overrides.endTimestamp || props.endTimestamp,
|
||||
query: overrides.filterQuery || props.filterQuery,
|
||||
};
|
||||
|
||||
const fetchArgs: LogEntriesRequest = getEntriesBefore
|
||||
|
@ -279,10 +282,10 @@ const useFetchEntriesEffect = (
|
|||
const streamEntriesEffect = () => {
|
||||
(async () => {
|
||||
if (props.isStreaming && !state.isLoadingMore && !state.isReloading) {
|
||||
const endTimestamp = Date.now();
|
||||
if (startedStreaming) {
|
||||
await new Promise((res) => setTimeout(res, LIVE_STREAM_INTERVAL));
|
||||
} else {
|
||||
const endTimestamp = Date.now();
|
||||
props.jumpToTargetPosition({ tiebreaker: 0, time: endTimestamp });
|
||||
setStartedStreaming(true);
|
||||
if (state.hasMoreAfterEnd) {
|
||||
|
@ -290,7 +293,9 @@ const useFetchEntriesEffect = (
|
|||
return;
|
||||
}
|
||||
}
|
||||
const newEntriesEnd = await runFetchMoreEntriesRequest(ShouldFetchMoreEntries.After);
|
||||
const newEntriesEnd = await runFetchMoreEntriesRequest(ShouldFetchMoreEntries.After, {
|
||||
endTimestamp,
|
||||
});
|
||||
if (newEntriesEnd) {
|
||||
props.jumpToTargetPosition(newEntriesEnd);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue