diff --git a/x-pack/plugins/reporting/export_types/csv/server/execute_job.js b/x-pack/plugins/reporting/export_types/csv/server/execute_job.js index 89ac80016fa55..4ef1658d88f8e 100644 --- a/x-pack/plugins/reporting/export_types/csv/server/execute_job.js +++ b/x-pack/plugins/reporting/export_types/csv/server/execute_job.js @@ -65,7 +65,7 @@ function executeJobFn(server) { const maxSizeBytes = config.get('xpack.reporting.csv.maxSizeBytes'); const scroll = config.get('xpack.reporting.csv.scroll'); - const { content, maxSizeReached } = await generateCsv({ + const { content, maxSizeReached, size } = await generateCsv({ searchRequest, fields, formatsMap, @@ -84,7 +84,8 @@ function executeJobFn(server) { return { content_type: 'text/csv', content, - max_size_reached: maxSizeReached + max_size_reached: maxSizeReached, + size, }; }; } diff --git a/x-pack/plugins/reporting/export_types/csv/server/lib/__tests__/max_size_string_builder.js b/x-pack/plugins/reporting/export_types/csv/server/lib/__tests__/max_size_string_builder.js index d550399636845..15a10934b5db5 100644 --- a/x-pack/plugins/reporting/export_types/csv/server/lib/__tests__/max_size_string_builder.js +++ b/x-pack/plugins/reporting/export_types/csv/server/lib/__tests__/max_size_string_builder.js @@ -63,4 +63,18 @@ describe('MaxSizeStringBuilder', function () { expect(builder.getString()).to.be('a'); }); }); + + describe('getSizeInBytes', function () { + it(`should return 0 when no strings have been appended`, function () { + const builder = new MaxSizeStringBuilder(100); + expect(builder.getSizeInBytes()).to.be(0); + }); + + it(`should the size in bytes`, function () { + const builder = new MaxSizeStringBuilder(100); + const stringValue = 'foobar'; + builder.tryAppend(stringValue); + expect(builder.getSizeInBytes()).to.be(stringValue.length); + }); + }); }); diff --git a/x-pack/plugins/reporting/export_types/csv/server/lib/generate_csv.js b/x-pack/plugins/reporting/export_types/csv/server/lib/generate_csv.js index 016081198d033..2d0133238bf82 100644 --- a/x-pack/plugins/reporting/export_types/csv/server/lib/generate_csv.js +++ b/x-pack/plugins/reporting/export_types/csv/server/lib/generate_csv.js @@ -58,11 +58,13 @@ export function createGenerateCsv(logger) { } finally { await iterator.return(); } + const size = builder.getSizeInBytes(); + logger(`finished generating, total size in bytes: ${size}`); - logger('finished generating'); return { content: builder.getString(), - maxSizeReached + maxSizeReached, + size, }; }; } diff --git a/x-pack/plugins/reporting/export_types/csv/server/lib/max_size_string_builder.js b/x-pack/plugins/reporting/export_types/csv/server/lib/max_size_string_builder.js index d1d86fd2bb250..b4bdfcc13b3f6 100644 --- a/x-pack/plugins/reporting/export_types/csv/server/lib/max_size_string_builder.js +++ b/x-pack/plugins/reporting/export_types/csv/server/lib/max_size_string_builder.js @@ -22,6 +22,10 @@ export class MaxSizeStringBuilder { return false; } + getSizeInBytes() { + return this._size; + } + getString() { return this._buffer.slice(0, this._size).toString(); } diff --git a/x-pack/plugins/reporting/export_types/png/server/execute_job/index.js b/x-pack/plugins/reporting/export_types/png/server/execute_job/index.js index d9edbd7e0c6de..fda79fb92da2a 100644 --- a/x-pack/plugins/reporting/export_types/png/server/execute_job/index.js +++ b/x-pack/plugins/reporting/export_types/png/server/execute_job/index.js @@ -26,7 +26,8 @@ function executeJobFn(server) { }), map(buffer => ({ content_type: 'image/png', - content: buffer.toString('base64') + content: buffer.toString('base64'), + size: buffer.byteLength, })) ); diff --git a/x-pack/plugins/reporting/export_types/printable_pdf/server/execute_job/index.js b/x-pack/plugins/reporting/export_types/printable_pdf/server/execute_job/index.js index 4f5e6ca830625..618a26b99cc1d 100644 --- a/x-pack/plugins/reporting/export_types/printable_pdf/server/execute_job/index.js +++ b/x-pack/plugins/reporting/export_types/printable_pdf/server/execute_job/index.js @@ -34,7 +34,8 @@ function executeJobFn(server) { }), map(buffer => ({ content_type: 'application/pdf', - content: buffer.toString('base64') + content: buffer.toString('base64'), + size: buffer.byteLength, })) ); diff --git a/x-pack/plugins/reporting/public/components/report_info_button.tsx b/x-pack/plugins/reporting/public/components/report_info_button.tsx index 6168a2e2a8f6b..56ad3f927498c 100644 --- a/x-pack/plugins/reporting/public/components/report_info_button.tsx +++ b/x-pack/plugins/reporting/public/components/report_info_button.tsx @@ -126,6 +126,10 @@ export class ReportInfoButton extends Component { title: 'Content Type', description: get(info, 'output.content_type') || NA, }, + { + title: 'Size in Bytes', + description: get(info, 'output.size') || NA, + }, ], status: [ { diff --git a/x-pack/plugins/reporting/public/lib/job_queue_client.ts b/x-pack/plugins/reporting/public/lib/job_queue_client.ts index d5cdde62acfbd..ca5d21dccfb1f 100644 --- a/x-pack/plugins/reporting/public/lib/job_queue_client.ts +++ b/x-pack/plugins/reporting/public/lib/job_queue_client.ts @@ -27,7 +27,10 @@ export interface JobInfo { jobtype: string; created_by: string; timeout: number; - output: { content_type: string }; + output: { + content_type: string; + size: number; + }; process_expiration: string; completed_at: string; payload: { diff --git a/x-pack/plugins/reporting/server/lib/esqueue/helpers/create_index.js b/x-pack/plugins/reporting/server/lib/esqueue/helpers/create_index.js index bf022ba7f98f4..45be7529e6887 100644 --- a/x-pack/plugins/reporting/server/lib/esqueue/helpers/create_index.js +++ b/x-pack/plugins/reporting/server/lib/esqueue/helpers/create_index.js @@ -58,6 +58,7 @@ const schema = { type: 'object', properties: { content_type: { type: 'keyword' }, + size: { type: 'keyword' }, content: { type: 'object', enabled: false } } } diff --git a/x-pack/plugins/reporting/server/lib/esqueue/worker.js b/x-pack/plugins/reporting/server/lib/esqueue/worker.js index 02f9c054c2e3b..97439b5713579 100644 --- a/x-pack/plugins/reporting/server/lib/esqueue/worker.js +++ b/x-pack/plugins/reporting/server/lib/esqueue/worker.js @@ -184,6 +184,7 @@ export class Worker extends events.EventEmitter { docOutput.content = output.content; docOutput.content_type = output.content_type || unknownMime; docOutput.max_size_reached = output.max_size_reached; + docOutput.size = output.size; } else { docOutput.content = output || defaultOutput; docOutput.content_type = unknownMime;