Skip to content

Commit ad77c7e

Browse files
authored
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
1 parent e09425c commit ad77c7e

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
@@ -345,6 +345,12 @@ public ClusterState applyCreateIndexRequest(ClusterState currentState, CreateInd
345345
final List<IndexTemplateMetadata> v1Templates = MetadataIndexTemplateService.findV1Templates(currentState.metadata(),
346346
request.index(), isHiddenFromRequest);
347347

348+
if (v1Templates.size() > 1) {
349+
deprecationLogger.deprecatedAndMaybeLog("index_template_multiple_match", "index [{}] matches multiple v1 templates " +
350+
"[{}], v2 index templates will only match a single index template", request.index(),
351+
v1Templates.stream().map(IndexTemplateMetadata::name).sorted().collect(Collectors.joining(", ")));
352+
}
353+
348354
return applyCreateIndexRequestWithV1Templates(currentState, request, silent, v1Templates, metadataTransformer);
349355
}
350356
}

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

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

238241
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:
@@ -272,6 +276,8 @@ setup:
272276
type: keyword
273277

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

0 commit comments

Comments
 (0)