Skip to content

Commit 7322015

Browse files
authored
[Deprecation API] Refactor resource deprecation checkers and add new resources. (#120505)
1 parent 453db3f commit 7322015

File tree

22 files changed

+1411
-382
lines changed

22 files changed

+1411
-382
lines changed

docs/changelog/120505.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 120505
2+
summary: "introduce new categories for deprecated resources in deprecation API"
3+
area: Indices APIs
4+
type: enhancement
5+
issues: []

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/SourceModeRollingUpgradeIT.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,9 @@ public void testConfigureStoredSourceBeforeIndexCreationLegacy() throws IOExcept
5050
putComponentTemplateRequest.setOptions(expectWarnings(SourceFieldMapper.DEPRECATION_WARNING));
5151
putComponentTemplateRequest.setJsonEntity(storedSourceMapping);
5252
assertOK(client().performRequest(putComponentTemplateRequest));
53-
54-
var request = new Request("GET", "/_migration/deprecations");
55-
var nodeSettings = (Map<?, ?>) ((List<?>) entityAsMap(client().performRequest(request)).get("node_settings")).getFirst();
56-
assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING));
57-
assertThat(
58-
(String) nodeSettings.get("details"),
59-
containsString(SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [" + templateName + "]")
60-
);
53+
assertDeprecationWarningForTemplate(templateName);
6154
} else if (isUpgradedCluster()) {
62-
var request = new Request("GET", "/_migration/deprecations");
63-
var nodeSettings = (Map<?, ?>) ((List<?>) entityAsMap(client().performRequest(request)).get("node_settings")).getFirst();
64-
assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING));
65-
assertThat(
66-
(String) nodeSettings.get("details"),
67-
containsString(SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [" + templateName + "]")
68-
);
55+
assertDeprecationWarningForTemplate(templateName);
6956
}
7057
}
7158

