-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Fix config migration from ingestManager to support both xpack…
….fleet and xpack.ingestManager config values (#111612) (#111714) Co-authored-by: Nicolas Chaulet <[email protected]>
- Loading branch information
1 parent
d82c54f
commit 99789fe
Showing
2 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters