Skip to content

Commit

Permalink
[data.search] Do not send keep_alive after a session is sent to backg…
Browse files Browse the repository at this point in the history
…round
  • Loading branch information
lukasolson committed Dec 8, 2020
1 parent 72ed936 commit 1781a44
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export const eqlSearchStrategyProvider = (
uiSettingsClient
);
const params = id
? getDefaultAsyncGetParams()
? getDefaultAsyncGetParams(options)
: {
...(await getIgnoreThrottled(uiSettingsClient)),
...defaultParams,
...getDefaultAsyncGetParams(),
...getDefaultAsyncGetParams(options),
...request.params,
};
const promise = id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ describe('ES search strategy', () => {

beforeEach(() => {
mockApiCaller.mockClear();
mockGetCaller.mockClear();
mockSubmitCaller.mockClear();
});

it('returns a strategy with `search`', async () => {
Expand Down Expand Up @@ -103,6 +105,34 @@ describe('ES search strategy', () => {
expect(request).toHaveProperty('keep_alive');
});

it('does not include keep_alive after a session is saved', async () => {
mockGetCaller.mockResolvedValueOnce(mockAsyncResponse);

const params = { index: 'logstash-*', body: { query: {} } };
const options = { sessionId: 'foo', isStored: true };
const esSearch = await enhancedEsSearchStrategyProvider(mockConfig$, mockLogger);

await esSearch.search({ id: 'foo', params }, options, mockDeps).toPromise();

expect(mockGetCaller).toBeCalled();
const request = mockGetCaller.mock.calls[0][0];
expect(request).not.toHaveProperty('keep_alive');
});

it('does not include keep_alive when a session is being restored', async () => {
mockGetCaller.mockResolvedValueOnce(mockAsyncResponse);

const params = { index: 'logstash-*', body: { query: {} } };
const options = { sessionId: 'foo', isStored: true, isRestored: true };
const esSearch = await enhancedEsSearchStrategyProvider(mockConfig$, mockLogger);

await esSearch.search({ id: 'foo', params }, options, mockDeps).toPromise();

expect(mockGetCaller).toBeCalled();
const request = mockGetCaller.mock.calls[0][0];
expect(request).not.toHaveProperty('keep_alive');
});

it('calls the rollup API if the index is a rollup type', async () => {
mockApiCaller.mockResolvedValueOnce(mockRollupResponse);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const enhancedEsSearchStrategyProvider = (

const search = async () => {
const params = id
? getDefaultAsyncGetParams()
? getDefaultAsyncGetParams(options)
: { ...(await getDefaultAsyncSubmitParams(uiSettingsClient, options)), ...request.params };
const promise = id
? client.get<AsyncSearchResponse>({ ...params, id })
Expand Down
14 changes: 8 additions & 6 deletions x-pack/plugins/data_enhanced/server/search/request_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function getDefaultAsyncSubmitParams(
return {
batched_reduce_size: 64,
keep_on_completion: !!options.sessionId, // Always return an ID, even if the request completes quickly
...getDefaultAsyncGetParams(),
...getDefaultAsyncGetParams(options),
...(await getIgnoreThrottled(uiSettingsClient)),
...(await getDefaultSearchParams(uiSettingsClient)),
};
Expand All @@ -53,12 +53,14 @@ export async function getDefaultAsyncSubmitParams(
/**
@internal
*/
export function getDefaultAsyncGetParams(): Pick<
AsyncSearchGet,
'keep_alive' | 'wait_for_completion_timeout'
> {
export function getDefaultAsyncGetParams(
options: ISearchOptions
): Pick<AsyncSearchGet, 'keep_alive' | 'wait_for_completion_timeout'> {
// Extend the TTL for this search request by one minute (unless it has already been sent to background)
const isSentToBackground = options.sessionId && (options.isStored || options.isRestore);
const keepAlive = !isSentToBackground ? { keep_alive: '1m' } : {};
return {
keep_alive: '1m', // Extend the TTL for this search request by one minute
...keepAlive,
wait_for_completion_timeout: '100ms', // Wait up to 100ms for the response to return
};
}

0 comments on commit 1781a44

Please sign in to comment.