Skip to content
5 changes: 5 additions & 0 deletions docs/changelog/120821.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 120821
summary: "[Deprecation] Add `transform_ids` to outdated index"
area: Transform
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand All @@ -39,21 +38,13 @@
public class IndexDeprecationChecker implements ResourceDeprecationChecker {

public static final String NAME = "index_settings";
private static final List<BiFunction<IndexMetadata, ClusterState, DeprecationIssue>> INDEX_SETTINGS_CHECKS = List.of(
IndexDeprecationChecker::oldIndicesCheck,
IndexDeprecationChecker::ignoredOldIndicesCheck,
IndexDeprecationChecker::translogRetentionSettingCheck,
IndexDeprecationChecker::checkIndexDataPath,
IndexDeprecationChecker::storeTypeSettingCheck,
IndexDeprecationChecker::frozenIndexSettingCheck,
IndexDeprecationChecker::deprecatedCamelCasePattern,
IndexDeprecationChecker::legacyRoutingSettingCheck
);

private final IndexNameExpressionResolver indexNameExpressionResolver;
private final Map<String, List<String>> indexToTransformIds;

public IndexDeprecationChecker(IndexNameExpressionResolver indexNameExpressionResolver) {
public IndexDeprecationChecker(IndexNameExpressionResolver indexNameExpressionResolver, Map<String, List<String>> indexToTransformIds) {
this.indexNameExpressionResolver = indexNameExpressionResolver;
this.indexToTransformIds = indexToTransformIds;
}

@Override
Expand All @@ -62,7 +53,7 @@ public Map<String, List<DeprecationIssue>> check(ClusterState clusterState, Depr
String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
for (String concreteIndex : concreteIndexNames) {
IndexMetadata indexMetadata = clusterState.getMetadata().index(concreteIndex);
List<DeprecationIssue> singleIndexIssues = filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata, clusterState));
List<DeprecationIssue> singleIndexIssues = filterChecks(indexSettingsChecks(), c -> c.apply(indexMetadata, clusterState));
if (singleIndexIssues.isEmpty() == false) {
indexSettingsIssues.put(concreteIndex, singleIndexIssues);
}
Expand All @@ -73,12 +64,25 @@ public Map<String, List<DeprecationIssue>> check(ClusterState clusterState, Depr
return indexSettingsIssues;
}

private List<BiFunction<IndexMetadata, ClusterState, DeprecationIssue>> indexSettingsChecks() {
return List.of(
this::oldIndicesCheck,
this::ignoredOldIndicesCheck,
IndexDeprecationChecker::translogRetentionSettingCheck,
IndexDeprecationChecker::checkIndexDataPath,
IndexDeprecationChecker::storeTypeSettingCheck,
IndexDeprecationChecker::frozenIndexSettingCheck,
IndexDeprecationChecker::deprecatedCamelCasePattern,
IndexDeprecationChecker::legacyRoutingSettingCheck
);
}

@Override
public String getName() {
return NAME;
}

static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
private DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
// TODO: this check needs to be revised. It's trivially true right now.
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
Expand All @@ -89,13 +93,22 @@ static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterStat
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
"This index has version: " + currentCompatibilityVersion.toReleaseVersion(),
false,
Collections.singletonMap("reindex_required", true)
meta(indexMetadata)
);
}
return null;
}

static DeprecationIssue ignoredOldIndicesCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
private Map<String, Object> meta(IndexMetadata indexMetadata) {
var transforms = indexToTransformIds.getOrDefault(indexMetadata.getIndex().getName(), List.of());
if (transforms.isEmpty()) {
return Map.of("reindex_required", true);
} else {
return Map.of("reindex_required", true, "transform_ids", transforms);
}
}

private DeprecationIssue ignoredOldIndicesCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, true) && isNotDataStreamIndex(indexMetadata, clusterState)) {
Expand All @@ -107,7 +120,7 @@ static DeprecationIssue ignoredOldIndicesCheck(IndexMetadata indexMetadata, Clus
+ currentCompatibilityVersion.toReleaseVersion()
+ " and will be supported as read-only in 9.0",
false,
Collections.singletonMap("reindex_required", true)
meta(indexMetadata)
);
}
return null;
Expand All @@ -117,7 +130,7 @@ private static boolean isNotDataStreamIndex(IndexMetadata indexMetadata, Cluster
return clusterState.metadata().findDataStreams(indexMetadata.getIndex().getName()).isEmpty();
}

