Skip to content

Commit

Permalink
Adding in browser info to the report-info drawer (#26307) (#26656)
Browse files Browse the repository at this point in the history
* Adding in browser info to the report-info drawer

* Conditionalizes the browser-type panel prints + constantizes jobTypes

* Fixing config feedback lost in force push
  • Loading branch information
joelgriffith authored Dec 4, 2018
1 parent 09cd080 commit d51b57a
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 7 deletions.
5 changes: 5 additions & 0 deletions x-pack/plugins/reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ export const UI_SETTINGS_CUSTOM_PDF_LOGO = 'xpackReporting:customPdfLogo';
* @type {string}
*/
export const KIBANA_REPORTING_TYPE = 'reporting';

export const PDF_JOB_TYPE = 'printable_pdf';
export const PNG_JOB_TYPE = 'PNG';
export const CSV_JOB_TYPE = 'csv';
export const USES_HEADLESS_JOB_TYPES = [PDF_JOB_TYPE, PNG_JOB_TYPE];
3 changes: 2 additions & 1 deletion x-pack/plugins/reporting/export_types/csv/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import { createJobFactory } from './create_job';
import { executeJobFactory } from './execute_job';
import { metadata } from '../metadata';
import { CSV_JOB_TYPE as jobType } from '../../../common/constants';

export function register(registry) {
registry.register({
...metadata,
jobType: 'csv',
jobType,
jobContentExtension: 'csv',
createJobFactory,
executeJobFactory,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/reporting/export_types/png/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import { createJobFactory } from './create_job';
import { executeJobFactory } from './execute_job';
import { metadata } from '../metadata';
import { PNG_JOB_TYPE as jobType } from '../../../common/constants';

export function register(registry) {
registry.register({
...metadata,
jobType: 'PNG',
jobType,
jobContentEncoding: 'base64',
jobContentExtension: 'PNG',
createJobFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import { createJobFactory } from './create_job';
import { executeJobFactory } from './execute_job';
import { metadata } from '../metadata';
import { PDF_JOB_TYPE as jobType } from '../../../common/constants';

export function register(registry) {
registry.register({
...metadata,
jobType: 'printable_pdf',
jobType,
jobContentEncoding: 'base64',
jobContentExtension: 'pdf',
createJobFactory,
Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/reporting/public/components/report_info_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '@elastic/eui';
import { get } from 'lodash';
import React, { Component, Fragment } from 'react';
import { USES_HEADLESS_JOB_TYPES } from '../../common/constants';
import { JobInfo, jobQueueClient } from '../lib/job_queue_client';

interface Props {
Expand All @@ -32,6 +33,7 @@ interface State {
}

const NA = 'n/a';
const UNKNOWN = 'unknown';

const getDimensions = (info: JobInfo) => {
const defaultDimensions = { width: null, height: null };
Expand Down Expand Up @@ -73,7 +75,8 @@ export class ReportInfoButton extends Component<Props, State> {
return null;
}

// TODO browser type
const jobType = get(info, 'jobtype', NA);

// TODO queue method (clicked UI, watcher, etc)
const jobInfoParts = {
datetimes: [
Expand Down Expand Up @@ -117,7 +120,7 @@ export class ReportInfoButton extends Component<Props, State> {
},
{
title: 'Job Type',
description: get(info, 'jobtype', NA),
description: jobType,
},
{
title: 'Content Type',
Expand Down Expand Up @@ -145,6 +148,12 @@ export class ReportInfoButton extends Component<Props, State> {
title: 'Status',
description: get(info, 'status', NA),
},
{
title: 'Browser Type',
description: USES_HEADLESS_JOB_TYPES.includes(jobType)
? get(info, 'browser_type', UNKNOWN)
: NA,
},
],
};

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/reporting/public/lib/job_queue_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface JobContent {
}

export interface JobInfo {
browser_type: string;
created_at: string;
priority: number;
jobtype: string;
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/reporting/server/lib/enqueue_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { oncePerServer } from './once_per_server';

function enqueueJobFn(server) {
const jobQueue = server.plugins.reporting.queue;
const queueConfig = server.config().get('xpack.reporting.queue');
const config = server.config();
const queueConfig = config.get('xpack.reporting.queue');
const browserType = config.get('xpack.reporting.capture.browser.type');
const exportTypesRegistry = server.plugins.reporting.exportTypesRegistry;

return async function enqueueJob(exportTypeId, jobParams, user, headers, request) {
Expand All @@ -21,6 +23,7 @@ function enqueueJobFn(server) {
const options = {
timeout: queueConfig.timeout,
created_by: get(user, 'username', false),
browser_type: browserType,
};

return new Promise((resolve, reject) => {
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/reporting/server/lib/esqueue/__tests__/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ describe('Job Class', function () {
expect(indexArgs.body).to.have.property('priority', defaultPriority);
});
});

it('should set a browser type', function () {
const job = new Job(mockQueue, index, type, payload);
return job.ready.then(() => {
const indexArgs = validateDoc(client.index);
expect(indexArgs.body).to.have.property('browser_type');
});
});
});

describe('option passing', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const schema = {
},
}
},
browser_type: { type: 'keyword' },
jobtype: { type: 'keyword' },
payload: { type: 'object', enabled: false },
priority: { type: 'byte' },
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/reporting/server/lib/esqueue/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class Job extends events.EventEmitter {
this.priority = Math.max(Math.min(options.priority || 10, 20), -20);
this.doctype = options.doctype || constants.DEFAULT_SETTING_DOCTYPE;
this.indexSettings = options.indexSettings || {};
this.browser_type = options.browser_type;

this.debug = (msg, err) => {
const logger = options.logger || function () {};
Expand Down Expand Up @@ -66,6 +67,7 @@ export class Job extends events.EventEmitter {
attempts: 0,
max_attempts: this.maxAttempts,
status: constants.JOB_STATUS_PENDING,
browser_type: this.browser_type,
}
};

Expand Down Expand Up @@ -131,7 +133,8 @@ export class Job extends events.EventEmitter {
payload: this.payload,
timeout: this.timeout,
max_attempts: this.maxAttempts,
priority: this.priority
priority: this.priority,
browser_type: this.browser_type,
};
}
}

0 comments on commit d51b57a

Please sign in to comment.