From 00a3edc9cb836994c930482db1594c12130f20b5 Mon Sep 17 00:00:00 2001 From: Joel Griffith Date: Tue, 27 Nov 2018 13:32:58 -0800 Subject: [PATCH 1/3] Adding in browser info to the report-info drawer --- .../reporting/public/components/report_info_button.tsx | 5 ++++- x-pack/plugins/reporting/public/lib/job_queue_client.ts | 1 + x-pack/plugins/reporting/server/lib/enqueue_job.js | 2 ++ .../plugins/reporting/server/lib/esqueue/__tests__/job.js | 8 ++++++++ .../reporting/server/lib/esqueue/helpers/create_index.js | 1 + x-pack/plugins/reporting/server/lib/esqueue/job.js | 5 ++++- 6 files changed, 20 insertions(+), 2 deletions(-) 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 4f8f330c6f5ee..599b081bd4896 100644 --- a/x-pack/plugins/reporting/public/components/report_info_button.tsx +++ b/x-pack/plugins/reporting/public/components/report_info_button.tsx @@ -73,7 +73,6 @@ export class ReportInfoButton extends Component { return null; } - // TODO browser type // TODO queue method (clicked UI, watcher, etc) const jobInfoParts = { datetimes: [ @@ -145,6 +144,10 @@ export class ReportInfoButton extends Component { title: 'Status', description: get(info, 'status', NA), }, + { + title: 'Browser Type', + description: get(info, 'browser_type', NA), + }, ], }; 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 5c979eebf21af..d5cdde62acfbd 100644 --- a/x-pack/plugins/reporting/public/lib/job_queue_client.ts +++ b/x-pack/plugins/reporting/public/lib/job_queue_client.ts @@ -21,6 +21,7 @@ export interface JobContent { } export interface JobInfo { + browser_type: string; created_at: string; priority: number; jobtype: string; diff --git a/x-pack/plugins/reporting/server/lib/enqueue_job.js b/x-pack/plugins/reporting/server/lib/enqueue_job.js index 53dd52c8e5a90..8ab0d98824cd6 100644 --- a/x-pack/plugins/reporting/server/lib/enqueue_job.js +++ b/x-pack/plugins/reporting/server/lib/enqueue_job.js @@ -11,6 +11,7 @@ import { oncePerServer } from './once_per_server'; function enqueueJobFn(server) { const jobQueue = server.plugins.reporting.queue; const queueConfig = server.config().get('xpack.reporting.queue'); + const browserType = server.config().get('xpack.reporting.capture.browser.type'); const exportTypesRegistry = server.plugins.reporting.exportTypesRegistry; return async function enqueueJob(exportTypeId, jobParams, user, headers, request) { @@ -21,6 +22,7 @@ function enqueueJobFn(server) { const options = { timeout: queueConfig.timeout, created_by: get(user, 'username', false), + browser_type: browserType, }; return new Promise((resolve, reject) => { diff --git a/x-pack/plugins/reporting/server/lib/esqueue/__tests__/job.js b/x-pack/plugins/reporting/server/lib/esqueue/__tests__/job.js index d928f82f3abb3..1bdc3589dbb3d 100644 --- a/x-pack/plugins/reporting/server/lib/esqueue/__tests__/job.js +++ b/x-pack/plugins/reporting/server/lib/esqueue/__tests__/job.js @@ -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 () { 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 f846d9fb2da0b..bf022ba7f98f4 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 @@ -41,6 +41,7 @@ const schema = { }, } }, + browser_type: { type: 'keyword' }, jobtype: { type: 'keyword' }, payload: { type: 'object', enabled: false }, priority: { type: 'byte' }, diff --git a/x-pack/plugins/reporting/server/lib/esqueue/job.js b/x-pack/plugins/reporting/server/lib/esqueue/job.js index 70cb32a551657..cf8eeacfbe92e 100644 --- a/x-pack/plugins/reporting/server/lib/esqueue/job.js +++ b/x-pack/plugins/reporting/server/lib/esqueue/job.js @@ -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 () {}; @@ -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, } }; @@ -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, }; } } From 66c0ef1357d134f3a43c4b517e46d995746fef54 Mon Sep 17 00:00:00 2001 From: Joel Griffith Date: Thu, 29 Nov 2018 10:52:09 -0800 Subject: [PATCH 2/3] Conditionalizes the browser-type panel prints + constantizes jobTypes --- x-pack/plugins/reporting/common/constants.ts | 5 +++++ .../plugins/reporting/export_types/csv/server/index.js | 3 ++- .../plugins/reporting/export_types/png/server/index.js | 3 ++- .../export_types/printable_pdf/server/index.js | 3 ++- .../reporting/public/components/report_info_button.tsx | 10 ++++++++-- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/reporting/common/constants.ts b/x-pack/plugins/reporting/common/constants.ts index a9df537c41d50..5268a1dd5329c 100644 --- a/x-pack/plugins/reporting/common/constants.ts +++ b/x-pack/plugins/reporting/common/constants.ts @@ -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]; diff --git a/x-pack/plugins/reporting/export_types/csv/server/index.js b/x-pack/plugins/reporting/export_types/csv/server/index.js index 4d3ee6912eaf2..f41f6ca9a1580 100644 --- a/x-pack/plugins/reporting/export_types/csv/server/index.js +++ b/x-pack/plugins/reporting/export_types/csv/server/index.js @@ -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, diff --git a/x-pack/plugins/reporting/export_types/png/server/index.js b/x-pack/plugins/reporting/export_types/png/server/index.js index cb60775dbb02d..65802491b89b1 100644 --- a/x-pack/plugins/reporting/export_types/png/server/index.js +++ b/x-pack/plugins/reporting/export_types/png/server/index.js @@ -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, diff --git a/x-pack/plugins/reporting/export_types/printable_pdf/server/index.js b/x-pack/plugins/reporting/export_types/printable_pdf/server/index.js index 909fe43999952..51caa8502acaa 100644 --- a/x-pack/plugins/reporting/export_types/printable_pdf/server/index.js +++ b/x-pack/plugins/reporting/export_types/printable_pdf/server/index.js @@ -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, 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 599b081bd4896..6168a2e2a8f6b 100644 --- a/x-pack/plugins/reporting/public/components/report_info_button.tsx +++ b/x-pack/plugins/reporting/public/components/report_info_button.tsx @@ -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 { @@ -32,6 +33,7 @@ interface State { } const NA = 'n/a'; +const UNKNOWN = 'unknown'; const getDimensions = (info: JobInfo) => { const defaultDimensions = { width: null, height: null }; @@ -73,6 +75,8 @@ export class ReportInfoButton extends Component { return null; } + const jobType = get(info, 'jobtype', NA); + // TODO queue method (clicked UI, watcher, etc) const jobInfoParts = { datetimes: [ @@ -116,7 +120,7 @@ export class ReportInfoButton extends Component { }, { title: 'Job Type', - description: get(info, 'jobtype', NA), + description: jobType, }, { title: 'Content Type', @@ -146,7 +150,9 @@ export class ReportInfoButton extends Component { }, { title: 'Browser Type', - description: get(info, 'browser_type', NA), + description: USES_HEADLESS_JOB_TYPES.includes(jobType) + ? get(info, 'browser_type', UNKNOWN) + : NA, }, ], }; From e73218fa26c0efed2c0465332bf8896c5ab4b55a Mon Sep 17 00:00:00 2001 From: Joel Griffith Date: Fri, 30 Nov 2018 09:52:47 -0800 Subject: [PATCH 3/3] Fixing config feedback lost in force push --- x-pack/plugins/reporting/server/lib/enqueue_job.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/reporting/server/lib/enqueue_job.js b/x-pack/plugins/reporting/server/lib/enqueue_job.js index 8ab0d98824cd6..0bd25e6265fd3 100644 --- a/x-pack/plugins/reporting/server/lib/enqueue_job.js +++ b/x-pack/plugins/reporting/server/lib/enqueue_job.js @@ -10,8 +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 browserType = server.config().get('xpack.reporting.capture.browser.type'); + 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) {