-
Notifications
You must be signed in to change notification settings - Fork 25k
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
System indices ignore all user templates #87260
Changes from 5 commits
8444d88
f95bd79
b319de0
fff1130
996e7cb
aa85a9c
d859145
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: 87260 | ||
summary: System indices ignore all user templates | ||
area: Infra/Core | ||
type: bug | ||
issues: [] | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.CollectionUtils; | ||
import org.elasticsearch.indices.SystemIndexDescriptor; | ||
import org.elasticsearch.indices.TestSystemIndexDescriptorAllowsTemplates; | ||
import org.elasticsearch.indices.TestSystemIndexPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.plugins.SystemIndexPlugin; | ||
|
@@ -167,40 +168,60 @@ public void testSystemIndicesAutoCreateRejectedWhenNotHidden() { | |
); | ||
} | ||
|
||
/** | ||
* Check that a template applying a system alias creates a hidden alias. | ||
*/ | ||
public void testAutoCreateSystemAliasViaV1Template() throws Exception { | ||
private String autoCreateSystemAliasViaV1Template(String indexName) throws Exception { | ||
assertAcked( | ||
client().admin() | ||
.indices() | ||
.preparePutTemplate("test-template") | ||
.setPatterns(List.of(INDEX_NAME + "*")) | ||
.addAlias(new Alias(INDEX_NAME + "-legacy-alias")) | ||
.setPatterns(List.of(indexName + "*")) | ||
.addAlias(new Alias(indexName + "-legacy-alias")) | ||
.get() | ||
); | ||
|
||
String nonPrimaryIndex = INDEX_NAME + "-2"; | ||
String nonPrimaryIndex = indexName + "-2"; | ||
CreateIndexRequest request = new CreateIndexRequest(nonPrimaryIndex); | ||
assertAcked(client().execute(AutoCreateAction.INSTANCE, request).get()); | ||
|
||
assertTrue(indexExists(nonPrimaryIndex)); | ||
|
||
assertAliasesHidden(nonPrimaryIndex, Set.of(".test-index", ".test-index-legacy-alias")); | ||
return nonPrimaryIndex; | ||
} | ||
|
||
/** | ||
* Check that a legacy template does not create an alias for a system index | ||
*/ | ||
public void testAutoCreateSystemAliasViaV1Template() throws Exception { | ||
var nonPrimaryIndex = autoCreateSystemAliasViaV1Template(INDEX_NAME); | ||
|
||
assertAliasesHidden(nonPrimaryIndex, Set.of(INDEX_NAME), 1); | ||
|
||
assertAcked(client().admin().indices().prepareDeleteTemplate("*").get()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, it looks like this line was copied - can you remove it from here as well? It's equally unnecessary. |
||
} | ||
|
||
/** | ||
* Check that a composable template applying a system alias creates a hidden alias. | ||
* Check that a legacy template does create an alias for a system index, because of allows templates | ||
*/ | ||
public void testAutoCreateSystemAliasViaComposableTemplate() throws Exception { | ||
public void testAutoCreateSystemAliasViaV1TemplateAllowsTemplates() throws Exception { | ||
var nonPrimaryIndex = autoCreateSystemAliasViaV1Template(TestSystemIndexDescriptorAllowsTemplates.INDEX_NAME); | ||
|
||
assertAliasesHidden( | ||
nonPrimaryIndex, | ||
Set.of( | ||
TestSystemIndexDescriptorAllowsTemplates.INDEX_NAME, | ||
TestSystemIndexDescriptorAllowsTemplates.INDEX_NAME + "-legacy-alias" | ||
), | ||
2 | ||
); | ||
|
||
assertAcked(client().admin().indices().prepareDeleteTemplate("*").get()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line isn't necessary, it's done in the |
||
} | ||
|
||
private String autoCreateSystemAliasViaComposableTemplate(String indexName) throws Exception { | ||
ComposableIndexTemplate cit = new ComposableIndexTemplate( | ||
Collections.singletonList(INDEX_NAME + "*"), | ||
Collections.singletonList(indexName + "*"), | ||
new Template( | ||
null, | ||
null, | ||
Map.of(INDEX_NAME + "-composable-alias", AliasMetadata.builder(INDEX_NAME + "-composable-alias").build()) | ||
Map.of(indexName + "-composable-alias", AliasMetadata.builder(indexName + "-composable-alias").build()) | ||
), | ||
Collections.emptyList(), | ||
4L, | ||
|
@@ -214,13 +235,45 @@ public void testAutoCreateSystemAliasViaComposableTemplate() throws Exception { | |
).get() | ||
); | ||
|
||
String nonPrimaryIndex = INDEX_NAME + "-2"; | ||
String nonPrimaryIndex = indexName + "-2"; | ||
CreateIndexRequest request = new CreateIndexRequest(nonPrimaryIndex); | ||
assertAcked(client().execute(AutoCreateAction.INSTANCE, request).get()); | ||
|
||
assertTrue(indexExists(nonPrimaryIndex)); | ||
|
||
assertAliasesHidden(nonPrimaryIndex, Set.of(".test-index", ".test-index-composable-alias")); | ||
return nonPrimaryIndex; | ||
} | ||
|
||
/** | ||
* Check that a composable template does not create an alias for a system index | ||
*/ | ||
public void testAutoCreateSystemAliasViaComposableTemplate() throws Exception { | ||
String nonPrimaryIndex = autoCreateSystemAliasViaComposableTemplate(INDEX_NAME); | ||
|
||
assertAliasesHidden(nonPrimaryIndex, Set.of(INDEX_NAME), 1); | ||
|
||
assertAcked( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure this is unnecessary as well despite not being explicitly in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm inclined to leave it, it does clean up the template explicitly and at the same time it tests we can clean up composable templates. |
||
client().execute( | ||
DeleteComposableIndexTemplateAction.INSTANCE, | ||
new DeleteComposableIndexTemplateAction.Request("test-composable-template") | ||
).get() | ||
); | ||
} | ||
|
||
/** | ||
* Check that a composable template does create an alias for a system index, because of allows templates | ||
*/ | ||
public void testAutoCreateSystemAliasViaComposableTemplateAllowsTemplates() throws Exception { | ||
String nonPrimaryIndex = autoCreateSystemAliasViaComposableTemplate(TestSystemIndexDescriptorAllowsTemplates.INDEX_NAME); | ||
|
||
assertAliasesHidden( | ||
nonPrimaryIndex, | ||
Set.of( | ||
TestSystemIndexDescriptorAllowsTemplates.INDEX_NAME, | ||
TestSystemIndexDescriptorAllowsTemplates.INDEX_NAME + "-composable-alias" | ||
), | ||
2 | ||
); | ||
|
||
assertAcked( | ||
client().execute( | ||
|
@@ -230,14 +283,15 @@ public void testAutoCreateSystemAliasViaComposableTemplate() throws Exception { | |
); | ||
} | ||
|
||
private void assertAliasesHidden(String nonPrimaryIndex, Set<String> aliasNames) throws InterruptedException, ExecutionException { | ||
private void assertAliasesHidden(String nonPrimaryIndex, Set<String> aliasNames, int aliasCount) throws InterruptedException, | ||
ExecutionException { | ||
final GetAliasesResponse getAliasesResponse = client().admin() | ||
.indices() | ||
.getAliases(new GetAliasesRequest().indicesOptions(IndicesOptions.strictExpandHidden())) | ||
.get(); | ||
|
||
assertThat(getAliasesResponse.getAliases().size(), equalTo(1)); | ||
assertThat(getAliasesResponse.getAliases().get(nonPrimaryIndex).size(), equalTo(2)); | ||
assertThat(getAliasesResponse.getAliases().get(nonPrimaryIndex).size(), equalTo(aliasCount)); | ||
assertThat( | ||
getAliasesResponse.getAliases().get(nonPrimaryIndex).stream().map(AliasMetadata::alias).collect(Collectors.toSet()), | ||
equalTo(aliasNames) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to add the relevant issue links here.