Skip to content

Commit 9e098ff

Browse files
gmaroulidakrone
andauthored
[8.x][Deprecation API] Refactor resource deprecation checkers and add new resources (#120505) (#121016)
* [Deprecation API] Refactor resource deprecation checkers and add new resources. #120505 * Fix test * Fix test --------- Co-authored-by: Lee Hinman <[email protected]>
1 parent e5fd5bb commit 9e098ff

File tree

22 files changed

+1401
-372
lines changed

22 files changed

+1401
-372
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: []

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ static TransportVersion def(int id) {
173173
public static final TransportVersion RANK_DOC_OPTIONAL_METADATA_FOR_EXPLAIN = def(8_833_00_0);
174174
public static final TransportVersion ILM_ADD_SEARCHABLE_SNAPSHOT_ADD_REPLICATE_FOR = def(8_834_00_0);
175175
public static final TransportVersion INGEST_REQUEST_INCLUDE_SOURCE_ON_ERROR = def(8_835_00_0);
176+
public static final TransportVersion RESOURCE_DEPRECATION_CHECKS = def(8_836_00_0);
176177

177178
/*
178179
* 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

@@ -89,25 +86,9 @@ private DeprecationChecks() {}
8986
NodeDeprecationChecks::checkEqlEnabledSetting,
9087
NodeDeprecationChecks::checkNodeAttrData,
9188
NodeDeprecationChecks::checkWatcherBulkConcurrentRequestsSetting,
92-
NodeDeprecationChecks::checkTracingApmSettings,
93-
NodeDeprecationChecks::checkSourceModeInComponentTemplates
89+
NodeDeprecationChecks::checkTracingApmSettings
9490
);
9591

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

0 commit comments

Comments
 (0)