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

[data.search] Do not send keep_alive after a session is sent to background #85350

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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
};
}