@@ -87,17 +74,24 @@ public void testConfigureStoredSourceWhenIndexIsCreatedLegacy() throws IOExcepti
8774
putComponentTemplateRequest.setOptions(expectWarnings(SourceFieldMapper.DEPRECATION_WARNING));
8875
putComponentTemplateRequest.setJsonEntity(storedSourceMapping);
8976
assertOK(client().performRequest(putComponentTemplateRequest));
90-
91-
var request = new Request("GET", "/_migration/deprecations");
92-
var nodeSettings = (Map<?, ?>) ((List<?>) entityAsMap(client().performRequest(request)).get("node_settings")).getFirst();
93-
assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING));
94-
assertThat(
95-
(String) nodeSettings.get("details"),
96-
containsString(SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [" + templateName + "]")
97-
);
77+
assertDeprecationWarningForTemplate(templateName);
9878
} else if (isUpgradedCluster()) {
99-
var request = new Request("GET", "/_migration/deprecations");
100-
var nodeSettings = (Map<?, ?>) ((List<?>) entityAsMap(client().performRequest(request)).get("node_settings")).getFirst();
79+
assertDeprecationWarningForTemplate(templateName);
80+
}
81+
}
82+
83+
private void assertDeprecationWarningForTemplate(String templateName) throws IOException {
84+
var request = new Request("GET", "/_migration/deprecations");
85+
var response = entityAsMap(client().performRequest(request));
86+
if (response.containsKey("templates")) {
87+
// Check the newer version of the deprecation API that contains the templates section
88+
Map<?, ?> issuesByTemplate = (Map<?, ?>) response.get("templates");
89+
assertThat(issuesByTemplate.containsKey(templateName), equalTo(true));
90+
var templateIssues = (List<?>) issuesByTemplate.get(templateName);
91+
assertThat(((Map<?, ?>) templateIssues.getFirst()).get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING));
92+
} else {
93+
// Bwc version with 8.18 until https://github.com/elastic/elasticsearch/pull/120505/ gets backported, clean up after backport
94+
var nodeSettings = (Map<?, ?>) ((List<?>) response.get("node_settings")).getFirst();
10195
assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING));
10296
assertThat(
10397
(String) nodeSettings.get("details"),

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ static TransportVersion def(int id) {
167167
public static final TransportVersion RANK_DOC_OPTIONAL_METADATA_FOR_EXPLAIN = def(8_833_00_0);
168168
public static final TransportVersion ILM_ADD_SEARCHABLE_SNAPSHOT_ADD_REPLICATE_FOR = def(8_834_00_0);
169169
public static final TransportVersion INGEST_REQUEST_INCLUDE_SOURCE_ON_ERROR = def(8_835_00_0);
170+
public static final TransportVersion RESOURCE_DEPRECATION_CHECKS = def(8_836_00_0);
170171

171172
/*
172173
* STOP! READ THIS FIRST! No, really,

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,7 @@ public static DeprecationIssue getIntersectionOfRemovableSettings(List<Deprecati
240240
* }
241241
* }
242242
*/
243-
private static final class Meta {
244-
private final List<Action> actions;
245-
private final Map<String, Object> nonActionMetadata;
246-
247-
Meta(List<Action> actions, Map<String, Object> nonActionMetadata) {
248-
this.actions = actions;
249-
this.nonActionMetadata = nonActionMetadata;
250-
}
243+
private record Meta(List<Action> actions, Map<String, Object> nonActionMetadata) {
251244

252245
private static Meta fromRemovableSettings(List<String> removableSettings) {
253246
List<Action> actions;
@@ -358,12 +351,7 @@ private interface Action {
358351
/*
359352
* This class a represents remove_settings action within the actions list in a meta Map.
360353
*/
361-
private static final class RemovalAction implements Action {
362-
private final List<String> removableSettings;
363-
364-
RemovalAction(List<String> removableSettings) {
365-
this.removableSettings = removableSettings;
366-
}
354+
private record RemovalAction(List<String> removableSettings) implements Action {
367355

368356
@SuppressWarnings("unchecked")
369357
private static RemovalAction fromActionMap(Map<String, Object> actionMap) {
@@ -398,12 +386,7 @@ public Map<String, Object> toActionMap() {
398386
/*
399387
* This represents an action within the actions list in a meta Map that is *not* a removal_action.
400388
*/
401-
private static class UnknownAction implements Action {
402-
private final Map<String, Object> actionMap;
403-
404-
private UnknownAction(Map<String, Object> actionMap) {
405-
this.actionMap = actionMap;
406-
}
389+
private record UnknownAction(Map<String, Object> actionMap) implements Action {
407390

408391
private static Action fromActionMap(Map<String, Object> actionMap) {
409392
return new UnknownAction(actionMap);
Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,65 @@
77

88
package org.elasticsearch.xpack.deprecation;
99

10+
import org.elasticsearch.action.support.IndicesOptions;
1011
import org.elasticsearch.cluster.ClusterState;
1112
import org.elasticsearch.cluster.metadata.DataStream;
13+
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1214
import org.elasticsearch.index.Index;
1315
import org.elasticsearch.xpack.core.deprecation.DeprecatedIndexPredicate;
1416
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
1517

18+
import java.util.HashMap;
1619
import java.util.List;
20+
import java.util.Map;
1721
import java.util.Set;
22+
import java.util.function.BiFunction;
1823
import java.util.stream.Collectors;
1924

2025
import static java.util.Map.entry;
2126
import static java.util.Map.ofEntries;
27+
import static org.elasticsearch.xpack.deprecation.DeprecationInfoAction.filterChecks;
28+
29+
/**
30+
* Checks the data streams for deprecation warnings.
31+
*/
32+
public class DataStreamDeprecationChecker implements ResourceDeprecationChecker {
33+
34+
public static final String NAME = "data_streams";
35+
private static final List<BiFunction<DataStream, ClusterState, DeprecationIssue>> DATA_STREAM_CHECKS = List.of(
36+
DataStreamDeprecationChecker::oldIndicesCheck,
37+
DataStreamDeprecationChecker::ignoredOldIndicesCheck
38+
);
39+
private final IndexNameExpressionResolver indexNameExpressionResolver;
40+
41+
public DataStreamDeprecationChecker(IndexNameExpressionResolver indexNameExpressionResolver) {
42+
this.indexNameExpressionResolver = indexNameExpressionResolver;
43+
}
44+
45+
/**
46+
* @param clusterState The cluster state provided for the checker
47+
* @return the name of the data streams that have violated the checks with their respective warnings.
48+
*/
49+
@Override
50+
public Map<String, List<DeprecationIssue>> check(ClusterState clusterState, DeprecationInfoAction.Request request) {
51+
List<String> dataStreamNames = indexNameExpressionResolver.dataStreamNames(
52+
clusterState,
53+
IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN
54+
);
55+
if (dataStreamNames.isEmpty()) {
56+
return Map.of();
57+
}
58+
Map<String, List<DeprecationIssue>> dataStreamIssues = new HashMap<>();
59+
for (String dataStreamName : dataStreamNames) {
60+
DataStream dataStream = clusterState.metadata().dataStreams().get(dataStreamName);
61+
List<DeprecationIssue> issuesForSingleDataStream = filterChecks(DATA_STREAM_CHECKS, c -> c.apply(dataStream, clusterState));
62+
if (issuesForSingleDataStream.isEmpty() == false) {
63+
dataStreamIssues.put(dataStreamName, issuesForSingleDataStream);
64+
}
65+
}
66+
return dataStreamIssues.isEmpty() ? Map.of() : dataStreamIssues;
67+
}
2268

23-
public class DataStreamDeprecationChecks {
2469
static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
2570
List<Index> backingIndices = dataStream.getIndices();
2671

@@ -47,9 +92,7 @@ static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clus
4792

4893
static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
4994
List<Index> backingIndices = dataStream.getIndices();
50-
5195
Set<String> ignoredIndices = getReindexRequiredIndices(backingIndices, clusterState, true);
52-
5396
if (ignoredIndices.isEmpty() == false) {
5497
return new DeprecationIssue(
5598
DeprecationIssue.Level.WARNING,
@@ -66,7 +109,6 @@ static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ClusterSta
66109
)
67110
);
68111
}
69-
70112
return null;
71113
}
72114

@@ -80,4 +122,9 @@ private static Set<String> getReindexRequiredIndices(
80122
.map(Index::getName)
81123
.collect(Collectors.toUnmodifiableSet());
82124
}
125+
126+
@Override
127+
public String getName() {
128+
return NAME;
129+
}
83130
}

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88

99
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
1010
import org.elasticsearch.cluster.ClusterState;
11-
import org.elasticsearch.cluster.metadata.DataStream;
12-
import org.elasticsearch.cluster.metadata.IndexMetadata;
1311
import org.elasticsearch.common.settings.Setting;
1412
import org.elasticsearch.common.settings.Settings;
1513
import org.elasticsearch.license.XPackLicenseState;
1614
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
1715

1816
import java.util.List;
1917
import java.util.Objects;
20-
import java.util.function.BiFunction;
2118
import java.util.function.Function;
2219
import java.util.stream.Collectors;
2320

@@ -88,25 +85,9 @@ private DeprecationChecks() {}
8885
NodeDeprecationChecks::checkEqlEnabledSetting,
8986
NodeDeprecationChecks::checkNodeAttrData,
9087
NodeDeprecationChecks::checkWatcherBulkConcurrentRequestsSetting,
91-
NodeDeprecationChecks::checkTracingApmSettings,
92-
NodeDeprecationChecks::checkSourceModeInComponentTemplates
88+
NodeDeprecationChecks::checkTracingApmSettings
9389
);
9490

95-
static List<BiFunction<IndexMetadata, ClusterState, DeprecationIssue>> INDEX_SETTINGS_CHECKS = List.of(
96-
IndexDeprecationChecks::oldIndicesCheck,
97-
IndexDeprecationChecks::ignoredOldIndicesCheck,
98-
IndexDeprecationChecks::translogRetentionSettingCheck,
99-
IndexDeprecationChecks::checkIndexDataPath,
100-
IndexDeprecationChecks::storeTypeSettingCheck,
101-
IndexDeprecationChecks::frozenIndexSettingCheck,
102-
IndexDeprecationChecks::deprecatedCamelCasePattern
103-
);
104-
105-
static List<BiFunction<DataStream, ClusterState, DeprecationIssue>> DATA_STREAM_CHECKS = List.of(
106-
DataStreamDeprecationChecks::oldIndicesCheck,
107-
DataStreamDeprecationChecks::ignoredOldIndicesCheck
108-
);
109-
11091
/**
11192
* helper utility function to reduce repeat of running a specific {@link List} of checks.
11293
*

0 commit comments

Comments
 (0)