Skip to content

Commit 797f63e

Browse files
authored
[7.x] Emit deprecation warning if multiple v1 templates match with a new index (#55558) (#56038)
* Emit deprecation warning if multiple v1 templates match with a new index (#55558) * Emit deprecation warning if multiple v1 templates match with a new index * DEPRECATION_LOGGER rename
1 parent fc6422f commit 797f63e

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/60_typed_keys.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
setup:
2+
- skip:
3+
features: allowed_warnings
24
- do:
35
indices.put_template:
46
name: index_template
@@ -18,6 +20,8 @@ setup:
1820
type: keyword
1921

2022
- do:
23+
allowed_warnings:
24+
- "index [test-0] matches multiple v1 templates [global, index_template], v2 index templates will only match a single index template"
2125
bulk:
2226
refresh: true
2327
body:

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ public ClusterState applyCreateIndexRequest(ClusterState currentState, CreateInd
342342
final List<IndexTemplateMetadata> v1Templates = MetadataIndexTemplateService.findV1Templates(currentState.metadata(),
343343
request.index(), isHiddenFromRequest);
344344

345+
if (v1Templates.size() > 1) {
346+
DEPRECATION_LOGGER.deprecatedAndMaybeLog("index_template_multiple_match", "index [{}] matches multiple v1 templates " +
347+
"[{}], v2 index templates will only match a single index template", request.index(),
348+
v1Templates.stream().map(IndexTemplateMetadata::name).sorted().collect(Collectors.joining(", ")));
349+
}
350+
345351
return applyCreateIndexRequestWithV1Templates(currentState, request, silent, v1Templates, metadataTransformer);
346352
}
347353
}

server/src/test/java/org/elasticsearch/indices/template/TemplatePreferenceIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ public void testRolloverMaintainsSetting() throws Exception {
235235
resp.getSetting(INDEX + "-000002", "index.priority"), equalTo("23"));
236236
client().admin().indices().prepareDelete(INDEX + "*").get();
237237
}
238+
239+
assertWarnings("index [index-000002] matches multiple v1 templates [one_shard_index_template, " +
240+
"random-soft-deletes-template, v1], v2 index templates will only match a single index template");
238241
}
239242

240243
private void assertUsedV1() {

x-pack/plugin/src/test/resources/rest-api-spec/test/ml/filter_crud.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
---
22
setup:
33
- skip:
4-
features: headers
4+
features:
5+
- headers
6+
- allowed_warnings
57
- do:
68
headers:
79
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
810
Content-Type: application/json
11+
allowed_warnings:
12+
- "index [.ml-meta] matches multiple v1 templates [.ml-meta, global], v2 index templates will only match a single index template"
913
index:
1014
index: .ml-meta
1115
id: filter_imposter-filter
@@ -320,6 +324,8 @@ setup:
320324
indices.delete:
321325
index: ".ml-meta"
322326
- do:
327+
allowed_warnings:
328+
- "index [.ml-meta] matches multiple v1 templates [.ml-meta, global], v2 index templates will only match a single index template"
323329
indices.create:
324330
index: ".ml-meta"
325331

x-pack/plugin/src/test/resources/rest-api-spec/test/ml/inference_stats_crud.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
setup:
22
- skip:
3-
features: headers
3+
features:
4+
- headers
5+
- allowed_warnings
46
- do:
7+
allowed_warnings:
8+
- "index [.ml-inference-000002] matches multiple v1 templates [.ml-inference-000002, global], v2 index templates will only match a single index template"
59
headers:
610
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
711
index:

x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
setup:
22
- skip:
3-
features: headers
3+
features:
4+
- headers
5+
- allowed_warnings
46
- do:
7+
allowed_warnings:
8+
- "index [foo_rollup] matches multiple v1 templates [global, test], v2 index templates will only match a single index template"
59
indices.create:
610
index: foo
711
body:
@@ -273,6 +277,8 @@ setup:
273277
type: keyword
274278

275279
- do:
280+
allowed_warnings:
281+
- "index [foo_rollup] matches multiple v1 templates [global, test], v2 index templates will only match a single index template"
276282
headers:
277283
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
278284
rollup.put_job:

0 commit comments

Comments
 (0)