Fix plugin deprecations (#29737) (#29985)

* [deprecations] convert flattened settings to nested settings

* [deprecations] reuse rename method for elasticsearch.url to elasticsearch.hosts

* newline

* add known issues to docs
This commit is contained in:
Jonathan Budzenski 2019-02-05 18:21:25 -06:00 committed by GitHub
parent 890b2c00ec
commit f60e17d2c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 3 deletions

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { difference } from 'lodash';
import { difference, get, set } from 'lodash';
import { transformDeprecations } from './transform_deprecations';
import { unset, formatListAsProse, getFlattenedObject } from '../../utils';
import { getTransform } from '../../deprecation';
@ -39,9 +39,13 @@ async function getUnusedConfigKeys(
const { spec } = plugins[i];
const transform = await getTransform(spec);
const prefix = spec.getConfigPrefix();
const pluginSettings = settings[prefix];
// nested plugin prefixes (a.b) translate to nested objects
const pluginSettings = get(settings, prefix);
if (pluginSettings) {
settings[prefix] = transform(pluginSettings);
// flattened settings are expected to be converted to nested objects
// a.b = true => { a: { b: true }}
set(settings, prefix, transform(pluginSettings));
}
}

View file

@ -252,6 +252,41 @@ describe('server/config completeMixin()', function () {
await expect(callCompleteMixin()).resolves.toBe(undefined);
});
it('should transform deeply nested deprecated plugin settings', async () => {
const { callCompleteMixin } = setup({
settings: {
xpack: {
monitoring: {
elasticsearch: {
url: 'http://localhost:9200'
}
}
}
},
configValues: {
xpack: {
monitoring: {
elasticsearch: {
hosts: 'http://localhost:9200'
}
}
}
},
plugins: [
{
spec: {
getDeprecationsProvider() {
return async ({ rename }) => [rename('elasticsearch.url', 'elasticsearch.hosts')];
},
getConfigPrefix: () => 'xpack.monitoring'
}
}
],
});
await expect(callCompleteMixin()).resolves.toBe(undefined);
});
});
describe('disabled plugins', () => {