Skip to content

Commit

Permalink
[Fleet] Fix config migration from ingestManager to support both xpack…
Browse files Browse the repository at this point in the history
….fleet and xpack.ingestManager config values (elastic#111612) (elastic#111714)

Co-authored-by: Nicolas Chaulet <[email protected]>
  • Loading branch information
kibanamachine and nchaulet authored Sep 9, 2021
1 parent d82c54f commit 99789fe
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 3 deletions.
79 changes: 79 additions & 0 deletions x-pack/plugins/fleet/server/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { applyDeprecations, configDeprecationFactory } from '@kbn/config';

import { config } from '.';

const applyConfigDeprecations = (settings: Record<string, any> = {}) => {
if (!config.deprecations) {
throw new Error('Config is not valid no deprecations');
}
const deprecations = config.deprecations(configDeprecationFactory);
const deprecationMessages: string[] = [];
const migrated = applyDeprecations(
settings,
deprecations.map((deprecation) => ({
deprecation,
path: '',
})),
() => ({ message }) => deprecationMessages.push(message)
);
return {
messages: deprecationMessages,
migrated: migrated.config,
};
};

describe('Config depreciation test', () => {
it('should migrate old xpack.ingestManager.fleet settings to xpack.fleet.agents', () => {
const { migrated } = applyConfigDeprecations({
xpack: {
ingestManager: {
fleet: { enabled: true, elasticsearch: { host: 'http://testes.fr:9200' } },
},
},
});

expect(migrated).toMatchInlineSnapshot(`
Object {
"xpack": Object {
"fleet": Object {
"agents": Object {
"elasticsearch": Object {
"hosts": Array [
"http://testes.fr:9200",
],
},
"enabled": true,
},
},
},
}
`);
});

it('should support mixing xpack.ingestManager config and xpack.fleet config', () => {
const { migrated } = applyConfigDeprecations({
xpack: {
ingestManager: { registryUrl: 'http://registrytest.fr' },
fleet: { registryProxyUrl: 'http://registryProxy.fr' },
},
});

expect(migrated).toMatchInlineSnapshot(`
Object {
"xpack": Object {
"fleet": Object {
"registryProxyUrl": "http://registryProxy.fr",
"registryUrl": "http://registrytest.fr",
},
},
}
`);
});
});
35 changes: 32 additions & 3 deletions x-pack/plugins/fleet/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,45 @@ export const config: PluginConfigDescriptor = {
epm: true,
agents: true,
},
deprecations: ({ renameFromRoot, unused }) => [
renameFromRoot('xpack.ingestManager', 'xpack.fleet'),
renameFromRoot('xpack.fleet.fleet', 'xpack.fleet.agents'),
deprecations: ({ renameFromRoot, unused, unusedFromRoot }) => [
// Fleet plugin was named ingestManager before
renameFromRoot('xpack.ingestManager.enabled', 'xpack.fleet.enabled'),
renameFromRoot('xpack.ingestManager.registryUrl', 'xpack.fleet.registryUrl'),
renameFromRoot('xpack.ingestManager.registryProxyUrl', 'xpack.fleet.registryProxyUrl'),
renameFromRoot('xpack.ingestManager.fleet', 'xpack.ingestManager.agents'),
renameFromRoot('xpack.ingestManager.agents.enabled', 'xpack.fleet.agents.enabled'),
renameFromRoot('xpack.ingestManager.agents.elasticsearch', 'xpack.fleet.agents.elasticsearch'),
renameFromRoot(
'xpack.ingestManager.agents.tlsCheckDisabled',
'xpack.fleet.agents.tlsCheckDisabled'
),
renameFromRoot(
'xpack.ingestManager.agents.pollingRequestTimeout',
'xpack.fleet.agents.pollingRequestTimeout'
),
renameFromRoot(
'xpack.ingestManager.agents.maxConcurrentConnections',
'xpack.fleet.agents.maxConcurrentConnections'
),
renameFromRoot('xpack.ingestManager.agents.kibana', 'xpack.fleet.agents.kibana'),
renameFromRoot(
'xpack.ingestManager.agents.agentPolicyRolloutRateLimitIntervalMs',
'xpack.fleet.agents.agentPolicyRolloutRateLimitIntervalMs'
),
renameFromRoot(
'xpack.ingestManager.agents.agentPolicyRolloutRateLimitRequestPerInterval',
'xpack.fleet.agents.agentPolicyRolloutRateLimitRequestPerInterval'
),
unusedFromRoot('xpack.ingestManager'),
// Unused settings before Fleet server exists
unused('agents.kibana'),
unused('agents.maxConcurrentConnections'),
unused('agents.agentPolicyRolloutRateLimitIntervalMs'),
unused('agents.agentPolicyRolloutRateLimitRequestPerInterval'),
unused('agents.pollingRequestTimeout'),
unused('agents.tlsCheckDisabled'),
unused('agents.fleetServerEnabled'),
// Renaming elasticsearch.host => elasticsearch.hosts
(fullConfig, fromPath, addDeprecation) => {
const oldValue = fullConfig?.xpack?.fleet?.agents?.elasticsearch?.host;
if (oldValue) {
Expand Down

0 comments on commit 99789fe

Please sign in to comment.