static DeprecationIssue translogRetentionSettingCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
private static DeprecationIssue translogRetentionSettingCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
final boolean softDeletesEnabled = IndexSettings.INDEX_SOFT_DELETES_SETTING.get(indexMetadata.getSettings());
if (softDeletesEnabled) {
if (IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.exists(indexMetadata.getSettings())
Expand All @@ -144,7 +157,7 @@ static DeprecationIssue translogRetentionSettingCheck(IndexMetadata indexMetadat
return null;
}

static DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ClusterState clusterState) {
private static DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ClusterState clusterState) {
if (IndexMetadata.INDEX_DATA_PATH_SETTING.exists(indexMetadata.getSettings())) {
final String message = String.format(
Locale.ROOT,
Expand All @@ -159,7 +172,7 @@ static DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ClusterS
return null;
}

static DeprecationIssue storeTypeSettingCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
private static DeprecationIssue storeTypeSettingCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
final String storeType = IndexModule.INDEX_STORE_TYPE_SETTING.get(indexMetadata.getSettings());
if (IndexModule.Type.SIMPLEFS.match(storeType)) {
return new DeprecationIssue(
Expand All @@ -176,7 +189,7 @@ static DeprecationIssue storeTypeSettingCheck(IndexMetadata indexMetadata, Clust
return null;
}

static DeprecationIssue frozenIndexSettingCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
private static DeprecationIssue frozenIndexSettingCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
Boolean isIndexFrozen = FrozenEngine.INDEX_FROZEN.get(indexMetadata.getSettings());
if (Boolean.TRUE.equals(isIndexFrozen)) {
String indexName = indexMetadata.getIndex().getName();
Expand All @@ -194,7 +207,7 @@ static DeprecationIssue frozenIndexSettingCheck(IndexMetadata indexMetadata, Clu
return null;
}

static DeprecationIssue legacyRoutingSettingCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
private static DeprecationIssue legacyRoutingSettingCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
List<String> deprecatedSettings = LegacyTiersDetection.getDeprecatedFilteredAllocationSettings(indexMetadata.getSettings());
if (deprecatedSettings.isEmpty()) {
return null;
Expand Down Expand Up @@ -228,7 +241,7 @@ private static void fieldLevelMappingIssue(IndexMetadata indexMetadata, BiConsum
* @return a list of issues found in fields
*/
@SuppressWarnings("unchecked")
static List<String> findInPropertiesRecursively(
private static List<String> findInPropertiesRecursively(
String type,
Map<String, Object> parentMap,
Function<Map<?, ?>, Boolean> predicate,
Expand Down Expand Up @@ -282,7 +295,7 @@ static List<String> findInPropertiesRecursively(
return issues;
}

static DeprecationIssue deprecatedCamelCasePattern(IndexMetadata indexMetadata, ClusterState clusterState) {
private static DeprecationIssue deprecatedCamelCasePattern(IndexMetadata indexMetadata, ClusterState clusterState) {
List<String> fields = new ArrayList<>();
fieldLevelMappingIssue(
indexMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
package org.elasticsearch.xpack.deprecation;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.core.action.util.PageParams;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
import org.elasticsearch.xpack.core.transform.action.GetTransformAction;
import org.elasticsearch.xpack.core.transform.transforms.TransformConfig;

import java.util.ArrayList;
import java.util.List;

public class TransformDeprecationChecker implements DeprecationChecker {
class TransformDeprecationChecker implements DeprecationChecker {

public static final String TRANSFORM_DEPRECATION_KEY = "transform_settings";
private final List<TransformConfig> transformConfigs;

TransformDeprecationChecker(List<TransformConfig> transformConfigs) {
this.transformConfigs = transformConfigs;
}

@Override
public boolean enabled(Settings settings) {
Expand All @@ -30,43 +32,17 @@ public boolean enabled(Settings settings) {

@Override
public void check(Components components, ActionListener<CheckResult> deprecationIssueListener) {

PageParams startPage = new PageParams(0, PageParams.DEFAULT_SIZE);
List<DeprecationIssue> issues = new ArrayList<>();
recursiveGetTransformsAndCollectDeprecations(
components,
issues,
startPage,
deprecationIssueListener.delegateFailureAndWrap((l, allIssues) -> l.onResponse(new CheckResult(getName(), allIssues)))
);
ActionListener.completeWith(deprecationIssueListener, () -> {
List<DeprecationIssue> allIssues = new ArrayList<>();
for (var config : transformConfigs) {
allIssues.addAll(config.checkForDeprecations(components.xContentRegistry()));
}
return new CheckResult(getName(), allIssues);
});
}

@Override
public String getName() {
return TRANSFORM_DEPRECATION_KEY;
}

private static void recursiveGetTransformsAndCollectDeprecations(
Components components,
List<DeprecationIssue> issues,
PageParams page,
ActionListener<List<DeprecationIssue>> listener
) {
final GetTransformAction.Request request = new GetTransformAction.Request(Metadata.ALL);
request.setPageParams(page);
request.setAllowNoResources(true);

components.client()
.execute(GetTransformAction.INSTANCE, request, listener.delegateFailureAndWrap((delegate, getTransformResponse) -> {
for (TransformConfig config : getTransformResponse.getTransformConfigurations()) {
issues.addAll(config.checkForDeprecations(components.xContentRegistry()));
}
if (getTransformResponse.getTransformConfigurationCount() >= (page.getFrom() + page.getSize())) {
PageParams nextPage = new PageParams(page.getFrom() + page.getSize(), PageParams.DEFAULT_SIZE);
recursiveGetTransformsAndCollectDeprecations(components, issues, nextPage, delegate);
} else {
delegate.onResponse(issues);
}
}));
}
}
Loading