From c1677454e84baa5514f7d37082e7fdbc78a1942a Mon Sep 17 00:00:00 2001 From: Tim Sullivan Date: Fri, 30 Jul 2021 08:17:29 -0700 Subject: [PATCH] [Reporting CSV] Fix scroll ID bug for deprecated csv export (#106892) * [Reporting CSV] Fix scroll ID bug for deprecated csv export * fix unit test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../server/export_types/csv/execute_job.test.ts | 10 +++++----- .../export_types/csv/generate_csv/hit_iterator.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/reporting/server/export_types/csv/execute_job.test.ts b/x-pack/plugins/reporting/server/export_types/csv/execute_job.test.ts index 18cd6e826b5e7..2fb7b9b032356 100644 --- a/x-pack/plugins/reporting/server/export_types/csv/execute_job.test.ts +++ b/x-pack/plugins/reporting/server/export_types/csv/execute_job.test.ts @@ -175,7 +175,7 @@ describe('CSV Execute Job', function () { ); expect(mockEsClient.scroll).toHaveBeenCalledWith( - expect.objectContaining({ scroll_id: scrollId }) + expect.objectContaining({ body: { scroll_id: scrollId } }) ); }); @@ -261,7 +261,7 @@ describe('CSV Execute Job', function () { ); expect(mockEsClient.clearScroll).toHaveBeenCalledWith( - expect.objectContaining({ scroll_id: lastScrollId }) + expect.objectContaining({ body: { scroll_id: lastScrollId } }) ); }); @@ -295,7 +295,7 @@ describe('CSV Execute Job', function () { ); expect(mockEsClient.clearScroll).toHaveBeenCalledWith( - expect.objectContaining({ scroll_id: lastScrollId }) + expect.objectContaining({ body: { scroll_id: lastScrollId } }) ); }); }); @@ -754,7 +754,7 @@ describe('CSV Execute Job', function () { expect(mockEsClient.clearScroll).toHaveBeenCalledWith( expect.objectContaining({ - scroll_id: scrollId, + body: { scroll_id: scrollId }, }) ); }); @@ -1151,7 +1151,7 @@ describe('CSV Execute Job', function () { await runTask('job123', jobParams, cancellationToken); expect(mockEsClient.scroll).toHaveBeenCalledWith( - expect.objectContaining({ scroll: scrollDuration }) + expect.objectContaining({ body: { scroll: scrollDuration, scroll_id: 'scrollId' } }) ); }); }); diff --git a/x-pack/plugins/reporting/server/export_types/csv/generate_csv/hit_iterator.ts b/x-pack/plugins/reporting/server/export_types/csv/generate_csv/hit_iterator.ts index 72935e64dd6b5..9014e4f85b3b2 100644 --- a/x-pack/plugins/reporting/server/export_types/csv/generate_csv/hit_iterator.ts +++ b/x-pack/plugins/reporting/server/export_types/csv/generate_csv/hit_iterator.ts @@ -60,12 +60,14 @@ export function createHitIterator(logger: LevelLogger) { ); } - async function scroll(scrollId: string | undefined) { + async function scroll(scrollId: string) { logger.debug('executing scroll request'); return parseResponse( await elasticsearchClient.scroll({ - scroll_id: scrollId, - scroll: scrollSettings.duration, + body: { + scroll_id: scrollId, + scroll: scrollSettings.duration, + }, }) ); } @@ -74,7 +76,7 @@ export function createHitIterator(logger: LevelLogger) { logger.debug('executing clearScroll request'); try { await elasticsearchClient.clearScroll({ - scroll_id: scrollId, + body: { scroll_id: scrollId }, }); } catch (err) { // Do not throw the error, as the job can still be completed successfully