Skip to content

Commit

Permalink
[Reporting] add capture.maxAttempts setting (elastic#44011) (elastic#…
Browse files Browse the repository at this point in the history
…44850)

* [Reporting] add capture.maxAttempts setting

* restore default in code, so tests will pass

* --wip-- [skip ci]

* write test

* fix test

* update error message with value
  • Loading branch information
tsullivan authored Sep 6, 2019
1 parent 0a93fd1 commit f6c62fa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/settings/reporting-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ Defaults to `120000` (two minutes).
Reporting works by capturing screenshots from Kibana. The following settings
control the capturing process.

`xpack.reporting.capture.maxAttempts`::
If capturing a report fails for any reason, Kibana will re-attempt othe reporting
job, as many times as this setting. Defaults to `3`.

`xpack.reporting.capture.loadDelay`::
When visualizations are not evented, this is the amount of time before
taking a screenshot. All visualizations that ship with Kibana are evented, so this
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions x-pack/legacy/plugins/reporting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ export const reporting = (kibana) => {
}).default(),
maxScreenshotDimension: Joi.number().integer().default(1950)
}).default()
}).default(),
maxAttempts: Joi.number().integer().greater(0).when('$dist', {
is: true,
then: Joi.default(3),
otherwise: Joi.default(1),
}).default()
}).default(),
csv: Joi.object({
Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/reporting/server/lib/enqueue_job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function enqueueJobFn(server: KbnServer) {
const config = server.config();
const queueConfig = config.get('xpack.reporting.queue');
const browserType = config.get('xpack.reporting.capture.browser.type');
const maxAttempts = config.get('xpack.reporting.capture.maxAttempts');
const exportTypesRegistry = server.plugins.reporting.exportTypesRegistry;

return async function enqueueJob(
Expand All @@ -42,6 +43,7 @@ function enqueueJobFn(server: KbnServer) {
timeout: queueConfig.timeout,
created_by: get(user, 'username', false),
browser_type: browserType,
max_attempts: maxAttempts,
};

return new Promise((resolve, reject) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ describe('Job Class', function () {
const init = () => new Job(mockQueue, index, 'type1', [1, 2, 3]);
expect(init).to.throwException(/plain.+object/i);
});

it(`should throw error if invalid maxAttempts`, function () {
const init = () => new Job(mockQueue, index, 'type1', { id: '123' }, { max_attempts: -1 });
expect(init).to.throwException(/invalid.+max_attempts/i);
});
});

describe('construction', function () {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/legacy/plugins/reporting/server/lib/esqueue/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class Job extends events.EventEmitter {
this.indexSettings = options.indexSettings || {};
this.browser_type = options.browser_type;

if (typeof this.maxAttempts !== 'number' || this.maxAttempts < 1) {
throw new Error(`Invalid max_attempts: ${this.maxAttempts}`);
}

this.debug = (msg, err) => {
const logger = options.logger || function () {};
const message = `${this.id} - ${msg}`;
Expand Down

0 comments on commit f6c62fa

Please sign in to comment.