[Index Template] Fix previewing data streams in template editor #140189
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
fix #139925
Currently, when you create a data stream template and try to use the "preview template" functionality, you'll simulate an index template without a data stream configuration because the data stream is configured using an empty object
{}
and existing code strips empty objects from the template during simulation:kibana/x-pack/plugins/index_management/public/application/components/index_templates/simulate_template/simulate_template.tsx
Line 38 in bc2a181
You can see this that by starting creating a data stream:
![Screenshot 2022-09-07 at 15 14 18](https://user-images.githubusercontent.com/7784120/188887507-fd325eca-e577-41f4-a32d-a27ad26b2717.png)
![Screenshot 2022-09-07 at 15 14 54](https://user-images.githubusercontent.com/7784120/188887572-ffdd9864-d8de-4095-b277-ba4bec1b1815.png)
And then use "preview" on the next step. See there is no
data_stream:{}
in thesimulate
request:This is problematic in cases where a configurion is valid for a data stream template, but invalid for a regular index template. I bumped into this while testing new time series streams in #138748
The fix makes simulation code to remove only empty strings, but leave empty objects untouched.
Please check if this is OK. Looks like all other places which pre-process template are already removing only empty strings. For example:
kibana/x-pack/plugins/index_management/public/application/components/template_form/template_form.tsx
Lines 228 to 230 in bc2a181
A safer alternative could be to make handling specific for
data_stream
key