Skip to content

Commit fda7fc7

Browse files
authored
[Deprecation] Refine Transform Destination Index message (#122192)
When we detect that a Transform writes to the index and the index is incompatible with the next version, change the message, detail, and URL to help the user take the necessary steps to migrate the destination index.
1 parent cd74d18 commit fda7fc7

File tree

2 files changed

+202
-45
lines changed

2 files changed

+202
-45
lines changed

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecker.java

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.common.TriFunction;
1414
import org.elasticsearch.common.time.DateFormatter;
1515
import org.elasticsearch.common.time.LegacyFormatNames;
16+
import org.elasticsearch.core.Strings;
1617
import org.elasticsearch.index.IndexModule;
1718
import org.elasticsearch.index.IndexSettings;
1819
import org.elasticsearch.index.IndexVersion;
@@ -95,25 +96,39 @@ private DeprecationIssue oldIndicesCheck(
9596
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
9697
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
9798
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, false) && isNotDataStreamIndex(indexMetadata, clusterState)) {
98-
return new DeprecationIssue(
99-
DeprecationIssue.Level.CRITICAL,
100-
"Old index with a compatibility version < 9.0",
101-
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
102-
"This index has version: " + currentCompatibilityVersion.toReleaseVersion(),
103-
false,
104-
meta(indexMetadata, indexToTransformIds)
105-
);
99+
var transforms = transformIdsForIndex(indexMetadata, indexToTransformIds);
100+
if (transforms.isEmpty() == false) {
101+
return new DeprecationIssue(
102+
DeprecationIssue.Level.CRITICAL,
103+
"One or more Transforms write to this index with a compatibility version < 9.0",
104+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-9.0.html"
105+
+ "#breaking_90_transform_destination_index",
106+
Strings.format(
107+
"This index was created in version [%s] and requires action before upgrading to 9.0. The following transforms are "
108+
+ "configured to write to this index: [%s]. Refer to the migration guide to learn more about how to prepare "
109+
+ "transforms destination indices for your upgrade.",
110+
currentCompatibilityVersion.toReleaseVersion(),
111+
String.join(", ", transforms)
112+
),
113+
false,
114+
Map.of("reindex_required", true, "transform_ids", transforms)
115+
);
116+
} else {
117+
return new DeprecationIssue(
118+
DeprecationIssue.Level.CRITICAL,
119+
"Old index with a compatibility version < 9.0",
120+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
121+
"This index has version: " + currentCompatibilityVersion.toReleaseVersion(),
122+
false,
123+
Map.of("reindex_required", true)
124+
);
125+
}
106126
}
107127
return null;
108128
}
109129

110-
private Map<String, Object> meta(IndexMetadata indexMetadata, Map<String, List<String>> indexToTransformIds) {
111-
var transforms = indexToTransformIds.getOrDefault(indexMetadata.getIndex().getName(), List.of());
112-
if (transforms.isEmpty()) {
113-
return Map.of("reindex_required", true);
114-
} else {
115-
return Map.of("reindex_required", true, "transform_ids", transforms);
116-
}
130+
private List<String> transformIdsForIndex(IndexMetadata indexMetadata, Map<String, List<String>> indexToTransformIds) {
131+
return indexToTransformIds.getOrDefault(indexMetadata.getIndex().getName(), List.of());
117132
}
118133

119134
private DeprecationIssue ignoredOldIndicesCheck(
@@ -124,16 +139,35 @@ private DeprecationIssue ignoredOldIndicesCheck(
124139
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
125140
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
126141
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, true) && isNotDataStreamIndex(indexMetadata, clusterState)) {
127-
return new DeprecationIssue(
128-
DeprecationIssue.Level.WARNING,
129-
"Old index with a compatibility version < 9.0 Has Been Ignored",
130-
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
131-
"This read-only index has version: "
132-
+ currentCompatibilityVersion.toReleaseVersion()
133-
+ " and will be supported as read-only in 9.0",
134-
false,
135-
meta(indexMetadata, indexToTransformIds)
136-
);
142+
var transforms = transformIdsForIndex(indexMetadata, indexToTransformIds);
143+
if (transforms.isEmpty() == false) {
144+
return new DeprecationIssue(
145+
DeprecationIssue.Level.WARNING,
146+
"One or more Transforms write to this old index with a compatibility version < 9.0",
147+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-9.0.html"
148+
+ "#breaking_90_transform_destination_index",
149+
Strings.format(
150+
"This index was created in version [%s] and will be supported as a read-only index in 9.0. The following "
151+
+ "transforms are no longer able to write to this index: [%s]. Refer to the migration guide to learn more "
152+
+ "about how to handle your transforms destination indices.",
153+
currentCompatibilityVersion.toReleaseVersion(),
154+
String.join(", ", transforms)
155+
),
156+
false,
157+
Map.of("reindex_required", true, "transform_ids", transforms)
158+
);
159+
} else {
160+
return new DeprecationIssue(
161+
DeprecationIssue.Level.WARNING,
162+
"Old index with a compatibility version < 9.0 has been ignored",
163+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
164+
"This read-only index has version: "
165+
+ currentCompatibilityVersion.toReleaseVersion()
166+
+ " and will be supported as read-only in 9.0",
167+
false,
168+
Map.of("reindex_required", true)
169+
);
170+
}
137171
}
138172
return null;
139173
}

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationCheckerTests.java

