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

ESQL streaming PoC #191003

Closed
wants to merge 2 commits into from
Closed
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 @@ -453,6 +453,16 @@ export class SearchInterceptor {
...searchOptions,
}),
})
.then((response) => {
return response.rawResponse
? response
: {
id: response.id,
rawResponse: response,
isPartial: response.is_partial,
isRunning: response.is_running,
};
})
.catch((e: IHttpFetchError<KibanaServerError>) => {
if (e?.body) {
throw e.body;
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/data/server/search/routes/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { first } from 'rxjs';
import { schema } from '@kbn/config-schema';
import { reportServerError } from '@kbn/kibana-utils-plugin/server';
import { PassThrough } from 'stream';
import { reportSearchError } from '../report_search_error';
import { getRequestAbortedSignal } from '../../lib';
import type { DataPluginRouter } from '../types';
Expand Down Expand Up @@ -73,7 +74,13 @@ export function registerSearchRoute(router: DataPluginRouter): void {
.pipe(first())
.toPromise();

return res.ok({ body: response });
if (response.rawResponse.pipe) {
const stream = new PassThrough();
response.rawResponse.pipe(stream);
return res.ok({ body: stream });
} else {
return res.ok({ body: response });
}
} catch (err) {
return reportSearchError(res, err);
}
Expand Down
6 changes: 1 addition & 5 deletions src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
switchMap((searchRequest) =>
strategy.search(searchRequest, options, deps).pipe(
concatMap((response) => {
response = {
...response,
isRestored: !!searchRequest.id,
};

response.isRestored = !!searchRequest.id;
if (
options.sessionId && // if within search session
options.isStored && // and search session was saved (saved object exists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { pollSearch } from '../../../../common';
import { getKbnSearchError } from '../../report_search_error';
import type { ISearchStrategy, SearchStrategyDependencies } from '../../types';
import type { IAsyncSearchOptions } from '../../../../common';
import { toAsyncKibanaSearchResponse } from './response_utils';
import { SearchConfigSchema } from '../../../../config';
import { sanitizeRequestParams } from '../../sanitize_request_params';

// `drop_null_columns` is going to change the response
// now we get `all_columns` and `columns`
Expand Down Expand Up @@ -73,14 +73,14 @@ export const esqlAsyncSearchStrategyProvider = (
...(await getCommonDefaultAsyncSubmitParams(searchConfig, options)),
...requestParams,
};
const { body, headers, meta } = id
const response = id
? await client.transport.request<SqlGetAsyncResponse>(
{
method: 'GET',
path: `/_query/async/${id}`,
querystring: { ...params },
},
{ ...options.transport, signal: options.abortSignal, meta: true }
{ ...options.transport, signal: options.abortSignal, meta: true, asStream: true }
)
: await client.transport.request<SqlGetAsyncResponse>(
{
Expand All @@ -89,16 +89,16 @@ export const esqlAsyncSearchStrategyProvider = (
body: params,
querystring: dropNullColumns ? 'drop_null_columns' : '',
},
{ ...options.transport, signal: options.abortSignal, meta: true }
{ ...options.transport, signal: options.abortSignal, meta: true, asStream: true }
);

const finalResponse = toAsyncKibanaSearchResponse(
body,
headers?.warning,
// do not return requestParams on polling calls
id ? undefined : meta?.request?.params
);
return finalResponse;
const { body, headers, meta } = response;
return {
id: headers['x-elasticsearch-async-id'],
rawResponse: body,
isRunning: headers['x-elasticsearch-async-is-running'] === '?1',
...(headers?.warning ? { warning: headers?.warning } : {}),
...(requestParams ? { requestParams: sanitizeRequestParams(meta?.request?.params) } : {}),
};
};

const cancel = async () => {
Expand Down