Skip to content

Commit

Permalink
[Monitoring] Added deprecated tag to the advanced settings for xPack:…
Browse files Browse the repository at this point in the history
…defaultAdminEmail (#70280)

* Added deprecated tag to the advanced settings

* Addressed code feedback

* Code feedback

* Code feedback

* Fixed version

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
igoristic and elasticmachine authored Jul 7, 2020
1 parent d539af5 commit 58e64af
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 10 deletions.
3 changes: 2 additions & 1 deletion docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<cluster-alert-email-notifications,Email Notifications>> instead.**
Email address for X-Pack admin operations, such as
cluster alert notifications from Monitoring.


Expand Down
1 change: 1 addition & 0 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
},
Expand Down
7 changes: 7 additions & 0 deletions x-pack/legacy/plugins/xpack_main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 8.0. Please configure `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,
},
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
48 changes: 48 additions & 0 deletions x-pack/plugins/monitoring/server/core_services.ts
Original file line number Diff line number Diff line change
@@ -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<CoreStart> {
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'
);
}
}
}
11 changes: 7 additions & 4 deletions x-pack/plugins/monitoring/server/deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ 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."`
`Config key [${fromPath}.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}] will be required for email notifications to work in 8.0."`
);
}
return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: emailAddress },
} = config.cluster_alerts;

if (enabled && emailAddress?.length) {
return emailAddress;
}

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 8.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
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/monitoring/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -131,6 +132,8 @@ export class Plugin {
.pipe(first())
.toPromise();

CoreServices.init(core);

this.legacyShimDependencies = {
router: core.http.createRouter(),
instanceUuid: core.uuid.getInstanceUuid(),
Expand Down

0 comments on commit 58e64af

Please sign in to comment.