mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Search Sessions] Don’t try to delete errored searches (#105434)
This commit is contained in:
parent
4b4a405043
commit
5fcdb9d137
3 changed files with 45 additions and 3 deletions
|
@ -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,
|
||||
|
@ -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', () => {
|
|
@ -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';
|
||||
|
@ -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 });
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue