From eb127218efa60dab37bc405d33c7c3e2e2fa7eab Mon Sep 17 00:00:00 2001 From: chrisronline Date: Wed, 22 Sep 2021 13:44:31 -0400 Subject: [PATCH] PR feedback --- .../server/routes/stats/stats.ts | 2 +- x-pack/plugins/actions/server/config.ts | 2 +- x-pack/plugins/actions/server/index.test.ts | 22 ++++++++++++++++--- x-pack/plugins/actions/server/index.ts | 16 ++++++-------- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/plugins/usage_collection/server/routes/stats/stats.ts b/src/plugins/usage_collection/server/routes/stats/stats.ts index 6cae56afa281b..f1998ec391ab4 100644 --- a/src/plugins/usage_collection/server/routes/stats/stats.ts +++ b/src/plugins/usage_collection/server/routes/stats/stats.ts @@ -103,7 +103,7 @@ export function registerStatsRoute({ if (shouldGetUsage) { const collectorsReady = await collectorSet.areAllCollectorsReady(); if (!collectorsReady) { - return res.customError({ statusCode: 503, body: { message: STATS_NOT_READY_MESSAGE } }); + // return res.customError({ statusCode: 503, body: { message: STATS_NOT_READY_MESSAGE } }); } } diff --git a/x-pack/plugins/actions/server/config.ts b/x-pack/plugins/actions/server/config.ts index a288c54bb0b0a..f4539c93352ec 100644 --- a/x-pack/plugins/actions/server/config.ts +++ b/x-pack/plugins/actions/server/config.ts @@ -59,7 +59,7 @@ export type CustomHostSettings = TypeOf; export const configSchema = schema.object({ enabled: schema.boolean({ defaultValue: true }), /** - * @deprecated in favor of `allowedHostsj` + * @deprecated in favor of `allowedHosts` **/ whitelistedHosts: schema.maybe( schema.arrayOf( diff --git a/x-pack/plugins/actions/server/index.test.ts b/x-pack/plugins/actions/server/index.test.ts index dbe8fca806f17..f23ddcb3a611a 100644 --- a/x-pack/plugins/actions/server/index.test.ts +++ b/x-pack/plugins/actions/server/index.test.ts @@ -14,18 +14,20 @@ const applyStackAlertDeprecations = (settings: Record = {}) => const _config = { [CONFIG_PATH]: settings, }; - const { config: migrated } = applyDeprecations( + const { config: migrated, changedPaths } = applyDeprecations( _config, deprecations.map((deprecation) => ({ deprecation, path: CONFIG_PATH, })), () => - ({ message }) => - deprecationMessages.push(message) + ({ message }) => { + deprecationMessages.push(message); + } ); return { messages: deprecationMessages, + changedPaths, migrated, }; }; @@ -40,5 +42,19 @@ describe('index', () => { ] `); }); + + it('should perform a custom set on deprecated and removed configs', () => { + jest.spyOn(configDeprecationFactory, 'renameFromRoot'); + + const { changedPaths } = applyStackAlertDeprecations({ + whitelistedHosts: ['smtp.gmail.com'], + }); + + expect(configDeprecationFactory.renameFromRoot).toHaveBeenCalledWith( + 'xpack.actions.whitelistedHosts', + 'xpack.actions.allowedHosts' + ); + expect(changedPaths).toStrictEqual({ set: ['xpack.actions.allowedHosts'], unset: [] }); + }); }); }); diff --git a/x-pack/plugins/actions/server/index.ts b/x-pack/plugins/actions/server/index.ts index 1be2f4f75746b..fa0a5801c985c 100644 --- a/x-pack/plugins/actions/server/index.ts +++ b/x-pack/plugins/actions/server/index.ts @@ -61,7 +61,7 @@ export const config: PluginConfigDescriptor = { rejectUnauthorized: true, proxyRejectUnauthorizedCertificates: true, }, - deprecations: ({ renameFromRoot, unused }) => [ + deprecations: ({ renameFromRoot, unused, rename }) => [ // Use a custom copy function here so we can perserve the telemetry provided for the deprecated config // See https://github.com/elastic/kibana/issues/112585#issuecomment-923715363 (settings, fromPath, addDeprecation) => { @@ -69,19 +69,17 @@ export const config: PluginConfigDescriptor = { const fullNewPath = 'xpack.actions.allowedHosts'; const actions = get(settings, fromPath); const whitelistedHosts = actions?.whitelistedHosts; + const renameFn = renameFromRoot(fullOldPath, fullNewPath); + const result = renameFn(settings, fromPath, addDeprecation); + + // If it is set, make sure we return custom logic to ensure the usage is tracked if (whitelistedHosts) { - addDeprecation({ - message: `Setting "${fullOldPath}" has been replaced by "${fullNewPath}"`, - correctiveActions: { - manualSteps: [ - `Replace "${fullOldPath}" with "${fullNewPath}" in the Kibana config file, CLI flag, or environment variable (in Docker only).`, - ], - }, - }); return { set: [{ path: fullNewPath, value: whitelistedHosts }], }; } + + return result; }, (settings, fromPath, addDeprecation) => { const actions = get(settings, fromPath);