From a543b04e03eb48e9fece09b36fc7a2369bd4d398 Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Tue, 31 Jul 2018 16:51:24 -0400 Subject: [PATCH 1/2] Default to chromium and add deprecation warning for phantom. --- docs/settings/reporting-settings.asciidoc | 5 ++- x-pack/plugins/reporting/index.js | 8 +++- .../server/browsers/browser_types.js | 8 ++++ .../server/browsers/default_browser.js | 38 +++++++++---------- .../reporting/server/browsers/index.js | 1 + 5 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 x-pack/plugins/reporting/server/browsers/browser_types.js diff --git a/docs/settings/reporting-settings.asciidoc b/docs/settings/reporting-settings.asciidoc index 52f7fc30bfc35..9be86f53852f2 100644 --- a/docs/settings/reporting-settings.asciidoc +++ b/docs/settings/reporting-settings.asciidoc @@ -76,8 +76,9 @@ Defaults to `3000` (3 seconds). [[xpack-reporting-browser]]`xpack.reporting.capture.browser.type`:: Specifies the browser to use to capture screenshots. Valid options are `phantom` and `chromium`. When `chromium` is set, the settings specified in the <> -are respected. -Defaults to `phantom`. +are respected. This setting will be deprecated in 7.0, when Phantom support is removed. +Defaults to `chromium`. + [float] [[reporting-chromium-settings]] diff --git a/x-pack/plugins/reporting/index.js b/x-pack/plugins/reporting/index.js index a00b2fcbc718a..fdf4948fb408d 100644 --- a/x-pack/plugins/reporting/index.js +++ b/x-pack/plugins/reporting/index.js @@ -15,7 +15,7 @@ import { config as appConfig } from './server/config/config'; import { checkLicenseFactory } from './server/lib/check_license'; import { validateConfig } from './server/lib/validate_config'; import { exportTypesRegistryFactory } from './server/lib/export_types_registry'; -import { createBrowserDriverFactory, getDefaultBrowser, getDefaultChromiumSandboxDisabled } from './server/browsers'; +import { PHANTOM, createBrowserDriverFactory, getDefaultBrowser, getDefaultChromiumSandboxDisabled } from './server/browsers'; import { logConfiguration } from './log_configuration'; import { getReportingUsageCollector } from './server/usage'; @@ -87,7 +87,7 @@ export const reporting = (kibana) => { settleTime: Joi.number().integer().default(1000), //deprecated concurrency: Joi.number().integer().default(appConfig.concurrency), //deprecated browser: Joi.object({ - type: Joi.any().valid('phantom', 'chromium').default(await getDefaultBrowser()), + type: Joi.any().valid('phantom', 'chromium').default(await getDefaultBrowser()), // TODO: remove support in 7.0 autoDownload: Joi.boolean().when('$dev', { is: true, then: Joi.default(true), @@ -145,6 +145,10 @@ export const reporting = (kibana) => { validateConfig(config, message => server.log(['reporting', 'warning'], message)); logConfiguration(config, message => server.log(['reporting', 'debug'], message)); + if (config.get('xpack.reporting.capture.browser.type') === PHANTOM) { + server.log(['reporting', 'warning'], 'Phantom browser type for reporting will be deprecated starting in 7.0'); + } + const { xpack_main: xpackMainPlugin } = server.plugins; mirrorPluginStatus(xpackMainPlugin, this); diff --git a/x-pack/plugins/reporting/server/browsers/browser_types.js b/x-pack/plugins/reporting/server/browsers/browser_types.js new file mode 100644 index 0000000000000..7cc691db47ae6 --- /dev/null +++ b/x-pack/plugins/reporting/server/browsers/browser_types.js @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const PHANTOM = 'phantom'; +export const CHROMIUM = 'chromium'; \ No newline at end of file diff --git a/x-pack/plugins/reporting/server/browsers/default_browser.js b/x-pack/plugins/reporting/server/browsers/default_browser.js index 4aeb72f89cb6f..87067b364b20a 100644 --- a/x-pack/plugins/reporting/server/browsers/default_browser.js +++ b/x-pack/plugins/reporting/server/browsers/default_browser.js @@ -4,30 +4,28 @@ * you may not use this file except in compliance with the Elastic License. */ -// import getosSync from 'getos'; -// import { promisify } from 'bluebird'; +import getosSync from 'getos'; +import { promisify } from 'bluebird'; +import { PHANTOM, CHROMIUM } from './browser_types'; -// const getos = promisify(getosSync); +const getos = promisify(getosSync); -// Chromium is unsupported on RHEL/CentOS before 7.0 -// const distroSupportsChromium = (distro, release) => { -// if (distro.toLowerCase() !== 'centos' && distro.toLowerCase () !== 'red hat linux') { -// return true; -// } -// const releaseNumber = parseInt(release, 10); -// return releaseNumber >= 7.0; -// }; +// Chromium is unsupported on RHEL/CentOS before 7.0. +const distroSupportsChromium = (distro, release) => { + if (distro.toLowerCase() !== 'centos' && distro.toLowerCase () !== 'red hat linux') { + return true; + } + const releaseNumber = parseInt(release, 10); + return releaseNumber >= 7.0; +}; export async function getDefaultBrowser() { - return 'phantom'; + const os = await getos(); - // TODO: Switch to chromium once all the kinks are worked out - // const os = await getos(); - // - // if (os.os === 'linux' && !distroSupportsChromium(os.dist, os.release)) { - // return 'phantom'; - // } else { - // return 'chromium'; - // } + if (os.os === 'linux' && !distroSupportsChromium(os.dist, os.release)) { + return PHANTOM; + } else { + return CHROMIUM; + } } diff --git a/x-pack/plugins/reporting/server/browsers/index.js b/x-pack/plugins/reporting/server/browsers/index.js index d1355cd7d9283..5dfe8aea8c3a0 100644 --- a/x-pack/plugins/reporting/server/browsers/index.js +++ b/x-pack/plugins/reporting/server/browsers/index.js @@ -8,3 +8,4 @@ export { ensureAllBrowsersDownloaded } from './download'; export { createBrowserDriverFactory } from './create_browser_driver_factory'; export { getDefaultBrowser } from './default_browser'; export { getDefaultChromiumSandboxDisabled } from './default_chromium_sandbox_disabled'; +export { PHANTOM, CHROMIUM } from './browser_types'; From 54039bfc64eb5b75380b8af89970ebcd41cbae10 Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Fri, 7 Sep 2018 09:43:42 -0400 Subject: [PATCH 2/2] use int, not float --- x-pack/plugins/reporting/server/browsers/default_browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/reporting/server/browsers/default_browser.js b/x-pack/plugins/reporting/server/browsers/default_browser.js index 87067b364b20a..1745bbdf74838 100644 --- a/x-pack/plugins/reporting/server/browsers/default_browser.js +++ b/x-pack/plugins/reporting/server/browsers/default_browser.js @@ -16,7 +16,7 @@ const distroSupportsChromium = (distro, release) => { return true; } const releaseNumber = parseInt(release, 10); - return releaseNumber >= 7.0; + return releaseNumber >= 7; };