Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logs UI] Fix log stream data fetching #93201

Merged
merged 4 commits into from
Mar 4, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface DateRange {
startTimestamp: number;
endTimestamp: number;
timestampsLastUpdate: number;
lastCompleteDateRangeExpressionUpdate: number;
}

interface VisiblePositions {
Expand All @@ -46,6 +47,7 @@ export interface LogPositionStateParams {
startTimestamp: number | null;
endTimestamp: number | null;
timestampsLastUpdate: number;
lastCompleteDateRangeExpressionUpdate: number;
}

export interface LogPositionCallbacks {
Expand Down Expand Up @@ -121,6 +123,7 @@ export const useLogPositionState: () => LogPositionStateParams & LogPositionCall
startTimestamp: datemathToEpochMillis(DEFAULT_DATE_RANGE.startDateExpression)!,
endTimestamp: datemathToEpochMillis(DEFAULT_DATE_RANGE.endDateExpression, 'up')!,
timestampsLastUpdate: Date.now(),
lastCompleteDateRangeExpressionUpdate: Date.now(),
});

useEffect(() => {
Expand Down Expand Up @@ -171,12 +174,18 @@ export const useLogPositionState: () => LogPositionStateParams & LogPositionCall
jumpToTargetPosition(null);
}

setDateRange({
setDateRange((prevState) => ({
...newDateRange,
startTimestamp: nextStartTimestamp,
endTimestamp: nextEndTimestamp,
timestampsLastUpdate: Date.now(),
});
// NOTE: Complete refers to the last time an update was requested with both expressions. These require a full refresh (unless streaming). Timerange expansion
// and pagination however do not.
lastCompleteDateRangeExpressionUpdate:
'startDateExpression' in newDateRange && 'endDateExpression' in newDateRange
? Date.now()
: prevState.lastCompleteDateRangeExpressionUpdate,
}));
},
[setDateRange, dateRange, targetPosition]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { useCallback } from 'react';
import { combineLatest, Observable, Subject } from 'rxjs';
import { combineLatest, Observable, ReplaySubject } from 'rxjs';
import { last, map, startWith, switchMap } from 'rxjs/operators';
import { LogSourceColumnConfiguration } from '../../../../common/http_api/log_sources';
import { LogEntryCursor } from '../../../../common/log_entry';
Expand Down Expand Up @@ -53,7 +53,7 @@ export const useFetchLogEntriesAround = ({
type LogEntriesAfterRequest = NonNullable<ReturnType<typeof fetchLogEntriesAfter>>;

const logEntriesAroundSearchRequests$ = useObservable(
() => new Subject<[LogEntriesBeforeRequest, Observable<LogEntriesAfterRequest>]>(),
() => new ReplaySubject<[LogEntriesBeforeRequest, Observable<LogEntriesAfterRequest>]>(),
[]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,14 @@ export const LogEntryExampleMessage: React.FunctionComponent<Props> = ({
flyoutOptions: encode({
surroundingLogsId: id,
}),
logFilter: encode({
expression: `${partitionField}: ${dataset}`,
kind: 'kuery',
}),
...(dataset
? {
logFilter: encode({
expression: `${partitionField}: ${dataset}`,
kind: 'kuery',
}),
}
: {}),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const LogsPageLogsContent: React.FunctionComponent = () => {
startDateExpression,
endDateExpression,
updateDateRange,
lastCompleteDateRangeExpressionUpdate,
} = useContext(LogPositionState.Context);
const { filterQuery, applyLogFilterQuery } = useContext(LogFilterState.Context);

Expand All @@ -81,16 +82,16 @@ export const LogsPageLogsContent: React.FunctionComponent = () => {
const prevStartTimestamp = usePrevious(startTimestamp);
const prevEndTimestamp = usePrevious(endTimestamp);
const prevFilterQuery = usePrevious(filterQuery);
const prevLastCompleteDateRangeExpressionUpdate = usePrevious(
lastCompleteDateRangeExpressionUpdate
);

// Refetch entries if...
useEffect(() => {
const isFirstLoad = !prevStartTimestamp || !prevEndTimestamp;

const newDateRangeDoesNotOverlap =
(prevStartTimestamp != null &&
startTimestamp != null &&
prevStartTimestamp < startTimestamp) ||
(prevEndTimestamp != null && endTimestamp != null && prevEndTimestamp > endTimestamp);
const completeDateRangeExpressionHasChanged =
lastCompleteDateRangeExpressionUpdate !== prevLastCompleteDateRangeExpressionUpdate;

const isCenterPointOutsideLoadedRange =
targetPosition != null &&
Expand All @@ -101,7 +102,7 @@ export const LogsPageLogsContent: React.FunctionComponent = () => {

if (
isFirstLoad ||
newDateRangeDoesNotOverlap ||
completeDateRangeExpressionHasChanged ||
isCenterPointOutsideLoadedRange ||
hasQueryChanged
) {
Expand All @@ -124,6 +125,8 @@ export const LogsPageLogsContent: React.FunctionComponent = () => {
bottomCursor,
filterQuery,
prevFilterQuery,
lastCompleteDateRangeExpressionUpdate,
prevLastCompleteDateRangeExpressionUpdate,
]);

const { logSummaryHighlights, currentHighlightKey, logEntryHighlightsById } = useContext(
Expand Down