Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Sep 22, 2021
1 parent f98c316 commit eb12721
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/plugins/usage_collection/server/routes/stats/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });
}
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/actions/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type CustomHostSettings = TypeOf<typeof customHostSettingsSchema>;
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(
Expand Down
22 changes: 19 additions & 3 deletions x-pack/plugins/actions/server/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ const applyStackAlertDeprecations = (settings: Record<string, unknown> = {}) =>
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,
};
};
Expand All @@ -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: [] });
});
});
});
16 changes: 7 additions & 9 deletions x-pack/plugins/actions/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,25 @@ export const config: PluginConfigDescriptor<ActionsConfig> = {
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) => {
const fullOldPath = 'xpack.actions.whitelistedHosts';
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);
Expand Down

0 comments on commit eb12721

Please sign in to comment.