Skip to content

Commit 2404dac

Browse files
authored
Make deprecation plugin project-aware (#130364)
Updates the majority of the plugin to be aware of multiple projects. The deprecation plugin is excluded in serverless, so in `DeprecationIndexingComponent` we hard-code the default project ID to avoid an unworthy investment of namespacing effort.
1 parent 6520fa2 commit 2404dac

14 files changed

+238
-362
lines changed

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
12-
import org.elasticsearch.cluster.ClusterState;
13-
import org.elasticsearch.common.TriConsumer;
1412
import org.elasticsearch.xcontent.NamedXContentRegistry;
1513
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
1614
import org.elasticsearch.xpack.core.transform.transforms.TransformConfig;
@@ -25,26 +23,19 @@
2523
public class ClusterDeprecationChecker {
2624

2725
private static final Logger logger = LogManager.getLogger(ClusterDeprecationChecker.class);
28-
private final List<TriConsumer<ClusterState, List<TransformConfig>, List<DeprecationIssue>>> CHECKS = List.of(
29-
this::checkTransformSettings
30-
);
3126
private final NamedXContentRegistry xContentRegistry;
3227

3328
ClusterDeprecationChecker(NamedXContentRegistry xContentRegistry) {
3429
this.xContentRegistry = xContentRegistry;
3530
}
3631

37-
public List<DeprecationIssue> check(ClusterState clusterState, List<TransformConfig> transformConfigs) {
32+
public List<DeprecationIssue> check(List<TransformConfig> transformConfigs) {
3833
List<DeprecationIssue> allIssues = new ArrayList<>();
39-
CHECKS.forEach(check -> check.apply(clusterState, transformConfigs, allIssues));
34+
checkTransformSettings(transformConfigs, allIssues);
4035
return allIssues;
4136
}
4237

43-
private void checkTransformSettings(
44-
ClusterState clusterState,
45-
List<TransformConfig> transformConfigs,
46-
List<DeprecationIssue> allIssues
47-
) {
38+
private void checkTransformSettings(List<TransformConfig> transformConfigs, List<DeprecationIssue> allIssues) {
4839
for (var config : transformConfigs) {
4940
try {
5041
allIssues.addAll(config.checkForDeprecations(xContentRegistry));

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
import org.elasticsearch.Version;
1111
import org.elasticsearch.action.support.IndicesOptions;
12-
import org.elasticsearch.cluster.ClusterState;
1312
import org.elasticsearch.cluster.metadata.DataStream;
1413
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
14+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1515
import org.elasticsearch.index.Index;
1616
import org.elasticsearch.xpack.core.deprecation.DeprecatedIndexPredicate;
1717
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
@@ -33,7 +33,7 @@
3333
public class DataStreamDeprecationChecker implements ResourceDeprecationChecker {
3434

3535
public static final String NAME = "data_streams";
36-
private static final List<BiFunction<DataStream, ClusterState, DeprecationIssue>> DATA_STREAM_CHECKS = List.of(
36+
private static final List<BiFunction<DataStream, ProjectMetadata, DeprecationIssue>> DATA_STREAM_CHECKS = List.of(
3737
DataStreamDeprecationChecker::oldIndicesCheck,
3838
DataStreamDeprecationChecker::ignoredOldIndicesCheck
3939
);
@@ -44,38 +44,38 @@ public DataStreamDeprecationChecker(IndexNameExpressionResolver indexNameExpress
4444
}
4545

4646
/**
47-
* @param clusterState The cluster state provided for the checker
47+
* @param project The project metadata provided for the checker
4848
* @param request not used yet in these checks
4949
* @param precomputedData not used yet in these checks
5050
* @return the name of the data streams that have violated the checks with their respective warnings.
5151
*/
5252
@Override
5353
public Map<String, List<DeprecationIssue>> check(
54-
ClusterState clusterState,
54+
ProjectMetadata project,
5555
DeprecationInfoAction.Request request,
5656
TransportDeprecationInfoAction.PrecomputedData precomputedData
5757
) {
58-
return check(clusterState);
58+
return check(project);
5959
}
6060

6161
/**
62-
* @param clusterState The cluster state provided for the checker
62+
* @param project The project metadata provided for the checker
6363
* @return the name of the data streams that have violated the checks with their respective warnings.
6464
*/
65-
public Map<String, List<DeprecationIssue>> check(ClusterState clusterState) {
65+
public Map<String, List<DeprecationIssue>> check(ProjectMetadata project) {
6666
List<String> dataStreamNames = indexNameExpressionResolver.dataStreamNames(
67-
clusterState,
67+
project,
6868
IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN
6969
);
7070
if (dataStreamNames.isEmpty()) {
7171
return Map.of();
7272
}
7373
Map<String, List<DeprecationIssue>> dataStreamIssues = new HashMap<>();
7474
for (String dataStreamName : dataStreamNames) {
75-
DataStream dataStream = clusterState.metadata().getProject().dataStreams().get(dataStreamName);
75+
DataStream dataStream = project.dataStreams().get(dataStreamName);
7676
if (dataStream.isSystem() == false) {
7777
List<DeprecationIssue> issuesForSingleDataStream = DATA_STREAM_CHECKS.stream()
78-
.map(c -> c.apply(dataStream, clusterState))
78+
.map(c -> c.apply(dataStream, project))
7979
.filter(Objects::nonNull)
8080
.toList();
8181
if (issuesForSingleDataStream.isEmpty() == false) {
@@ -86,10 +86,10 @@ public Map<String, List<DeprecationIssue>> check(ClusterState clusterState) {
8686
return dataStreamIssues.isEmpty() ? Map.of() : dataStreamIssues;
8787
}
8888

89-
static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
89+
static DeprecationIssue oldIndicesCheck(DataStream dataStream, ProjectMetadata project) {
9090
List<Index> backingIndices = dataStream.getIndices();
9191

92-
Set<String> indicesNeedingUpgrade = getReindexRequiredIndices(backingIndices, clusterState, false);
92+
Set<String> indicesNeedingUpgrade = getReindexRequiredIndices(backingIndices, project, false);
9393

9494
if (indicesNeedingUpgrade.isEmpty() == false) {
9595
return new DeprecationIssue(
@@ -110,9 +110,9 @@ static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clus
110110
return null;
111111
}
112112

113-
static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
113+
static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ProjectMetadata project) {
114114
List<Index> backingIndices = dataStream.getIndices();
115-
Set<String> ignoredIndices = getReindexRequiredIndices(backingIndices, clusterState, true);
115+
Set<String> ignoredIndices = getReindexRequiredIndices(backingIndices, project, true);
116116
if (ignoredIndices.isEmpty() == false) {
117117
return new DeprecationIssue(
118118
DeprecationIssue.Level.WARNING,
@@ -135,13 +135,11 @@ static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ClusterSta
135135

136136
private static Set<String> getReindexRequiredIndices(
137137
List<Index> backingIndices,
138-
ClusterState clusterState,
138+
ProjectMetadata project,
139139
boolean filterToBlockedStatus
140140
) {
141141
return backingIndices.stream()
142-
.filter(
143-
DeprecatedIndexPredicate.getReindexRequiredPredicate(clusterState.metadata().getProject(), filterToBlockedStatus, false)
144-
)
142+
.filter(DeprecatedIndexPredicate.getReindexRequiredPredicate(project, filterToBlockedStatus, false))
145143
.map(Index::getName)
146144
.collect(Collectors.toUnmodifiableSet());
147145
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
package org.elasticsearch.xpack.deprecation;
99

10-
import org.elasticsearch.cluster.ClusterState;
10+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1111
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
1212
import org.elasticsearch.xpack.core.ilm.AllocateAction;
1313
import org.elasticsearch.xpack.core.ilm.FreezeAction;
@@ -36,26 +36,26 @@ public class IlmPolicyDeprecationChecker implements ResourceDeprecationChecker {
3636
private final List<Function<LifecyclePolicy, DeprecationIssue>> checks = List.of(this::checkLegacyTiers, this::checkFrozenAction);
3737

3838
/**
39-
* @param clusterState The cluster state provided for the checker
39+
* @param project The project metadata provided for the checker
4040
* @param request not used yet in these checks
4141
* @param precomputedData not used yet in these checks
4242
* @return the name of the data streams that have violated the checks with their respective warnings.
4343
*/
4444
@Override
4545
public Map<String, List<DeprecationIssue>> check(
46-
ClusterState clusterState,
46+
ProjectMetadata project,
4747
DeprecationInfoAction.Request request,
4848
TransportDeprecationInfoAction.PrecomputedData precomputedData
4949
) {
50-
return check(clusterState);
50+
return check(project);
5151
}
5252

5353
/**
54-
* @param clusterState The cluster state provided for the checker
54+
* @param project The project metadata provided for the checker
5555
* @return the name of the data streams that have violated the checks with their respective warnings.
5656
*/
57-
Map<String, List<DeprecationIssue>> check(ClusterState clusterState) {
58-
IndexLifecycleMetadata lifecycleMetadata = clusterState.metadata().getProject().custom(IndexLifecycleMetadata.TYPE);
57+
Map<String, List<DeprecationIssue>> check(ProjectMetadata project) {
58+
IndexLifecycleMetadata lifecycleMetadata = project.custom(IndexLifecycleMetadata.TYPE);
5959
if (lifecycleMetadata == null || lifecycleMetadata.getPolicyMetadatas().isEmpty()) {
6060
return Map.of();
6161
}

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
package org.elasticsearch.xpack.deprecation;
88

99
import org.elasticsearch.Version;
10-
import org.elasticsearch.cluster.ClusterState;
1110
import org.elasticsearch.cluster.metadata.IndexMetadata;
1211
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1312
import org.elasticsearch.cluster.metadata.MappingMetadata;
13+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1414
import org.elasticsearch.common.TriFunction;
1515
import org.elasticsearch.common.time.DateFormatter;
1616
import org.elasticsearch.common.time.LegacyFormatNames;
@@ -44,7 +44,7 @@ public class IndexDeprecationChecker implements ResourceDeprecationChecker {
4444
public static final String NAME = "index_settings";
4545

4646
private final IndexNameExpressionResolver indexNameExpressionResolver;
47-
private final List<TriFunction<IndexMetadata, ClusterState, Map<String, List<String>>, DeprecationIssue>> checks = List.of(
47+
private final List<TriFunction<IndexMetadata, ProjectMetadata, Map<String, List<String>>, DeprecationIssue>> checks = List.of(
4848
this::oldIndicesCheck,
4949
this::ignoredOldIndicesCheck,
5050
this::translogRetentionSettingCheck,
@@ -60,17 +60,17 @@ public IndexDeprecationChecker(IndexNameExpressionResolver indexNameExpressionRe
6060

6161
@Override
6262
public Map<String, List<DeprecationIssue>> check(
63-
ClusterState clusterState,
63+
ProjectMetadata project,
6464
DeprecationInfoAction.Request request,
6565
TransportDeprecationInfoAction.PrecomputedData precomputedData
6666
) {
6767
Map<String, List<DeprecationIssue>> indexSettingsIssues = new HashMap<>();
68-
String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
68+
String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(project, request);
6969
Map<String, List<String>> indexToTransformIds = indexToTransformIds(precomputedData.transformConfigs());
7070
for (String concreteIndex : concreteIndexNames) {
71-
IndexMetadata indexMetadata = clusterState.getMetadata().getProject().index(concreteIndex);
71+
IndexMetadata indexMetadata = project.index(concreteIndex);
7272
List<DeprecationIssue> singleIndexIssues = checks.stream()
73-
.map(c -> c.apply(indexMetadata, clusterState, indexToTransformIds))
73+
.map(c -> c.apply(indexMetadata, project, indexToTransformIds))
7474
.filter(Objects::nonNull)
7575
.toList();
7676
if (singleIndexIssues.isEmpty() == false) {
@@ -90,13 +90,13 @@ public String getName() {
9090

9191
private DeprecationIssue oldIndicesCheck(
9292
IndexMetadata indexMetadata,
93-
ClusterState clusterState,
93+
ProjectMetadata project,
9494
Map<String, List<String>> indexToTransformIds
9595
) {
9696
// TODO: this check needs to be revised. It's trivially true right now.
9797
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
9898
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
99-
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, false, false) && isNotDataStreamIndex(indexMetadata, clusterState)) {
99+
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, false, false) && isNotDataStreamIndex(indexMetadata, project)) {
100100
var transforms = transformIdsForIndex(indexMetadata, indexToTransformIds);
101101
if (transforms.isEmpty() == false) {
102102
return new DeprecationIssue(
@@ -134,12 +134,12 @@ private List<String> transformIdsForIndex(IndexMetadata indexMetadata, Map<Strin
134134

135135
private DeprecationIssue ignoredOldIndicesCheck(
136136
IndexMetadata indexMetadata,
137-
ClusterState clusterState,
137+
ProjectMetadata project,
138138
Map<String, List<String>> indexToTransformIds
139139
) {
140140
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
141141
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
142-
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, true, false) && isNotDataStreamIndex(indexMetadata, clusterState)) {
142+
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, true, false) && isNotDataStreamIndex(indexMetadata, project)) {
143143
var transforms = transformIdsForIndex(indexMetadata, indexToTransformIds);
144144
if (transforms.isEmpty() == false) {
145145
return new DeprecationIssue(
@@ -175,13 +175,13 @@ private DeprecationIssue ignoredOldIndicesCheck(
175175
return null;
176176
}
177177

178-
private boolean isNotDataStreamIndex(IndexMetadata indexMetadata, ClusterState clusterState) {
179-
return clusterState.metadata().getProject().findDataStreams(indexMetadata.getIndex().getName()).isEmpty();
178+
private boolean isNotDataStreamIndex(IndexMetadata indexMetadata, ProjectMetadata project) {
179+
return project.findDataStreams(indexMetadata.getIndex().getName()).isEmpty();
180180
}
181181

182182
private DeprecationIssue translogRetentionSettingCheck(
183183
IndexMetadata indexMetadata,
184-
ClusterState clusterState,
184+
ProjectMetadata project,
185185
Map<String, List<String>> ignored
186186
) {
187187
final boolean softDeletesEnabled = IndexSettings.INDEX_SOFT_DELETES_SETTING.get(indexMetadata.getSettings());
@@ -210,7 +210,7 @@ private DeprecationIssue translogRetentionSettingCheck(
210210
return null;
211211
}
212212

213-
private DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ClusterState clusterState, Map<String, List<String>> ignored) {
213+
private DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ProjectMetadata project, Map<String, List<String>> ignored) {
214214
if (IndexMetadata.INDEX_DATA_PATH_SETTING.exists(indexMetadata.getSettings())) {
215215
final String message = String.format(
216216
Locale.ROOT,
@@ -226,7 +226,7 @@ private DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, Cluster
226226

227227
private DeprecationIssue storeTypeSettingCheck(
228228
IndexMetadata indexMetadata,
229-
ClusterState clusterState,
229+
ProjectMetadata project,
230230
Map<String, List<String>> ignored
231231
) {
232232
final String storeType = IndexModule.INDEX_STORE_TYPE_SETTING.get(indexMetadata.getSettings());
@@ -247,7 +247,7 @@ private DeprecationIssue storeTypeSettingCheck(
247247

248248
private DeprecationIssue legacyRoutingSettingCheck(
249249
IndexMetadata indexMetadata,
250-
ClusterState clusterState,
250+
ProjectMetadata project,
251251
Map<String, List<String>> ignored
252252
) {
253253
List<String> deprecatedSettings = LegacyTiersDetection.getDeprecatedFilteredAllocationSettings(indexMetadata.getSettings());
@@ -339,7 +339,7 @@ private List<String> findInPropertiesRecursively(
339339

340340
private DeprecationIssue deprecatedCamelCasePattern(
341341
IndexMetadata indexMetadata,
342-
ClusterState clusterState,
342+
ProjectMetadata project,
343343
Map<String, List<String>> ignored
344344
) {
345345
List<String> fields = new ArrayList<>();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
package org.elasticsearch.xpack.deprecation;
99

10-
import org.elasticsearch.cluster.ClusterState;
10+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1111
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
1212

1313
import java.util.List;
@@ -23,12 +23,12 @@ public interface ResourceDeprecationChecker {
2323
/**
2424
* This runs the checks for the current deprecation checker.
2525
*
26-
* @param clusterState The cluster state provided for the checker
26+
* @param project The project metadata provided for the checker
2727
* @param request The deprecation request that triggered this check
2828
* @param precomputedData Data that have been remotely retrieved and might be useful in the checks
2929
*/
3030
Map<String, List<DeprecationIssue>> check(
31-
ClusterState clusterState,
31+
ProjectMetadata project,
3232
DeprecationInfoAction.Request request,
3333
TransportDeprecationInfoAction.PrecomputedData precomputedData
3434
);

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
package org.elasticsearch.xpack.deprecation;
99

10-
import org.elasticsearch.cluster.ClusterState;
1110
import org.elasticsearch.cluster.metadata.ComponentTemplate;
1211
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
12+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1313
import org.elasticsearch.cluster.metadata.Template;
1414
import org.elasticsearch.common.xcontent.XContentHelper;
1515
import org.elasticsearch.index.mapper.SourceFieldMapper;
@@ -41,27 +41,27 @@ public class TemplateDeprecationChecker implements ResourceDeprecationChecker {
4141
);
4242

4343
/**
44-
* @param clusterState The cluster state provided for the checker
44+
* @param project The project metadata provided for the checker
4545
* @param request not used yet in these checks
4646
* @param precomputedData not used yet in these checks
4747
* @return the name of the data streams that have violated the checks with their respective warnings.
4848
*/
4949
@Override
5050
public Map<String, List<DeprecationIssue>> check(
51-
ClusterState clusterState,
51+
ProjectMetadata project,
5252
DeprecationInfoAction.Request request,
5353
TransportDeprecationInfoAction.PrecomputedData precomputedData
5454
) {
55-
return check(clusterState);
55+
return check(project);
5656
}
5757

5858
/**
59-
* @param clusterState The cluster state provided for the checker
59+
* @param project The project metadata provided for the checker
6060
* @return the name of the data streams that have violated the checks with their respective warnings.
6161
*/
62-
Map<String, List<DeprecationIssue>> check(ClusterState clusterState) {
63-
var indexTemplates = clusterState.metadata().getProject().templatesV2().entrySet();
64-
var componentTemplates = clusterState.metadata().getProject().componentTemplates().entrySet();
62+
Map<String, List<DeprecationIssue>> check(ProjectMetadata project) {
63+
var indexTemplates = project.templatesV2().entrySet();
64+
var componentTemplates = project.componentTemplates().entrySet();
6565
if (indexTemplates.isEmpty() && componentTemplates.isEmpty()) {
6666
return Map.of();
6767
}

0 commit comments

Comments
 (0)