[Fleet] Fix config migration from ingestManager to support both xpack.fleet and xpack.ingestManager config values (#111612)

This commit is contained in:
Nicolas Chaulet 2021-09-09 08:39:18 -04:00 committed by GitHub
parent dd69697517
commit a1a717862b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 111 additions and 3 deletions

View file

@ -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",
},
},
}
`);
});
});

View file

@ -38,9 +38,37 @@ 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'),
@ -48,6 +76,7 @@ export const config: PluginConfigDescriptor = {
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) {