Validate global V2 templates don't set index.hidden#55010
Validate global V2 templates don't set index.hidden#55010andreidan merged 6 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/es-core-features (:Core/Features/Indices APIs) |
.../main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateV2Action.java
Outdated
Show resolved
Hide resolved
.../main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateV2Action.java
Outdated
Show resolved
Hide resolved
...java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateV2RequestTests.java
Show resolved
Hide resolved
|
Thanks @andreidan for working on this, I've added 2 request around |
|
We could probably also add validation to |
|
@dakrone sure, I'll add that validation in this PR |
probakowski
left a comment
There was a problem hiding this comment.
LGTM, thanks @andreidan !
|
@elasticmachine update branch |
This also prevents updating the component template to add the index.hidden setting if that ct is referenced by a global index template.
|
@dakrone made the changes to prevent the I didn't use the |
|
@dakrone @probakowski this probably slipped off your radar. do you have any more thoughts/suggestions on this? |
probakowski
left a comment
There was a problem hiding this comment.
LGTM, thanks @andreidan! I left few comments but they are purely subjective and can be skipped
| // if we're updating a component template, let's check if it's part of any V2 template that will yield the CT update invalid | ||
| if (create == false && finalSettings != null) { | ||
| // if the CT is specifying the `index.hidden` setting it cannot be part of any global template | ||
| if (IndexMetadata.INDEX_HIDDEN_SETTING.exists(finalSettings)) { |
There was a problem hiding this comment.
I don't think that'd be necessarily more readable (especially in the context of maybe us wanting to add more checks, this index.hidden one being just one condition we identified now). If it's ok, I'll leave it like this now
There was a problem hiding this comment.
You definitely can leave it as it is, as I said this totally my personal preference only
| List<String> globalTemplatesThatUseThisComponent = new ArrayList<>(); | ||
| for (Map.Entry<String, IndexTemplateV2> entry : existingTemplates.entrySet()) { | ||
| IndexTemplateV2 templateV2 = entry.getValue(); | ||
| if (templateV2.composedOf().contains(name) && templateV2.indexPatterns().stream().anyMatch(Regex::isMatchAllPattern)) { | ||
| // global templates don't support configuring the `index.hidden` setting so we don't need to resolve the settings as | ||
| // no other component template can remove this setting from the resolved settings, so just invalidate this update | ||
| globalTemplatesThatUseThisComponent.add(entry.getKey()); | ||
| } | ||
| } |
There was a problem hiding this comment.
This can be replaced with stream version, which for me is more readable:
List<String> globalTemplatesThatUseThisComponent = currentState.metadata().templatesV2().entrySet().stream()
.filter(e -> e.getValue().composedOf().contains(name))
.filter(e -> e.getValue().indexPatterns().stream().anyMatch(Regex::isMatchAllPattern))
.map(Map.Entry::getKey)
.collect(Collectors.toList());There was a problem hiding this comment.
I'm not sure about this, to me they're equally readable, but your option is a bit more concise.
In the interest of moving this rather stale PR forward I'm merging it as it is and we can refactor it later if that's ok?
Validate adding global V2 templates don't configure the index.hidden setting. This also prevents updating the component template to add the index.hidden setting if that component template is referenced by a global index template. (cherry picked from commit 2e76898) Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
…55519) Validate adding global V2 templates don't configure the index.hidden setting. This also prevents updating the component template to add the index.hidden setting if that component template is referenced by a global index template. (cherry picked from commit 2e76898) Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
No description provided.