Lines changed: 143 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,14 @@ public void testOldTransformIndicesCheck() {
102102
.build();
103103
var expected = new DeprecationIssue(
104104
DeprecationIssue.Level.CRITICAL,
105-
"Old index with a compatibility version < 9.0",
106-
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
107-
"This index has version: " + OLD_VERSION.toReleaseVersion(),
105+
"One or more Transforms write to this index with a compatibility version < 9.0",
106+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-9.0.html"
107+
+ "#breaking_90_transform_destination_index",
108+
"This index was created in version ["
109+
+ OLD_VERSION.toReleaseVersion()
110+
+ "] and requires action before upgrading to 9.0. "
111+
+ "The following transforms are configured to write to this index: [test-transform]. Refer to the "
112+
+ "migration guide to learn more about how to prepare transforms destination indices for your upgrade.",
108113
false,
109114
Map.of("reindex_required", true, "transform_ids", List.of("test-transform"))
110115
);
@@ -124,9 +129,14 @@ public void testOldIndicesCheckWithMultipleTransforms() {
124129
.build();
125130
var expected = new DeprecationIssue(
126131
DeprecationIssue.Level.CRITICAL,
127-
"Old index with a compatibility version < 9.0",
128-
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
129-
"This index has version: " + OLD_VERSION.toReleaseVersion(),
132+
"One or more Transforms write to this index with a compatibility version < 9.0",
133+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-9.0.html"
134+
+ "#breaking_90_transform_destination_index",
135+
"This index was created in version ["
136+
+ OLD_VERSION.toReleaseVersion()
137+
+ "] and requires action before upgrading to 9.0. "
138+
+ "The following transforms are configured to write to this index: [test-transform1, test-transform2]. Refer to the "
139+
+ "migration guide to learn more about how to prepare transforms destination indices for your upgrade.",
130140
false,
131141
Map.of("reindex_required", true, "transform_ids", List.of("test-transform1", "test-transform2"))
132142
);
@@ -150,9 +160,14 @@ public void testMultipleOldIndicesCheckWithTransforms() {
150160
List.of(
151161
new DeprecationIssue(
152162
DeprecationIssue.Level.CRITICAL,
153-
"Old index with a compatibility version < 9.0",
154-
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
155-
"This index has version: " + OLD_VERSION.toReleaseVersion(),
163+
"One or more Transforms write to this index with a compatibility version < 9.0",
164+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-9.0.html"
165+
+ "#breaking_90_transform_destination_index",
166+
"This index was created in version ["
167+
+ OLD_VERSION.toReleaseVersion()
168+
+ "] and requires action before upgrading to 9.0. "
169+
+ "The following transforms are configured to write to this index: [test-transform1]. Refer to the "
170+
+ "migration guide to learn more about how to prepare transforms destination indices for your upgrade.",
156171
false,
157172
Map.of("reindex_required", true, "transform_ids", List.of("test-transform1"))
158173
)
@@ -161,9 +176,14 @@ public void testMultipleOldIndicesCheckWithTransforms() {
161176
List.of(
162177
new DeprecationIssue(
163178
DeprecationIssue.Level.CRITICAL,
164-
"Old index with a compatibility version < 9.0",
165-
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
166-
"This index has version: " + OLD_VERSION.toReleaseVersion(),
179+
"One or more Transforms write to this index with a compatibility version < 9.0",
180+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-9.0.html"
181+
+ "#breaking_90_transform_destination_index",
182+
"This index was created in version ["
183+
+ OLD_VERSION.toReleaseVersion()
184+
+ "] and requires action before upgrading to 9.0. "
185+
+ "The following transforms are configured to write to this index: [test-transform2]. Refer to the "
186+
+ "migration guide to learn more about how to prepare transforms destination indices for your upgrade.",
167187
false,
168188
Map.of("reindex_required", true, "transform_ids", List.of("test-transform2"))
169189
)
@@ -256,20 +276,14 @@ public void testOldIndicesCheckSnapshotIgnored() {
256276
}
257277

258278
public void testOldIndicesIgnoredWarningCheck() {
259-
Settings.Builder settings = settings(OLD_VERSION).put(MetadataIndexStateService.VERIFIED_READ_ONLY_SETTING.getKey(), true);
260-
IndexMetadata indexMetadata = IndexMetadata.builder("test")
261-
.settings(settings)
262-
.numberOfShards(1)
263-
.numberOfReplicas(0)
264-
.state(indexMetdataState)
265-
.build();
279+
IndexMetadata indexMetadata = readonlyIndexMetadata("test", OLD_VERSION);
266280
ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
267281
.metadata(Metadata.builder().put(indexMetadata, true))
268282
.blocks(clusterBlocksForIndices(indexMetadata))
269283
.build();
270284
DeprecationIssue expected = new DeprecationIssue(
271285
DeprecationIssue.Level.WARNING,
272-
"Old index with a compatibility version < 9.0 Has Been Ignored",
286+
"Old index with a compatibility version < 9.0 has been ignored",
273287
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
274288
"This read-only index has version: " + OLD_VERSION.toReleaseVersion() + " and will be supported as read-only in 9.0",
275289
false,
@@ -284,6 +298,115 @@ public void testOldIndicesIgnoredWarningCheck() {
284298
assertEquals(List.of(expected), issuesByIndex.get("test"));
285299
}
286300

301+
private IndexMetadata readonlyIndexMetadata(String indexName, IndexVersion indexVersion) {
302+
Settings.Builder settings = settings(indexVersion).put(MetadataIndexStateService.VERIFIED_READ_ONLY_SETTING.getKey(), true);
303+
return IndexMetadata.builder(indexName).settings(settings).numberOfShards(1).numberOfReplicas(0).state(indexMetdataState).build();
304+
}
305+
306+
public void testOldTransformIndicesIgnoredCheck() {
307+
var checker = new IndexDeprecationChecker(indexNameExpressionResolver);
308+
var indexMetadata = readonlyIndexMetadata("test", OLD_VERSION);
309+
var clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
310+
.metadata(Metadata.builder().put(indexMetadata, true))
311+
.blocks(clusterBlocksForIndices(indexMetadata))
312+
.build();
313+
var expected = new DeprecationIssue(
314+
DeprecationIssue.Level.WARNING,
315+
"One or more Transforms write to this old index with a compatibility version < 9.0",
316+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-9.0.html"
317+
+ "#breaking_90_transform_destination_index",
318+
"This index was created in version ["
319+
+ OLD_VERSION.toReleaseVersion()
320+
+ "] and will be supported as a read-only index in 9.0. "
321+
+ "The following transforms are no longer able to write to this index: [test-transform]. Refer to the "
322+
+ "migration guide to learn more about how to handle your transforms destination indices.",
323+
false,
324+
Map.of("reindex_required", true, "transform_ids", List.of("test-transform"))
325+
);
326+
var issuesByIndex = checker.check(
327+
clusterState,
328+
new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
329+
createContextWithTransformConfigs(Map.of("test", List.of("test-transform")))
330+
);
331+
assertEquals(singletonList(expected), issuesByIndex.get("test"));
332+
}
333+
334+
public void testOldIndicesIgnoredCheckWithMultipleTransforms() {
335+
var indexMetadata = readonlyIndexMetadata("test", OLD_VERSION);
336+
var clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
337+
.metadata(Metadata.builder().put(indexMetadata, true))
338+
.blocks(clusterBlocksForIndices(indexMetadata))
339+
.build();
340+
var expected = new DeprecationIssue(
341+
DeprecationIssue.Level.WARNING,
342+
"One or more Transforms write to this old index with a compatibility version < 9.0",
343+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-9.0.html"
344+
+ "#breaking_90_transform_destination_index",
345+
"This index was created in version ["
346+
+ OLD_VERSION.toReleaseVersion()
347+
+ "] and will be supported as a read-only index in 9.0. "
348+
+ "The following transforms are no longer able to write to this index: [test-transform1, test-transform2]. Refer to the "
349+
+ "migration guide to learn more about how to handle your transforms destination indices.",
350+
false,
351+
Map.of("reindex_required", true, "transform_ids", List.of("test-transform1", "test-transform2"))
352+
);
353+
var issuesByIndex = checker.check(
354+
clusterState,
355+
new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
356+
createContextWithTransformConfigs(Map.of("test", List.of("test-transform1", "test-transform2")))
357+
);
358+
assertEquals(singletonList(expected), issuesByIndex.get("test"));
359+
}
360+
361+
public void testMultipleOldIndicesIgnoredCheckWithTransforms() {
362+
var indexMetadata1 = readonlyIndexMetadata("test1", OLD_VERSION);
363+
var indexMetadata2 = readonlyIndexMetadata("test2", OLD_VERSION);
364+
var clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
365+
.metadata(Metadata.builder().put(indexMetadata1, true).put(indexMetadata2, true))
366+
.blocks(clusterBlocksForIndices(indexMetadata1, indexMetadata2))
367+
.build();
368+
var expected = Map.of(
369+
"test1",
370+
List.of(
371+
new DeprecationIssue(
372+
DeprecationIssue.Level.WARNING,
373+
"One or more Transforms write to this old index with a compatibility version < 9.0",
374+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-9.0.html"
375+
+ "#breaking_90_transform_destination_index",
376+
"This index was created in version ["
377+
+ OLD_VERSION.toReleaseVersion()
378+
+ "] and will be supported as a read-only index in 9.0. "
379+
+ "The following transforms are no longer able to write to this index: [test-transform1]. Refer to the "
380+
+ "migration guide to learn more about how to handle your transforms destination indices.",
381+
false,
382+
Map.of("reindex_required", true, "transform_ids", List.of("test-transform1"))
383+
)
384+
),
385+
"test2",
386+
List.of(
387+
new DeprecationIssue(
388+
DeprecationIssue.Level.WARNING,
389+
"One or more Transforms write to this old index with a compatibility version < 9.0",
390+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-9.0.html"
391+
+ "#breaking_90_transform_destination_index",
392+
"This index was created in version ["
393+
+ OLD_VERSION.toReleaseVersion()
394+
+ "] and will be supported as a read-only index in 9.0. "
395+
+ "The following transforms are no longer able to write to this index: [test-transform2]. Refer to the "
396+
+ "migration guide to learn more about how to handle your transforms destination indices.",
397+
false,
398+
Map.of("reindex_required", true, "transform_ids", List.of("test-transform2"))
399+
)
400+
)
401+
);
402+
var issuesByIndex = checker.check(
403+
clusterState,
404+
new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
405+
createContextWithTransformConfigs(Map.of("test1", List.of("test-transform1"), "test2", List.of("test-transform2")))
406+
);
407+
assertEquals(expected, issuesByIndex);
408+
}
409+
287410
public void testTranslogRetentionSettings() {
288411
Settings.Builder settings = settings(IndexVersion.current());
289412
settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.getKey(), randomPositiveTimeValue());

0 commit comments

Comments
 (0)