fix bug that prevent index.mapping settings to be propagated into component templates from default settings (#157289)

## Summary

If you have a setting like `index.mapping.ignore_malformed`, in the
default settings, that is currently not propagated when a new component
template is built in the function `buildComponentTemplates` in Fleet


### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

---------

Co-authored-by: Kyle Pollich <kyle.pollich@elastic.co>
This commit is contained in:
Giuseppe Santoro 2023-05-10 21:39:08 +01:00 committed by GitHub
parent d391c669d9
commit 91a23941d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 3 deletions

View file

@ -581,7 +581,7 @@ export interface TemplateMapEntry {
mappings: NonNullable<RegistryElasticsearch['index_template.mappings']>;
}
| {
settings: NonNullable<RegistryElasticsearch['index_template.settings']> | object;
settings: NonNullable<RegistryElasticsearch['index_template.settings']>;
};
}

View file

@ -286,4 +286,45 @@ describe('EPM index template install', () => {
index: { mode: 'time_series' },
});
});
it('test prepareTemplate to set ignore_malformed in settings', () => {
const dataStream = {
type: 'logs',
dataset: 'package.dataset',
title: 'test data stream',
release: 'experimental',
package: 'package',
path: 'path',
ingest_pipeline: 'default',
elasticsearch: {
'index_template.settings': {
index: {
mapping: {
ignored_malformed: true,
},
},
},
},
} as RegistryDataStream;
const pkg = {
name: 'package',
version: '0.0.1',
};
const { componentTemplates } = prepareTemplate({
pkg,
dataStream,
});
const packageTemplate = componentTemplates['logs-package.dataset@package'].template;
if (!('settings' in packageTemplate)) {
throw new Error('no mappings on package template');
}
expect(packageTemplate.settings?.index?.mapping).toEqual(
expect.objectContaining({ ignored_malformed: true })
);
});
});

View file

@ -322,9 +322,9 @@ export function buildComponentTemplates(params: {
...templateSettings.index,
...(pipelineName ? { default_pipeline: pipelineName } : {}),
mapping: {
...templateSettings?.mapping,
...templateSettings.index?.mapping,
total_fields: {
...templateSettings?.mapping?.total_fields,
...templateSettings.index?.mapping?.total_fields,
limit: '10000',
},
},