Skip to content

Commit

Permalink
Only log deprecation warning if xpack:defaultAdminEmail is actually s…
Browse files Browse the repository at this point in the history
…et (elastic#22774)

This PR fixes the logic for logging the deprecation warning introduced with elastic#22765. Previously Kibana would log the warning if the new `xpack.monitoring.cluster_alerts.email_notifications.email_address` setting was not defined, regardless of `xpack:defaultAdminEmail`'s setting.

Now, we will only log the deprecation warning if all of the following are true:
1) `xpack.monitoring.cluster_alerts.email_notifications.email_address` is not set.
2) `xpack:defaultAdminEmail` is set. (**<-- this is the new part**)
3) We haven't already logged the deprecation warning
  • Loading branch information
legrego committed Sep 7, 2018
1 parent da87111 commit e429571
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ describe('getSettingsCollector / getDefaultAdminEmail', () => {
sinon.assert.calledOnce(callCluster);
});

it('logs a deprecation warning', async () => {
it('does not log a deprecation warning', async () => {
const { config, callCluster, log } = setup({ docExists: false });
await getDefaultAdminEmail(config, callCluster, log);
sinon.assert.calledOnce(log.warn);
sinon.assert.notCalled(log.warn);
});
});

Expand All @@ -105,10 +105,10 @@ describe('getSettingsCollector / getDefaultAdminEmail', () => {
sinon.assert.calledOnce(callCluster);
});

it('logs a deprecation warning', async () => {
it('does not log a deprecation warning', async () => {
const { config, callCluster, log } = setup({ defaultAdminEmail: false });
await getDefaultAdminEmail(config, callCluster, log);
sinon.assert.calledOnce(log.warn);
sinon.assert.notCalled(log.warn);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ export async function getDefaultAdminEmail(config, callCluster, log) {
}

// DEPRECATED (Remove below in 7.0): If an email address is not configured in kibana.yml, then fallback to xpack:defaultAdminEmail
if (!loggedDeprecationWarning) {
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);
loggedDeprecationWarning = true;
}

const index = config.get('kibana.index');
const version = config.get('pkg.version');
Expand All @@ -50,7 +41,19 @@ export async function getDefaultAdminEmail(config, callCluster, log) {
ignore: [400, 404] // 400 if the index is closed, 404 if it does not exist
});

return get(uiSettingsDoc, ['_source', 'config', XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING], null);
const emailAddress = get(uiSettingsDoc, ['_source', 'config', XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING], null);

if (emailAddress && !loggedDeprecationWarning) {
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);
loggedDeprecationWarning = true;
}

return emailAddress;
}

// we use shouldUseNull to determine if we need to send nulls; we only send nulls if the last email wasn't null
Expand Down

0 comments on commit e429571

Please sign in to comment.