Reporting/reveal document bytes (#26667) (#27056)

* Adding a `size` property to all job-reporting meta-data and showing in reporting details pane
This commit is contained in:
Joel Griffith 2018-12-12 11:33:17 -08:00 committed by GitHub
parent e69ca8d5eb
commit b111074004
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 39 additions and 7 deletions

View file

@ -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,
@ -89,7 +89,8 @@ function executeJobFn(server) {
return {
content_type: 'text/csv',
content,
max_size_reached: maxSizeReached
max_size_reached: maxSizeReached,
size,
};
};
}

View file

@ -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);
});
});
});

View file

@ -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,
};
};
}

View file

@ -22,6 +22,10 @@ export class MaxSizeStringBuilder {
return false;
}
getSizeInBytes() {
return this._size;
}
getString() {
return this._buffer.slice(0, this._size).toString();
}

View file

@ -26,7 +26,8 @@ function executeJobFn(server) {
}),
map(buffer => ({
content_type: 'image/png',
content: buffer.toString('base64')
content: buffer.toString('base64'),
size: buffer.byteLength,
}))
);

View file

@ -34,7 +34,8 @@ function executeJobFn(server) {
}),
map(buffer => ({
content_type: 'application/pdf',
content: buffer.toString('base64')
content: buffer.toString('base64'),
size: buffer.byteLength,
}))
);

View file

@ -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: [
{

View file

@ -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: {

View file

@ -58,6 +58,7 @@ const schema = {
type: 'object',
properties: {
content_type: { type: 'keyword' },
size: { type: 'keyword' },
content: { type: 'object', enabled: false }
}
}

View file

@ -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;