Skip to content
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

Downgrade template update error to a warning for v1 templates #55611

Merged
merged 2 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -575,38 +575,21 @@ static ClusterState innerPutTemplate(final ClusterState currentState, PutRequest
if (request.create && isUpdate) {
throw new IllegalArgumentException("index_template [" + request.name + "] already exists");
}
boolean isUpdateAndPatternsAreUnchanged = isUpdate &&
currentState.metadata().templates().get(request.name).patterns().equals(request.indexPatterns);

Map<String, List<String>> overlaps = findConflictingV2Templates(currentState, request.name, request.indexPatterns);
if (overlaps.size() > 0) {
// Be less strict (just a warning) if we're updating an existing template or this is a match-all template
if (isUpdateAndPatternsAreUnchanged || request.indexPatterns.stream().anyMatch(Regex::isMatchAllPattern)) {
String warning = String.format(Locale.ROOT, "template [%s] has index patterns %s matching patterns" +
" from existing index templates [%s] with patterns (%s); this template [%s] may be ignored in favor of " +
"an index template at index creation time",
request.name,
request.indexPatterns,
Strings.collectionToCommaDelimitedString(overlaps.keySet()),
overlaps.entrySet().stream()
.map(e -> e.getKey() + " => " + e.getValue())
.collect(Collectors.joining(",")),
request.name);
logger.warn(warning);
deprecationLogger.deprecatedAndMaybeLog("index_template_pattern_overlap", warning);
} else {
// Otherwise, this is a hard error, the user should use V2 index templates instead
String error = String.format(Locale.ROOT, "template [%s] has index patterns %s matching patterns" +
" from existing index templates [%s] with patterns (%s), use index templates (/_index_template) instead",
request.name,
request.indexPatterns,
Strings.collectionToCommaDelimitedString(overlaps.keySet()),
overlaps.entrySet().stream()
.map(e -> e.getKey() + " => " + e.getValue())
.collect(Collectors.joining(",")));
logger.error(error);
throw new IllegalArgumentException(error);
}
String warning = String.format(Locale.ROOT, "template [%s] has index patterns %s matching patterns" +
" from existing index templates [%s] with patterns (%s); this template [%s] may be ignored in favor of " +
"an index template at index creation time",
request.name,
request.indexPatterns,
Strings.collectionToCommaDelimitedString(overlaps.keySet()),
overlaps.entrySet().stream()
.map(e -> e.getKey() + " => " + e.getValue())
.collect(Collectors.joining(",")),
request.name);
logger.warn(warning);
deprecationLogger.deprecatedAndMaybeLog("index_template_pattern_overlap", warning);
}

templateBuilder.order(request.order);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,24 +484,20 @@ public void testPuttingV1StarTemplateGeneratesWarning() throws Exception {
}

/**
* Test that if we have a pre-existing v2 template and put a v1 template that would match the same indices, we generate a hard error
* Test that if we have a pre-existing v2 template and put a v1 template that would match the same indices, we generate a warning
*/
public void testPuttingV1NonStarTemplateGeneratesError() throws Exception {
public void testPuttingV1NonStarTemplateGeneratesWarning() throws Exception {
final MetadataIndexTemplateService metadataIndexTemplateService = getMetadataIndexTemplateService();
IndexTemplateV2 v2Template = new IndexTemplateV2(Arrays.asList("foo-bar-*", "eggplant"), null, null, null, null, null);
ClusterState state = metadataIndexTemplateService.addIndexTemplateV2(ClusterState.EMPTY_STATE, false, "v2-template", v2Template);

MetadataIndexTemplateService.PutRequest req = new MetadataIndexTemplateService.PutRequest("cause", "v1-template");
req.patterns(Arrays.asList("egg*", "baz"));
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> MetadataIndexTemplateService.innerPutTemplate(state, req, IndexTemplateMetadata.builder("v1-template")));

assertThat(e.getMessage(),
equalTo("template [v1-template] has index patterns [egg*, baz] matching patterns from existing index " +
"templates [v2-template] with patterns (v2-template => [foo-bar-*, eggplant]), use index templates " +
"(/_index_template) instead"));
MetadataIndexTemplateService.innerPutTemplate(state, req, IndexTemplateMetadata.builder("v1-template"));

assertNull(state.metadata().templates().get("v1-template"));
assertWarnings("template [v1-template] has index patterns [egg*, baz] matching patterns " +
"from existing index templates [v2-template] with patterns (v2-template => [foo-bar-*, eggplant]);" +
" this template [v1-template] may be ignored in favor of an index template at index creation time");
}

/**
Expand Down Expand Up @@ -547,9 +543,9 @@ public void testUpdatingV1NonStarTemplateWithUnchangedPatternsGeneratesWarning()

/**
* Test that if we have a pre-existing v1 and v2 template, and we update the existing v1
* template *AND* change the index patterns that an error is generated
* template *AND* change the index patterns that a warning is generated
*/
public void testUpdatingV1NonStarWithChangedPatternsTemplateGeneratesError() throws Exception {
public void testUpdatingV1NonStarWithChangedPatternsTemplateGeneratesWarning() throws Exception {
final MetadataIndexTemplateService metadataIndexTemplateService = getMetadataIndexTemplateService();
IndexTemplateMetadata v1Template = IndexTemplateMetadata.builder("v1-template")
.patterns(Arrays.asList("fo*", "baz"))
Expand All @@ -576,12 +572,11 @@ public void testUpdatingV1NonStarWithChangedPatternsTemplateGeneratesError() thr
MetadataIndexTemplateService.PutRequest req = new MetadataIndexTemplateService.PutRequest("cause", "v1-template");
req.patterns(Arrays.asList("egg*", "baz"));
final ClusterState finalState = state;
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> MetadataIndexTemplateService.innerPutTemplate(finalState, req, IndexTemplateMetadata.builder("v1-template")));
MetadataIndexTemplateService.innerPutTemplate(finalState, req, IndexTemplateMetadata.builder("v1-template"));

assertThat(e.getMessage(), equalTo("template [v1-template] has index patterns [egg*, baz] matching patterns " +
"from existing index templates [v2-template] with patterns (v2-template => [foo-bar-*, eggplant]), use index " +
"templates (/_index_template) instead"));
assertWarnings("template [v1-template] has index patterns [egg*, baz] matching patterns " +
"from existing index templates [v2-template] with patterns (v2-template => [foo-bar-*, eggplant]); " +
"this template [v1-template] may be ignored in favor of an index template at index creation time");
}

public void testPuttingOverlappingV2Template() throws Exception {
Expand Down