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

[backport] Reporting/reveal document bytes (#26667) #27056

Merged
merged 1 commit into from
Dec 12, 2018
Merged
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 @@ -70,7 +70,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,
Expand All @@ -89,7 +89,8 @@ function executeJobFn(server) {
return {
content_type: 'text/csv',
content,
max_size_reached: maxSizeReached
max_size_reached: maxSizeReached,
size,
};
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class MaxSizeStringBuilder {
return false;
}

getSizeInBytes() {
return this._size;
}

getString() {
return this._buffer.slice(0, this._size).toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function executeJobFn(server) {
}),
map(buffer => ({
content_type: 'image/png',
content: buffer.toString('base64')
content: buffer.toString('base64'),
size: buffer.byteLength,
}))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function executeJobFn(server) {
}),
map(buffer => ({
content_type: 'application/pdf',
content: buffer.toString('base64')
content: buffer.toString('base64'),
size: buffer.byteLength,
}))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export class ReportInfoButton extends Component<Props, State> {
title: 'Content Type',
description: get(info, 'output.content_type') || NA,
},
{
title: 'Size in Bytes',
description: get(info, 'output.size') || NA,
},
],
status: [
{
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/reporting/public/lib/job_queue_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const schema = {
type: 'object',
properties: {
content_type: { type: 'keyword' },
size: { type: 'keyword' },
content: { type: 'object', enabled: false }
}
}
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/reporting/server/lib/esqueue/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down