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

[Search Sessions] Don’t try deleting errored searches #105434

Merged
merged 3 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -5,7 +5,7 @@
* 2.0.
*/

import { checkNonPersistedSessions as checkNonPersistedSessions$ } from './check_non_persiseted_sessions';
import { checkNonPersistedSessions as checkNonPersistedSessions$ } from './check_non_persisted_sessions';
import {
SearchSessionStatus,
SearchSessionSavedObjectAttributes,
Expand Down Expand Up @@ -322,6 +322,46 @@ describe('checkNonPersistedSessions', () => {
const { id } = mockClient.asyncSearch.delete.mock.calls[0][0];
expect(id).toBe('async-id');
});

test("doesn't attempt to delete errored out async search", async () => {
mockClient.asyncSearch.delete = jest.fn();

savedObjectsClient.find.mockResolvedValue({
saved_objects: [
{
id: '123',
attributes: {
persisted: false,
status: SearchSessionStatus.ERROR,
expires: moment().add(moment.duration(3, 'm')),
created: moment().subtract(moment.duration(30, 'm')),
touched: moment().subtract(moment.duration(6, 'm')),
idMapping: {
'map-key': {
strategy: ENHANCED_ES_SEARCH_STRATEGY,
id: 'async-id',
status: SearchStatus.ERROR,
},
},
},
},
],
total: 1,
} as any);

await checkNonPersistedSessions(
{
savedObjectsClient,
client: mockClient,
logger: mockLogger,
},
config
);

expect(savedObjectsClient.bulkUpdate).not.toBeCalled();
expect(savedObjectsClient.delete).toBeCalled();
expect(mockClient.asyncSearch.delete).not.toBeCalled();
});
});

describe('update', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
KueryNode,
} from '../../../../../../src/plugins/data/common';
import { checkSearchSessionsByPage, getSearchSessionsPage$ } from './get_search_session_page';
import { SearchSessionsConfig, CheckSearchSessionsDeps } from './types';
import { SearchSessionsConfig, CheckSearchSessionsDeps, SearchStatus } from './types';
import { bulkUpdateSessions, getAllSessionsStatusUpdates } from './update_session_status';

export const SEARCH_SESSIONS_CLEANUP_TASK_TYPE = 'search_sessions_cleanup';
Expand Down Expand Up @@ -87,6 +87,8 @@ function checkNonPersistedSessionsPage(
// Send a delete request for each async search to ES
Object.keys(session.attributes.idMapping).map(async (searchKey: string) => {
const searchInfo = session.attributes.idMapping[searchKey];
if (searchInfo.status === SearchStatus.ERROR) return; // skip attempting to delete async search in case we know it has errored out

if (searchInfo.strategy === ENHANCED_ES_SEARCH_STRATEGY) {
try {
await client.asyncSearch.delete({ id: searchInfo.id });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
SEARCH_SESSIONS_CLEANUP_TASK_TYPE,
checkNonPersistedSessions,
SEARCH_SESSIONS_CLEANUP_TASK_ID,
} from './check_non_persiseted_sessions';
} from './check_non_persisted_sessions';
import {
SEARCH_SESSIONS_EXPIRE_TASK_TYPE,
SEARCH_SESSIONS_EXPIRE_TASK_ID,
Expand Down