-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Add ignore_missing_component_templates config option
#92436
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
Changes from 18 commits
866dbbd
5aaa91b
3befa9b
21ca694
d4a6c31
5b8a46f
ab46b1b
64e141f
1a18d50
0512edf
5dd2ee7
c28b24b
9c68539
1cd0127
29a34fb
71ae211
23559c0
0374941
91b1837
d5ff03a
54c4a3d
84c4a57
9e40dd3
157ba01
7fa7ab8
824be38
1d84c00
7a66bf3
cc9cc5c
1de49ca
973c49f
072c81a
da7e66d
cc824c5
2bb57f5
f12afe8
57a9ce9
55ef4bc
0f64578
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 92436 | ||
| summary: Add `ignore_missing_component_templates` config option | ||
| area: "Data streams, Indices APIs" | ||
| type: enhancement | ||
| issues: [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| [[ignore_missing_component_templates]] | ||
| == Config ignore_missing_component_templates | ||
|
|
||
| The configuration option `ignore_missing_component_templates` can be used when an index template references a component template that might not exist yet. Every time a data stream is create based on the index template, the existance of the component template will be checked. If it exists, it will taken as part of the mapping. If it does not exist, it is ignored. | ||
|
|
||
| === Usage example | ||
|
|
||
| In the following, one component template and an index template are created. The index template references 2 component templates but only the `@package` one exists. | ||
ruflin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| Create of the component template `logs-foo@package`. This has to be created before the index template as it is not optional: | ||
ruflin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [source,console] | ||
| ---- | ||
| PUT _component_template/logs-foo@package | ||
| { | ||
| "template": { | ||
| "mappings": { | ||
| "properties": { | ||
| "host.name": { | ||
| "type": "keyword" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ---- | ||
|
|
||
| The index template is now created and and it references two component templates: | ||
|
||
|
|
||
| [source,JSON] | ||
| ---- | ||
| "composed_of": ["logs-foo@package", "logs-foo@custom"] | ||
| ---- | ||
|
|
||
| Before, only the `logs-foo@package` compontent template was created, meaning the `logs-foo@custom` is missing. Because of this the following entry was added to the config: | ||
ruflin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [source,JSON] | ||
| ---- | ||
| "ignore_missing_component_templates": ["logs-foo@custom"], | ||
| ---- | ||
|
|
||
| During creation of the template, it will not validate that `logs-foo@custom` exists: | ||
|
|
||
|
|
||
| [source,console] | ||
| ---- | ||
| 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 | ||
| } | ||
| ---- | ||
| // TEST[continued] | ||
|
|
||
| The index template `logs-foo` was successfully created. A data stream can be created based on this template: | ||
|
|
||
| [source,console] | ||
| ---- | ||
| PUT _data_stream/logs-foo-bar | ||
| ---- | ||
| // TEST[continued] | ||
|
|
||
| Looking at the mappings of the data stream, it will contain the `host.name` field. | ||
|
|
||
| At a later stage, the missing component template might be added: | ||
|
|
||
| [source,console] | ||
| ---- | ||
| PUT _component_template/logs-foo@custom | ||
| { | ||
| "template": { | ||
| "mappings": { | ||
| "properties": { | ||
| "host.ip": { | ||
| "type": "ip" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ---- | ||
| // TEST[continued] | ||
|
|
||
| This will not have an immediate effect on the data stream. The mapping `host.ip` will only show up in the data stream mappings when the data stream is rolled over automatically next time or a manual rollover is triggered: | ||
|
|
||
| [source,console] | ||
| ---- | ||
| POST logs-foo-bar/_rollover | ||
| ---- | ||
| // TEST[continued] | ||
ruflin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // TEST[teardown:data_stream_cleanup] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -510,7 +510,27 @@ public static void validateV2TemplateRequest(Metadata metadata, String name, Com | |
| .filter(componentTemplate -> componentTemplates.containsKey(componentTemplate) == false) | ||
| .toList(); | ||
|
|
||
| if (missingComponentTemplates.size() > 0) { | ||
| // TODO: Should the code be split up in two parts for better error messages? If ignore_missing_component_templates is not set | ||
| // it throws a different error? | ||
ruflin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| final List<String> ignoreMissingComponentTemplates = template.getIgnoreMissingComponentTemplates(); | ||
ruflin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Check | ||
| if (ignoreMissingComponentTemplates != null && ignoreMissingComponentTemplates.size() > 0) { | ||
| for (String missingComponentTemplate : missingComponentTemplates) { | ||
| // TODO if ignoreMissingComponentTemplates not set, jump directly out | ||
| if (ignoreMissingComponentTemplates.contains(missingComponentTemplate) == false) { | ||
| throw new InvalidIndexTemplateException( | ||
| name, | ||
| // TODO: should we make the code more complex and only error out in the end to have the full list reported? | ||
| "index template [" | ||
| + name | ||
| + "] specifies a missing component templates [" | ||
| + missingComponentTemplate | ||
| + "] that does not exist and is not part of 'ignore_missing_component_templates'" | ||
|
||
| ); | ||
| } | ||
| } | ||
| } else if (missingComponentTemplates.size() > 0) { | ||
| throw new InvalidIndexTemplateException( | ||
| name, | ||
| "index template [" + name + "] specifies component templates " + missingComponentTemplates + " that do not exist" | ||
|
|
@@ -579,7 +599,8 @@ public ClusterState addIndexTemplateV2( | |
| template.version(), | ||
| template.metadata(), | ||
| template.getDataStreamTemplate(), | ||
| template.getAllowAutoCreate() | ||
| template.getAllowAutoCreate(), | ||
| template.getIgnoreMissingComponentTemplates() | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -679,7 +700,8 @@ private void validateIndexTemplateV2(String name, ComposableIndexTemplate indexT | |
| indexTemplate.version(), | ||
| indexTemplate.metadata(), | ||
| indexTemplate.getDataStreamTemplate(), | ||
| indexTemplate.getAllowAutoCreate() | ||
| indexTemplate.getAllowAutoCreate(), | ||
| indexTemplate.getIgnoreMissingComponentTemplates() | ||
| ); | ||
|
|
||
| validate(name, templateToValidate); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.