From fb47f968c62b53f322f1133e0ca712d1c94b6359 Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Mon, 29 Jun 2020 20:25:41 -0400 Subject: [PATCH 1/5] Added deprecated tag to the advanced settings --- docs/management/advanced-options.asciidoc | 3 ++- src/core/public/doc_links/doc_links_service.ts | 1 + x-pack/legacy/plugins/xpack_main/index.js | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/management/advanced-options.asciidoc b/docs/management/advanced-options.asciidoc index 3d15b0504e85c..0aad6c2f6c385 100644 --- a/docs/management/advanced-options.asciidoc +++ b/docs/management/advanced-options.asciidoc @@ -103,7 +103,8 @@ Example: `{ "display": "15 seconds", "pause": true, "value": 15000 }`. `timepicker:timeDefaults`:: The default selection in the time filter. `truncate:maxHeight`:: The maximum height that a cell occupies in a table. Set to 0 to disable truncation. -`xPack:defaultAdminEmail`:: Email address for X-Pack admin operations, such as +`xPack:defaultAdminEmail`:: **Deprecated. Use <> instead.** +Email address for X-Pack admin operations, such as cluster alert notifications from Monitoring. diff --git a/src/core/public/doc_links/doc_links_service.ts b/src/core/public/doc_links/doc_links_service.ts index 0662586797164..759995c417b6f 100644 --- a/src/core/public/doc_links/doc_links_service.ts +++ b/src/core/public/doc_links/doc_links_service.ts @@ -123,6 +123,7 @@ export class DocLinksService { dateMath: `${ELASTICSEARCH_DOCS}common-options.html#date-math`, }, management: { + kibanaGeneralSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-general-settings`, kibanaSearchSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-search-settings`, dashboardSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-dashboard-settings`, }, diff --git a/x-pack/legacy/plugins/xpack_main/index.js b/x-pack/legacy/plugins/xpack_main/index.js index 547ea3b50282b..7dce595839977 100644 --- a/x-pack/legacy/plugins/xpack_main/index.js +++ b/x-pack/legacy/plugins/xpack_main/index.js @@ -52,6 +52,13 @@ export const xpackMain = (kibana) => { defaultMessage: 'Recipient email address for X-Pack admin operations, such as Cluster Alert email notifications from Monitoring.', }), + deprecation: { + message: i18n.translate('xpack.main.uiSettings.adminEmailDeprecation', { + defaultMessage: + 'This setting is deprecated and will not be supported in Kibana 7.0. Please configure `xpack.monitoring.cluster_alerts.email_notifications.email_address` in your kibana.yml settings.', + }), + docLinksKey: 'kibanaGeneralSettings', + }, type: 'string', // TODO: Any way of ensuring this is a valid email address? value: null, }, From 50739f08948fc3d4ae8c188cfb977e951b44936c Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Thu, 2 Jul 2020 03:11:16 -0400 Subject: [PATCH 2/5] Addressed code feedback --- x-pack/legacy/plugins/xpack_main/index.js | 2 +- x-pack/plugins/monitoring/common/constants.ts | 1 + .../monitoring/server/core_services.ts | 48 +++++++++++++++++++ .../collectors/get_settings_collector.ts | 37 ++++++++++++-- x-pack/plugins/monitoring/server/plugin.ts | 3 ++ 5 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 x-pack/plugins/monitoring/server/core_services.ts diff --git a/x-pack/legacy/plugins/xpack_main/index.js b/x-pack/legacy/plugins/xpack_main/index.js index 7dce595839977..20b0357f59dad 100644 --- a/x-pack/legacy/plugins/xpack_main/index.js +++ b/x-pack/legacy/plugins/xpack_main/index.js @@ -55,7 +55,7 @@ export const xpackMain = (kibana) => { deprecation: { message: i18n.translate('xpack.main.uiSettings.adminEmailDeprecation', { defaultMessage: - 'This setting is deprecated and will not be supported in Kibana 7.0. Please configure `xpack.monitoring.cluster_alerts.email_notifications.email_address` in your kibana.yml settings.', + 'This setting is deprecated and will not be supported in Kibana 7.0. Please configure `monitoring.cluster_alerts.email_notifications.email_address` in your kibana.yml settings.', }), docLinksKey: 'kibanaGeneralSettings', }, diff --git a/x-pack/plugins/monitoring/common/constants.ts b/x-pack/plugins/monitoring/common/constants.ts index eeed7b4d5acf6..b781740bed7ad 100644 --- a/x-pack/plugins/monitoring/common/constants.ts +++ b/x-pack/plugins/monitoring/common/constants.ts @@ -258,5 +258,6 @@ export const NUMBER_OF_MIGRATED_ALERTS = 2; * The advanced settings config name for the email address */ export const MONITORING_CONFIG_ALERTING_EMAIL_ADDRESS = 'monitoring:alertingEmailAddress'; +export const XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING = 'xPack:defaultAdminEmail'; export const ALERT_EMAIL_SERVICES = ['gmail', 'hotmail', 'icloud', 'outlook365', 'ses', 'yahoo']; diff --git a/x-pack/plugins/monitoring/server/core_services.ts b/x-pack/plugins/monitoring/server/core_services.ts new file mode 100644 index 0000000000000..54fbbf310b188 --- /dev/null +++ b/x-pack/plugins/monitoring/server/core_services.ts @@ -0,0 +1,48 @@ +/* + * 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. + */ + +import { CoreStart, CoreSetup } from 'kibana/server'; + +import { SavedObjectsClient } from '../../../../src/core/server'; + +export class CoreServices { + private static _coreSetup: CoreSetup; + private static _coreStart: CoreStart; + + public static init(core: CoreSetup) { + this._coreSetup = core; + } + + public static get coreSetup(): CoreSetup { + this.checkError(); + return this._coreSetup; + } + + public static async getCoreStart(): Promise { + if (this._coreStart) { + return this._coreStart; + } + const [coreStart] = await this.coreSetup.getStartServices(); + this._coreStart = coreStart; + return coreStart; + } + + public static async getUISetting(key: string) { + const coreStart = await this.getCoreStart(); + const { savedObjects, uiSettings } = coreStart; + const savedObjectsClient = new SavedObjectsClient(savedObjects.createInternalRepository()); + const theSettings = uiSettings.asScopedToClient(savedObjectsClient); + return await theSettings.get(key); + } + + private static checkError() { + if (!this._coreSetup) { + throw new Error( + 'CoreServices has not been initialized. Please run CoreServices.init(...) before use' + ); + } + } +} diff --git a/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts index 1b7c127f64286..8e90f250b5cd3 100644 --- a/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts @@ -4,15 +4,41 @@ * you may not use this file except in compliance with the Elastic License. */ -import { KIBANA_SETTINGS_TYPE } from '../../../common/constants'; +import { + KIBANA_SETTINGS_TYPE, + XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING, + CLUSTER_ALERTS_ADDRESS_CONFIG_KEY, +} from '../../../common/constants'; import { MonitoringConfig } from '../../config'; +import { CoreServices } from '../../core_services'; +import { Logger } from '../../../../../../src/core/server'; +let loggedDeprecationWarning = false; /* * Check if Cluster Alert email notifications is enabled in config * If so, use uiSettings API to fetch the X-Pack default admin email */ -export async function getDefaultAdminEmail(config: MonitoringConfig) { - return config.cluster_alerts.email_notifications.email_address || null; +export async function getDefaultAdminEmail(config: MonitoringConfig, log?: Logger) { + const { + email_notifications: { enabled, email_address: emailAddresss }, + } = config.cluster_alerts; + + if (enabled && emailAddresss?.length) { + return emailAddresss; + } + + const defaultAdminEmail = await CoreServices.getUISetting(XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING); + + if (defaultAdminEmail && !loggedDeprecationWarning && log) { + const emailAddressConfigKey = `monitoring.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}`; + loggedDeprecationWarning = true; + const message = + `Monitoring is using "${XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING}" for cluster alert notifications, ` + + `which will not be supported in Kibana 7.0. Please configure ${emailAddressConfigKey} in your kibana.yml settings`; + log.warn(message); + } + + return defaultAdminEmail; } // we use shouldUseNull to determine if we need to send nulls; we only send nulls if the last email wasn't null @@ -21,9 +47,10 @@ let shouldUseNull = true; export async function checkForEmailValue( config: MonitoringConfig, _shouldUseNull = shouldUseNull, - _getDefaultAdminEmail = getDefaultAdminEmail + _getDefaultAdminEmail = getDefaultAdminEmail, + log?: Logger ) { - const defaultAdminEmail = await _getDefaultAdminEmail(config); + const defaultAdminEmail = await _getDefaultAdminEmail(config, log); // Allow null so clearing the advanced setting will be reflected in the data const isAcceptableNull = defaultAdminEmail === null && _shouldUseNull; diff --git a/x-pack/plugins/monitoring/server/plugin.ts b/x-pack/plugins/monitoring/server/plugin.ts index ad2a5b7bb1ce2..240a8397de4e6 100644 --- a/x-pack/plugins/monitoring/server/plugin.ts +++ b/x-pack/plugins/monitoring/server/plugin.ts @@ -52,6 +52,7 @@ import { import { getLicenseExpiration } from './alerts/license_expiration'; import { getClusterState } from './alerts/cluster_state'; import { InfraPluginSetup } from '../../infra/server'; +import { CoreServices } from './core_services'; export interface LegacyAPI { getServerStatus: () => string; @@ -131,6 +132,8 @@ export class Plugin { .pipe(first()) .toPromise(); + CoreServices.init(core); + this.legacyShimDependencies = { router: core.http.createRouter(), instanceUuid: core.uuid.getInstanceUuid(), From f0623bdc54330f32ea44ac301211fd531af5ee9b Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Thu, 2 Jul 2020 14:54:14 -0400 Subject: [PATCH 3/5] Code feedback --- x-pack/legacy/plugins/xpack_main/index.js | 2 +- .../collectors/get_settings_collector.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/xpack_main/index.js b/x-pack/legacy/plugins/xpack_main/index.js index 20b0357f59dad..1fb91043576ba 100644 --- a/x-pack/legacy/plugins/xpack_main/index.js +++ b/x-pack/legacy/plugins/xpack_main/index.js @@ -55,7 +55,7 @@ export const xpackMain = (kibana) => { deprecation: { message: i18n.translate('xpack.main.uiSettings.adminEmailDeprecation', { defaultMessage: - 'This setting is deprecated and will not be supported in Kibana 7.0. Please configure `monitoring.cluster_alerts.email_notifications.email_address` in your kibana.yml settings.', + 'This setting is deprecated and will not be supported in Kibana 8.0. Please configure `monitoring.cluster_alerts.email_notifications.email_address` in your kibana.yml settings.', }), docLinksKey: 'kibanaGeneralSettings', }, diff --git a/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts index 8e90f250b5cd3..7e04d4b34f63c 100644 --- a/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts @@ -20,11 +20,11 @@ let loggedDeprecationWarning = false; */ export async function getDefaultAdminEmail(config: MonitoringConfig, log?: Logger) { const { - email_notifications: { enabled, email_address: emailAddresss }, + email_notifications: { enabled, email_address: emailAddress }, } = config.cluster_alerts; - if (enabled && emailAddresss?.length) { - return emailAddresss; + if (enabled && emailAddress?.length) { + return emailAddress; } const defaultAdminEmail = await CoreServices.getUISetting(XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING); @@ -34,7 +34,7 @@ export async function getDefaultAdminEmail(config: MonitoringConfig, log?: Logge loggedDeprecationWarning = true; const message = `Monitoring is using "${XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING}" for cluster alert notifications, ` + - `which will not be supported in Kibana 7.0. Please configure ${emailAddressConfigKey} in your kibana.yml settings`; + `which will not be supported in Kibana 8.0. Please configure ${emailAddressConfigKey} in your kibana.yml settings`; log.warn(message); } From 78cd7c474e7f3158845318ad7ec0f745db4d6c20 Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Mon, 6 Jul 2020 00:08:25 -0400 Subject: [PATCH 4/5] Code feedback --- x-pack/plugins/monitoring/server/deprecations.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/monitoring/server/deprecations.ts b/x-pack/plugins/monitoring/server/deprecations.ts index d40837885e198..ee8d050deb049 100644 --- a/x-pack/plugins/monitoring/server/deprecations.ts +++ b/x-pack/plugins/monitoring/server/deprecations.ts @@ -44,10 +44,13 @@ export const deprecations = ({ ), renameFromRoot('xpack.monitoring', 'monitoring'), (config, fromPath, logger) => { - const clusterAlertsEnabled = get(config, 'cluster_alerts.enabled'); + const clusterAlertsEnabled = get(config, 'monitoring.cluster_alerts.enabled', true); const emailNotificationsEnabled = - clusterAlertsEnabled && get(config, 'cluster_alerts.email_notifications.enabled'); - if (emailNotificationsEnabled && !get(config, CLUSTER_ALERTS_ADDRESS_CONFIG_KEY)) { + clusterAlertsEnabled && + get(config, 'monitoring.cluster_alerts.email_notifications.enabled', true); + const updatedKey = get(config, `monitoring.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}`); + const legacyKey = get(config, `xpack.monitoring.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}`); + if (emailNotificationsEnabled && !updatedKey && !legacyKey) { logger( `Config key [${fromPath}.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}] will be required for email notifications to work in 7.0."` ); From 0bbc68930c1a0b7f8275fad8f28b5fd37397cfde Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Mon, 6 Jul 2020 11:02:12 -0400 Subject: [PATCH 5/5] Fixed version --- x-pack/plugins/monitoring/server/deprecations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/monitoring/server/deprecations.ts b/x-pack/plugins/monitoring/server/deprecations.ts index ee8d050deb049..71b54313f3193 100644 --- a/x-pack/plugins/monitoring/server/deprecations.ts +++ b/x-pack/plugins/monitoring/server/deprecations.ts @@ -52,7 +52,7 @@ export const deprecations = ({ const legacyKey = get(config, `xpack.monitoring.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}`); if (emailNotificationsEnabled && !updatedKey && !legacyKey) { logger( - `Config key [${fromPath}.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}] will be required for email notifications to work in 7.0."` + `Config key [${fromPath}.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}] will be required for email notifications to work in 8.0."` ); } return config;