-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Composable templates] Improve support for customizing settings and mappings for groups of data streams #92426
Comments
Pinging @elastic/es-data-management (Team:Data Management) |
I did play around a bit with the Elasticsearch code. Commenting out the following lines has the effect that validation does not happen: I suggest we take inspiration from #87354 and add a config option
Happy to open a pull request with the proposed change in case the team agrees. |
As described in elastic#92426 a config option to not ignore missing component templates is needed. This introduces the config option `ignore_missing_component_templates`. If set to true, missing component templates are ignored. If set to false or not set at all, the existing behaviour applies. This is currently a draft PR as it only contains the functionality. It still needs tests and docs. Goal is to get an initial set of opinions on it.
I put up a draft PR with the change implemented: #92436 Misses test, docs etc. and I'm sure I missed a few bits that also need to be changed but so far it seems to be working. |
I like having it as a property of the template rather than a request-time parameter. From the Fleet side, I'm +1 on this direction. |
@ruflin I am working on a set of proposals for us to discuss and decide between. Today and Monday are holidays in the US, so we can discuss sometime next week. |
We discussed some possible solutions for this. I'll put the discussed options here: Option 1 — keep things the way they areAlways an option, we could keep the template stuff the same way it currently works. Instead, we could potentially invest time into making templates easier to manage, improving the UX without adding additional leniency. Pros Option 2 — total leniencyThis is the option the Fleet team suggested in the linked Github issue. In this option the existence of component templates is not required. If a component template does not exist at template or index creation time, it will be silently ignored. Pros Option 3 — template-specific leniencyIn this option (proposed PR), rather than making all component template existence lenient, we would allow the user to opt-in to leniency with a setting put on the composable index template itself. An example of what this could look like is (ignore the naming):
If this setting is set to 'true', then any missing component template will be ignored for this index template only. Templates without this setting, or with the setting set to false, would still require the existence of all of their component templates. Pros Option 4 — name-based leniencyFor this option, rather than leniency for all component templates, Elasticsearch would codify the component template naming scheme along with its leniency. This means that any component template ending with "@Custom" would leniently be ignored if it does not exist. In the following example:
The two bolded component templates, "logs@custom" and "global@custom", may optionally exist. If they do not exist, then they will be leniently ignored. Pros Option 5 — template-specific and name-based leniencyThis is a combination of options 3 and 4, to reduce the leniency further. For this proposal the non-existence of component templates ending with "@Custom" will be treated leniently only if the template setting is set to opt-in to the lenient behavior. For example:
The existence of "logs@custom" and "global@custom" will behave leniently because the "ignore_missing_custom_component_templates" (naming to be determined later) settings has been set to "true". Pros Option 6 — specify which templates can be optionalFor this option, instead of either hardcoding the name of the templates that can be missing, or adding leniency for all component templates, the user/package specifies which component templates are allowed to be missing. The list could be either concrete names, or support rudimentary wildcards (so "*@Custom" could be allowed.)
The existence of "logs@custom" and "global@custom" will behave leniently because all "*@Custom" component templates are allowed to be missing. Pros After discussing this on the Data Management team, we decided that we like option 6 the best. |
@ruflin are you still interested in the implementation for this? (i.e., the implementation of option 6, which is only slightly different than your existing PR) If you are, great! If not let me know and I can see where it will fit into our existing work. |
++ on option 6. Happy to take on the implementation on my end. I suggest to implement option 6 in two steps:
@dakrone Is that ok for you and team? |
++ to option 6. Updating the existing templates will not necessarily be an issue for Fleet's use case. We already have a versioning scheme on package installations to be able to detect when we need to reinstall templates due to a change like this. |
@ruflin that implementation plan sounds great to me, thanks for taking it on. |
#92436 is now in pretty good shape. Functionality wise it all works as expected but likely code still needs a bit of cleanup. Would be great to get some initial feedback. |
This change introduces the configuration option `ignore_missing_component_templates` as discussed in #92426 The implementation [option 6](#92426 (comment)) was picked with a slight adjustment meaning no patterns are allowed. ## Implementation During the creation of an index template, the list of component templates is checked if all component templates exist. This check is extended to skip any component templates which are listed under `ignore_missing_component_templates`. An index template that skips the check for the component template `logs-foo@custom` looks as following: ``` PUT _index_template/logs-foo { "index_patterns": ["logs-foo-*"], "data_stream": { }, "composed_of": ["logs-foo@package", "logs-foo@custom"], "ignore_missing_component_templates": ["logs-foo@custom"], "priority": 500 } ``` The component template `logs-foo@package` has to exist before creation. It can be created with: ``` PUT _component_template/logs-foo@custom { "template": { "mappings": { "properties": { "host.ip": { "type": "ip" } } } } } ``` ## Testing For manual testing, different scenarios can be tested. To simplify testing, the commands from `.http` file are added. Before each test run, a clean cluster is expected. ### New behaviour, missing component template With the new config option, it must be possible to create an index template with a missing component templates without getting an error: ``` ### Add logs-foo@package component template PUT http://localhost:9200/ _component_template/logs-foo@package Authorization: Basic elastic password Content-Type: application/json { "template": { "mappings": { "properties": { "host.name": { "type": "keyword" } } } } } ### Add logs-foo index template PUT http://localhost:9200/ _index_template/logs-foo Authorization: Basic elastic password Content-Type: application/json { "index_patterns": ["logs-foo-*"], "data_stream": { }, "composed_of": ["logs-foo@package", "logs-foo@custom"], "ignore_missing_component_templates": ["logs-foo@custom"], "priority": 500 } ### Create data stream PUT http://localhost:9200/ _data_stream/logs-foo-bar Authorization: Basic elastic password Content-Type: application/json ### Check if mappings exist GET http://localhost:9200/ logs-foo-bar Authorization: Basic elastic password Content-Type: application/json ``` It is checked if all templates could be created and data stream mappings are correct. ### Old behaviour, with all component templates In the following, a component template is made optional but it already exists. It is checked, that it will show up in the mappings: ``` ### Add logs-foo@package component template PUT http://localhost:9200/ _component_template/logs-foo@package Authorization: Basic elastic password Content-Type: application/json { "template": { "mappings": { "properties": { "host.name": { "type": "keyword" } } } } } ### Add logs-foo@custom component template PUT http://localhost:9200/ _component_template/logs-foo@custom Authorization: Basic elastic password Content-Type: application/json { "template": { "mappings": { "properties": { "host.ip": { "type": "ip" } } } } } ### Add logs-foo index template PUT http://localhost:9200/ _index_template/logs-foo Authorization: Basic elastic password Content-Type: application/json { "index_patterns": ["logs-foo-*"], "data_stream": { }, "composed_of": ["logs-foo@package", "logs-foo@custom"], "ignore_missing_component_templates": ["logs-foo@custom"], "priority": 500 } ### Create data stream PUT http://localhost:9200/ _data_stream/logs-foo-bar Authorization: Basic elastic password Content-Type: application/json ### Check if mappings exist GET http://localhost:9200/ logs-foo-bar Authorization: Basic elastic password Content-Type: application/json ``` ### Check old behaviour Ensure, that the old behaviour still exists when a component template is used that is not part of `ignore_missing_component_templates`: ``` ### Add logs-foo index template PUT http://localhost:9200/ _index_template/logs-foo Authorization: Basic elastic password Content-Type: application/json { "index_patterns": ["logs-foo-*"], "data_stream": { }, "composed_of": ["logs-foo@package", "logs-foo@custom"], "ignore_missing_component_templates": ["logs-foo@custom"], "priority": 500 } ``` Co-authored-by: Lee Hinman <[email protected]>
This has been resolved by #92436, so I'm closing this issue as fixed. |
This change introduces the configuration option `ignore_missing_component_templates` as discussed in elastic#92426 The implementation [option 6](elastic#92426 (comment)) was picked with a slight adjustment meaning no patterns are allowed. ## Implementation During the creation of an index template, the list of component templates is checked if all component templates exist. This check is extended to skip any component templates which are listed under `ignore_missing_component_templates`. An index template that skips the check for the component template `logs-foo@custom` looks as following: ``` PUT _index_template/logs-foo { "index_patterns": ["logs-foo-*"], "data_stream": { }, "composed_of": ["logs-foo@package", "logs-foo@custom"], "ignore_missing_component_templates": ["logs-foo@custom"], "priority": 500 } ``` The component template `logs-foo@package` has to exist before creation. It can be created with: ``` PUT _component_template/logs-foo@custom { "template": { "mappings": { "properties": { "host.ip": { "type": "ip" } } } } } ``` ## Testing For manual testing, different scenarios can be tested. To simplify testing, the commands from `.http` file are added. Before each test run, a clean cluster is expected. ### New behaviour, missing component template With the new config option, it must be possible to create an index template with a missing component templates without getting an error: ``` ### Add logs-foo@package component template PUT http://localhost:9200/ _component_template/logs-foo@package Authorization: Basic elastic password Content-Type: application/json { "template": { "mappings": { "properties": { "host.name": { "type": "keyword" } } } } } ### Add logs-foo index template PUT http://localhost:9200/ _index_template/logs-foo Authorization: Basic elastic password Content-Type: application/json { "index_patterns": ["logs-foo-*"], "data_stream": { }, "composed_of": ["logs-foo@package", "logs-foo@custom"], "ignore_missing_component_templates": ["logs-foo@custom"], "priority": 500 } ### Create data stream PUT http://localhost:9200/ _data_stream/logs-foo-bar Authorization: Basic elastic password Content-Type: application/json ### Check if mappings exist GET http://localhost:9200/ logs-foo-bar Authorization: Basic elastic password Content-Type: application/json ``` It is checked if all templates could be created and data stream mappings are correct. ### Old behaviour, with all component templates In the following, a component template is made optional but it already exists. It is checked, that it will show up in the mappings: ``` ### Add logs-foo@package component template PUT http://localhost:9200/ _component_template/logs-foo@package Authorization: Basic elastic password Content-Type: application/json { "template": { "mappings": { "properties": { "host.name": { "type": "keyword" } } } } } ### Add logs-foo@custom component template PUT http://localhost:9200/ _component_template/logs-foo@custom Authorization: Basic elastic password Content-Type: application/json { "template": { "mappings": { "properties": { "host.ip": { "type": "ip" } } } } } ### Add logs-foo index template PUT http://localhost:9200/ _index_template/logs-foo Authorization: Basic elastic password Content-Type: application/json { "index_patterns": ["logs-foo-*"], "data_stream": { }, "composed_of": ["logs-foo@package", "logs-foo@custom"], "ignore_missing_component_templates": ["logs-foo@custom"], "priority": 500 } ### Create data stream PUT http://localhost:9200/ _data_stream/logs-foo-bar Authorization: Basic elastic password Content-Type: application/json ### Check if mappings exist GET http://localhost:9200/ logs-foo-bar Authorization: Basic elastic password Content-Type: application/json ``` ### Check old behaviour Ensure, that the old behaviour still exists when a component template is used that is not part of `ignore_missing_component_templates`: ``` ### Add logs-foo index template PUT http://localhost:9200/ _index_template/logs-foo Authorization: Basic elastic password Content-Type: application/json { "index_patterns": ["logs-foo-*"], "data_stream": { }, "composed_of": ["logs-foo@package", "logs-foo@custom"], "ignore_missing_component_templates": ["logs-foo@custom"], "priority": 500 } ``` Co-authored-by: Lee Hinman <[email protected]>
Why
Integration users want to be able to define mappings and index settings that get applied to different groups of indices, at different levels of granularity:
*
)logs-*
)*-nginx.*-*
)logs-nginx.access-*
) - we support this todaylogs-nginx.access-foo
)*-*-foo
)Today, Fleet will install integrations with an empty
<type>-<dataset>@custom
component template that users can use to override any index setting mapping or mapping defined by the package. This only solves one of the levels of granularity desired, and adding additional component templates at each possible level will lead to explosion in the number of templates Fleet creates, the vast majority of which will be empty, creating a poor UX in the template UIs and APIs.We want to find another solution that would not lead to this explosion of templates.
Proposed solution: Make composable template existence optional
Today if you try to create an index template that references a component template that does not exist in the
composedOf
field, Elasticsearch will return a 400 error. This solution would add a new option to allow some templates to not exist at creation of the index template. This would allow the user or Fleet to create initialize index templates that reference component templates for different levels of granularity that will only be applied once the template is actually exists. For instance (just a demonstration, the precedence here is debatable still):Pros:
Cons:
logs-nginx.access-foo@custom
will not do anything.The text was updated successfully, but these errors were encountered: