From 9a1b4b9a6b5dcf480562c476635c814e408c892c Mon Sep 17 00:00:00 2001 From: Chris Roberson Date: Wed, 4 Mar 2020 09:27:23 -0500 Subject: [PATCH 1/2] [Monitoring] Ensure we use the monitoring cluster for retrieving xpack info (#59075) * Ensure we use the monitoring cluster for retrieving xpack info * Remove unnecessary code --- .../server/es_client/instantiate_client.js | 1 + .../server/init_monitoring_xpack_info.js | 19 +++++++--- .../elasticsearch/verify_monitoring_auth.js | 36 ++++++++++++------- .../plugins/monitoring/server/plugin.js | 4 ++- .../xpack_main/server/lib/setup_xpack_main.js | 9 ----- .../plugins/xpack_main/server/xpack_main.d.ts | 1 - 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/x-pack/legacy/plugins/monitoring/server/es_client/instantiate_client.js b/x-pack/legacy/plugins/monitoring/server/es_client/instantiate_client.js index 9aed1ac145617..671c6cdaaed70 100644 --- a/x-pack/legacy/plugins/monitoring/server/es_client/instantiate_client.js +++ b/x-pack/legacy/plugins/monitoring/server/es_client/instantiate_client.js @@ -25,6 +25,7 @@ export function exposeClient({ elasticsearchConfig, events, log, elasticsearchPl events.on('stop', bindKey(cluster, 'close')); const configSource = isMonitoringCluster ? 'monitoring' : 'production'; log([LOGGING_TAG, 'es-client'], `config sourced from: ${configSource} cluster`); + return cluster; } export function hasMonitoringCluster(config) { diff --git a/x-pack/legacy/plugins/monitoring/server/init_monitoring_xpack_info.js b/x-pack/legacy/plugins/monitoring/server/init_monitoring_xpack_info.js index ba07f512de896..7a6ab37798db6 100644 --- a/x-pack/legacy/plugins/monitoring/server/init_monitoring_xpack_info.js +++ b/x-pack/legacy/plugins/monitoring/server/init_monitoring_xpack_info.js @@ -7,15 +7,26 @@ import { checkLicenseGenerator } from './cluster_alerts/check_license'; import { hasMonitoringCluster } from './es_client/instantiate_client'; import { LOGGING_TAG } from '../common/constants'; +import { XPackInfo } from '../../xpack_main/server/lib/xpack_info'; /* * Expose xpackInfo for the Monitoring cluster as server.plugins.monitoring.info */ -export const initMonitoringXpackInfo = async ({ config, xpackMainPlugin, expose, log }) => { +export const initMonitoringXpackInfo = async ({ + config, + server, + client, + xpackMainPlugin, + licensing, + expose, + log, +}) => { const xpackInfo = hasMonitoringCluster(config) - ? xpackMainPlugin.createXPackInfo({ - clusterSource: 'monitoring', - pollFrequencyInMillis: config.get('monitoring.xpack_api_polling_frequency_millis'), + ? new XPackInfo(server, { + licensing: licensing.createLicensePoller( + client, + config.get('monitoring.xpack_api_polling_frequency_millis') + ), }) : xpackMainPlugin.info; diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js b/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js index 8362ebec0206b..96a0354556093 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js +++ b/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js @@ -38,19 +38,29 @@ export async function verifyMonitoringAuth(req) { async function verifyHasPrivileges(req) { const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring'); - const response = await callWithRequest(req, 'transport.request', { - method: 'POST', - path: '/_security/user/_has_privileges', - body: { - index: [ - { - names: [INDEX_PATTERN], // uses wildcard - privileges: ['read'], - }, - ], - }, - ignoreUnavailable: true, // we allow 404 incase the user shutdown security in-between the check and now - }); + let response; + try { + response = await callWithRequest(req, 'transport.request', { + method: 'POST', + path: '/_security/user/_has_privileges', + body: { + index: [ + { + names: [INDEX_PATTERN], // uses wildcard + privileges: ['read'], + }, + ], + }, + ignoreUnavailable: true, // we allow 404 incase the user shutdown security in-between the check and now + }); + } catch (err) { + if ( + err.message === 'no handler found for uri [/_security/user/_has_privileges] and method [POST]' + ) { + return; + } + throw err; + } // we assume true because, if the response 404ed, then it will not exist but we should try to continue const hasAllRequestedPrivileges = get(response, 'has_all_requested', true); diff --git a/x-pack/legacy/plugins/monitoring/server/plugin.js b/x-pack/legacy/plugins/monitoring/server/plugin.js index 3d6d110a01949..fa9f1ae699919 100644 --- a/x-pack/legacy/plugins/monitoring/server/plugin.js +++ b/x-pack/legacy/plugins/monitoring/server/plugin.js @@ -60,7 +60,7 @@ export class Plugin { const elasticsearchConfig = parseElasticsearchConfig(config); // Create the dedicated client - await instantiateClient({ + const client = await instantiateClient({ log, events, elasticsearchConfig, @@ -77,6 +77,8 @@ export class Plugin { if (uiEnabled) { await initMonitoringXpackInfo({ config, + server: hapiServer, + client, log, xpackMainPlugin: plugins.xpack_main, expose, diff --git a/x-pack/legacy/plugins/xpack_main/server/lib/setup_xpack_main.js b/x-pack/legacy/plugins/xpack_main/server/lib/setup_xpack_main.js index 21b781423531e..2707858a5fec8 100644 --- a/x-pack/legacy/plugins/xpack_main/server/lib/setup_xpack_main.js +++ b/x-pack/legacy/plugins/xpack_main/server/lib/setup_xpack_main.js @@ -19,15 +19,6 @@ export function setupXPackMain(server) { const info = new XPackInfo(server, { licensing: server.newPlatform.setup.plugins.licensing }); server.expose('info', info); - server.expose('createXPackInfo', options => { - const client = server.newPlatform.setup.core.elasticsearch.createClient(options.clusterSource); - const monitoringLicensing = server.newPlatform.setup.plugins.licensing.createLicensePoller( - client, - options.pollFrequencyInMillis - ); - - return new XPackInfo(server, { licensing: monitoringLicensing }); - }); server.ext('onPreResponse', (request, h) => injectXPackInfoSignature(info, request, h)); diff --git a/x-pack/legacy/plugins/xpack_main/server/xpack_main.d.ts b/x-pack/legacy/plugins/xpack_main/server/xpack_main.d.ts index 05cb97663e1af..a9abc733775d2 100644 --- a/x-pack/legacy/plugins/xpack_main/server/xpack_main.d.ts +++ b/x-pack/legacy/plugins/xpack_main/server/xpack_main.d.ts @@ -11,7 +11,6 @@ export { XPackFeature } from './lib/xpack_info'; export interface XPackMainPlugin { info: XPackInfo; - createXPackInfo(options: XPackInfoOptions): XPackInfo; getFeatures(): Feature[]; registerFeature(feature: FeatureWithAllOrReadPrivileges): void; } From 2361fe62cd6b241f75145e7ba436276c76cd0368 Mon Sep 17 00:00:00 2001 From: Bhavya RM Date: Wed, 4 Mar 2020 09:41:32 -0500 Subject: [PATCH 2/2] calling exitFullScreenMode in test (#59238) exitFullScreenMode in fullscreen dashboard test --- test/functional/apps/dashboard/full_screen_mode.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/functional/apps/dashboard/full_screen_mode.js b/test/functional/apps/dashboard/full_screen_mode.js index 69c0a05b8413b..df00f64530ca0 100644 --- a/test/functional/apps/dashboard/full_screen_mode.js +++ b/test/functional/apps/dashboard/full_screen_mode.js @@ -75,9 +75,7 @@ export default function({ getService, getPageObjects }) { }); it('exits when the text button is clicked on', async () => { - const logoButton = await PageObjects.dashboard.getExitFullScreenLogoButton(); - await logoButton.moveMouseTo(); - await PageObjects.dashboard.clickExitFullScreenTextButton(); + await PageObjects.dashboard.exitFullScreenMode(); await retry.try(async () => { const isChromeVisible = await PageObjects.common.isChromeVisible(); expect(isChromeVisible).to.be(true);