Skip to content

Commit

Permalink
use reporting’s timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Jan 12, 2024
1 parent df74f62 commit d27f68d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 7 additions & 1 deletion packages/kbn-generate-csv/src/generate_csv_esql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,13 @@ describe('CsvESQLGenerator', () => {
query: '',
},
},
{ strategy: 'esql' }
{
strategy: 'esql',
transport: {
requestTimeout: '30s',
},
abortSignal: expect.any(AbortSignal),
}
);
});
});
Expand Down
6 changes: 6 additions & 0 deletions packages/kbn-generate-csv/src/generate_csv_esql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,18 @@ export class CsvESQLGenerator {
};

try {
const abortController = new AbortController();
this.cancellationToken.on(() => abortController.abort());
const { rawResponse, warning } = await lastValueFrom(
this.clients.data.search<
IKibanaSearchRequest<ESQLSearchParams>,
IKibanaSearchResponse<ESQLSearchReponse>
>(searchParams, {
strategy: ESQL_SEARCH_STRATEGY,
abortSignal: abortController.signal,
transport: {
requestTimeout: settings.scroll.duration,
},
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { from } from 'rxjs';
import { ensureDuration } from '@kbn/config-schema/src/duration';
import type { Logger } from '@kbn/core/server';
import { getKbnSearchError, KbnSearchError } from '../../report_search_error';
import type { ISearchStrategy } from '../../types';
Expand All @@ -27,15 +28,17 @@ export const esqlSearchStrategyProvider = (
*/
search: (request, { abortSignal, ...options }, { esClient, uiSettingsClient }) => {
const abortController = new AbortController();
// We found out that there are cases where we are not aborting correctly
// For this reasons we want to manually cancel he abort signal after 2 mins

// We found out that there are cases where we are not aborting correctly
// For this reason we want to manually abort after 2 minute or after the custom options.transport?.requestTimeout
const forceAbortTimeout = options.transport?.requestTimeout
? ensureDuration(options.transport?.requestTimeout).asMilliseconds()
: ES_TIMEOUT_IN_MS;
abortSignal?.addEventListener('abort', () => {
abortController.abort();
});

// Also abort after two mins
setTimeout(() => abortController.abort(), ES_TIMEOUT_IN_MS);
// Also abort after two mins or after the custom options.transport?.requestTimeout
setTimeout(() => abortController.abort(), forceAbortTimeout);

// Only default index pattern type is supported here.
// See ese for other type support.
Expand All @@ -59,6 +62,7 @@ export const esqlSearchStrategyProvider = (
meta: true,
// we don't want the ES client to retry (default value is 3)
maxRetries: 0,
requestTimeout: options.transport?.requestTimeout,
}
);
return {
Expand Down

0 comments on commit d27f68d

Please sign in to comment.