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

[8.x] [Discover] Fix issue where KEEP columns are not applied after Elasticsearch error (#205833) #205968

Merged
merged 3 commits into from
Jan 9, 2025
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 @@ -183,7 +183,10 @@ export function fetchAll(
// Only the document query should send its errors to main$, to cause the full Discover app
// to get into an error state. The other queries will not cause all of Discover to error out
// but their errors will be shown in-place (e.g. of the chart).
.catch(sendErrorTo(dataSubjects.documents$, dataSubjects.main$));
.catch((e) => {
sendErrorMsg(dataSubjects.documents$, e, { query });
sendErrorMsg(dataSubjects.main$, e);
});

// Return a promise that will resolve once all the requests have finished or failed, or no results are found
return firstValueFrom(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function useEsqlMode({
switchMap(async (next) => {
const { query: nextQuery } = next;

if (!nextQuery || next.fetchStatus === FetchStatus.ERROR) {
if (!nextQuery) {
return;
}

Expand Down Expand Up @@ -104,6 +104,12 @@ export function useEsqlMode({
return;
}

if (next.fetchStatus === FetchStatus.ERROR) {
// An error occurred, but it's still considered an initial fetch
prev.current.initialFetch = false;
return;
}

if (next.fetchStatus !== FetchStatus.PARTIAL) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ export function sendLoadingMoreFinishedMsg(
/**
* Send ERROR message
*/
export function sendErrorMsg(data$: DataMain$ | DataDocuments$ | DataTotalHits$, error?: Error) {
data$.next({ fetchStatus: FetchStatus.ERROR, error });
export function sendErrorMsg<T extends DataMsg>(
data$: DataMain$ | DataDocuments$ | DataTotalHits$,
error?: Error,
props?: Omit<T, 'fetchStatus' | 'error'>
) {
data$.next({ fetchStatus: FetchStatus.ERROR, error, ...props });
}

/**
Expand Down
17 changes: 17 additions & 0 deletions test/functional/apps/discover/esql/_esql_columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await dataGrid.getHeaderFields()).to.eql(['ip', '@timestamp', 'bytes']);
});

it('should recover from an error and reset columns correctly when a transformational query is used', async () => {
await monacoEditor.setCodeEditorValue('from not_an_index');
await testSubjects.click('querySubmitButton');
await header.waitUntilLoadingHasFinished();
await discover.showsErrorCallout();
await browser.refresh();
await header.waitUntilLoadingHasFinished();
await discover.showsErrorCallout();
await monacoEditor.setCodeEditorValue(
'from logstash-* | keep ip, @timestamp, bytes | limit 10'
);
await testSubjects.click('querySubmitButton');
await header.waitUntilLoadingHasFinished();
await discover.waitUntilSearchingHasFinished();
expect(await dataGrid.getHeaderFields()).to.eql(['ip', '@timestamp', 'bytes']);
});

it('should restore columns correctly when switching between saved searches', async () => {
await discover.loadSavedSearch(SAVED_SEARCH_NON_TRANSFORMATIONAL_INITIAL_COLUMNS);
await header.waitUntilLoadingHasFinished();
Expand Down
Loading