Skip to content

Commit

Permalink
Excluding data stream indices from IndexDeprecationChecks.oldIndicesC…
Browse files Browse the repository at this point in the history
…heck() (elastic#116527) (elastic#116674)

* Excluding data stream indices from IndexDeprecationChecks.oldIndicesCheck() (elastic#116527)

* removing use of a method not available in 8.x

* fixing testCamelCaseDeprecation
  • Loading branch information
masseyke authored Nov 12, 2024
1 parent 37edf70 commit f76eea0
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private DeprecationChecks() {}
NodeDeprecationChecks::checkWatcherBulkConcurrentRequestsSetting
);

static List<Function<IndexMetadata, DeprecationIssue>> INDEX_SETTINGS_CHECKS = List.of(
static List<BiFunction<IndexMetadata, ClusterState, DeprecationIssue>> INDEX_SETTINGS_CHECKS = List.of(
IndexDeprecationChecks::oldIndicesCheck,
IndexDeprecationChecks::translogRetentionSettingCheck,
IndexDeprecationChecks::checkIndexDataPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static DeprecationInfoAction.Response from(
IndexNameExpressionResolver indexNameExpressionResolver,
Request request,
NodesDeprecationCheckResponse nodeDeprecationResponse,
List<Function<IndexMetadata, DeprecationIssue>> indexSettingsChecks,
List<BiFunction<IndexMetadata, ClusterState, DeprecationIssue>> indexSettingsChecks,
List<BiFunction<DataStream, ClusterState, DeprecationIssue>> dataStreamChecks,
List<Function<ClusterState, DeprecationIssue>> clusterSettingsChecks,
Map<String, List<DeprecationIssue>> pluginSettingIssues,
Expand All @@ -293,7 +293,10 @@ public static DeprecationInfoAction.Response from(
Map<String, List<DeprecationIssue>> indexSettingsIssues = new HashMap<>();
for (String concreteIndex : concreteIndexNames) {
IndexMetadata indexMetadata = stateWithSkippedSettingsRemoved.getMetadata().index(concreteIndex);
List<DeprecationIssue> singleIndexIssues = filterChecks(indexSettingsChecks, c -> c.apply(indexMetadata));
List<DeprecationIssue> singleIndexIssues = filterChecks(
indexSettingsChecks,
c -> c.apply(indexMetadata, stateWithSkippedSettingsRemoved)
);
if (singleIndexIssues.size() > 0) {
indexSettingsIssues.put(concreteIndex, singleIndexIssues);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.elasticsearch.xpack.deprecation;

import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.MappingMetadata;
import org.elasticsearch.common.time.DateFormatter;
Expand All @@ -30,14 +31,15 @@
*/
public class IndexDeprecationChecks {

static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata) {
static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
// TODO: this check needs to be revised. It's trivially true right now.
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
if (currentCompatibilityVersion.before(IndexVersions.V_7_0_0)) {
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
if (currentCompatibilityVersion.before(IndexVersions.V_8_0_0) && isNotDataStreamIndex(indexMetadata, clusterState)) {
return new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
"Old index with a compatibility version < 7.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" + "breaking-changes-8.0.html",
"Old index with a compatibility version < 8.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
"This index has version: " + currentCompatibilityVersion.toReleaseVersion(),
false,
null
Expand All @@ -46,7 +48,11 @@ static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata) {
return null;
}

static DeprecationIssue translogRetentionSettingCheck(IndexMetadata indexMetadata) {
private static boolean isNotDataStreamIndex(IndexMetadata indexMetadata, ClusterState clusterState) {
return clusterState.metadata().findDataStreams(indexMetadata.getIndex().getName()).isEmpty();
}

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 @@ -73,7 +79,7 @@ static DeprecationIssue translogRetentionSettingCheck(IndexMetadata indexMetadat
return null;
}

static DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata) {
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 @@ -88,7 +94,7 @@ static DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata) {
return null;
}

static DeprecationIssue storeTypeSettingCheck(IndexMetadata indexMetadata) {
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 @@ -105,7 +111,7 @@ static DeprecationIssue storeTypeSettingCheck(IndexMetadata indexMetadata) {
return null;
}

static DeprecationIssue frozenIndexSettingCheck(IndexMetadata indexMetadata) {
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 Down Expand Up @@ -195,7 +201,7 @@ static List<String> findInPropertiesRecursively(
return issues;
}

static DeprecationIssue deprecatedCamelCasePattern(IndexMetadata indexMetadata) {
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 @@ -117,7 +117,9 @@ public void testFrom() throws IOException {
boolean dataStreamIssueFound = randomBoolean();
DeprecationIssue foundIssue = createTestDeprecationIssue();
List<Function<ClusterState, DeprecationIssue>> clusterSettingsChecks = List.of((s) -> clusterIssueFound ? foundIssue : null);
List<Function<IndexMetadata, DeprecationIssue>> indexSettingsChecks = List.of((idx) -> indexIssueFound ? foundIssue : null);
List<BiFunction<IndexMetadata, ClusterState, DeprecationIssue>> indexSettingsChecks = List.of(
(idx, cs) -> indexIssueFound ? foundIssue : null
);
List<BiFunction<DataStream, ClusterState, DeprecationIssue>> dataStreamChecks = List.of(
(ds, cs) -> dataStreamIssueFound ? foundIssue : null
);
Expand Down Expand Up @@ -211,7 +213,7 @@ public void testFromWithMergeableNodeIssues() throws IOException {
DeprecationIssue foundIssue1 = createTestDeprecationIssue(metaMap1);
DeprecationIssue foundIssue2 = createTestDeprecationIssue(foundIssue1, metaMap2);
List<Function<ClusterState, DeprecationIssue>> clusterSettingsChecks = Collections.emptyList();
List<Function<IndexMetadata, DeprecationIssue>> indexSettingsChecks = List.of((idx) -> null);
List<BiFunction<IndexMetadata, ClusterState, DeprecationIssue>> indexSettingsChecks = List.of((idx, cs) -> null);
List<BiFunction<DataStream, ClusterState, DeprecationIssue>> dataStreamChecks = List.of((ds, cs) -> null);

NodesDeprecationCheckResponse nodeDeprecationIssues = new NodesDeprecationCheckResponse(
Expand Down Expand Up @@ -276,10 +278,12 @@ public void testRemoveSkippedSettings() throws IOException {
return null;
}));
AtomicReference<Settings> visibleIndexSettings = new AtomicReference<>();
List<Function<IndexMetadata, DeprecationIssue>> indexSettingsChecks = Collections.unmodifiableList(Arrays.asList((idx) -> {
visibleIndexSettings.set(idx.getSettings());
return null;
}));
List<BiFunction<IndexMetadata, ClusterState, DeprecationIssue>> indexSettingsChecks = Collections.unmodifiableList(
Arrays.asList((idx, cs) -> {
visibleIndexSettings.set(idx.getSettings());
return null;
})
);
AtomicInteger backingIndicesCount = new AtomicInteger(0);
List<BiFunction<DataStream, ClusterState, DeprecationIssue>> dataStreamChecks = Collections.unmodifiableList(
Arrays.asList((ds, cs) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@

package org.elasticsearch.xpack.deprecation;

import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.cluster.metadata.DataStreamMetadata;
import org.elasticsearch.cluster.metadata.DataStreamOptions;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
Expand All @@ -19,39 +26,89 @@

import java.io.IOException;
import java.util.List;
import java.util.Map;

import static java.util.Collections.singletonList;
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.INDEX_SETTINGS_CHECKS;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;

public class IndexDeprecationChecksTests extends ESTestCase {
public void testOldIndicesCheck() {
IndexVersion createdWith = IndexVersion.fromId(1000099);
IndexVersion createdWith = IndexVersion.fromId(7170099);
IndexMetadata indexMetadata = IndexMetadata.builder("test")
.settings(settings(createdWith))
.numberOfShards(1)
.numberOfReplicas(0)
.build();
ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
.metadata(Metadata.builder().put(indexMetadata, true))
.build();
DeprecationIssue expected = new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
"Old index with a compatibility version < 7.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" + "breaking-changes-8.0.html",
"Old index with a compatibility version < 8.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
"This index has version: " + createdWith.toReleaseVersion(),
false,
null
);
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata));
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata, clusterState));
assertEquals(singletonList(expected), issues);
}

public void testOldIndicesCheckDataStreamIndex() {
IndexVersion createdWith = IndexVersion.fromId(7170099);
IndexMetadata indexMetadata = IndexMetadata.builder(".ds-test")
.settings(settings(createdWith).put("index.hidden", true))
.numberOfShards(1)
.numberOfReplicas(0)
.build();
DataStream dataStream = new DataStream(
randomAlphaOfLength(10),
List.of(indexMetadata.getIndex()),
randomNonNegativeLong(),
Map.of(),
randomBoolean(),
false,
false,
randomBoolean(),
randomFrom(IndexMode.values()),
null,
randomFrom(DataStreamOptions.EMPTY, DataStreamOptions.FAILURE_STORE_DISABLED, DataStreamOptions.FAILURE_STORE_ENABLED, null),
List.of(),
randomBoolean(),
null
);
ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
.metadata(
Metadata.builder()
.put(indexMetadata, true)
.customs(
Map.of(
DataStreamMetadata.TYPE,
new DataStreamMetadata(
ImmutableOpenMap.builder(Map.of("my-data-stream", dataStream)).build(),
ImmutableOpenMap.of()
)
)
)
)
.build();
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata, clusterState));
assertThat(issues.size(), equalTo(0));
}

public void testTranslogRetentionSettings() {
Settings.Builder settings = settings(IndexVersion.current());
settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.getKey(), randomPositiveTimeValue());
settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.getKey(), between(1, 1024) + "b");
IndexMetadata indexMetadata = IndexMetadata.builder("test").settings(settings).numberOfShards(1).numberOfReplicas(0).build();
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata));
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(
INDEX_SETTINGS_CHECKS,
c -> c.apply(indexMetadata, ClusterState.EMPTY_STATE)
);
assertThat(
issues,
contains(
Expand Down Expand Up @@ -81,15 +138,21 @@ public void testDefaultTranslogRetentionSettings() {
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), false);
}
IndexMetadata indexMetadata = IndexMetadata.builder("test").settings(settings).numberOfShards(1).numberOfReplicas(0).build();
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata));
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(
INDEX_SETTINGS_CHECKS,
c -> c.apply(indexMetadata, ClusterState.EMPTY_STATE)
);
assertThat(issues, empty());
}

public void testIndexDataPathSetting() {
Settings.Builder settings = settings(IndexVersion.current());
settings.put(IndexMetadata.INDEX_DATA_PATH_SETTING.getKey(), createTempDir());
IndexMetadata indexMetadata = IndexMetadata.builder("test").settings(settings).numberOfShards(1).numberOfReplicas(0).build();
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata));
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(
INDEX_SETTINGS_CHECKS,
c -> c.apply(indexMetadata, ClusterState.EMPTY_STATE)
);
final String expectedUrl =
"https://www.elastic.co/guide/en/elasticsearch/reference/7.13/breaking-changes-7.13.html#deprecate-shared-data-path-setting";
assertThat(
Expand All @@ -111,7 +174,10 @@ public void testSimpleFSSetting() {
Settings.Builder settings = settings(IndexVersion.current());
settings.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), "simplefs");
IndexMetadata indexMetadata = IndexMetadata.builder("test").settings(settings).numberOfShards(1).numberOfReplicas(0).build();
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata));
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(
INDEX_SETTINGS_CHECKS,
c -> c.apply(indexMetadata, ClusterState.EMPTY_STATE)
);
assertThat(
issues,
contains(
Expand All @@ -133,7 +199,10 @@ public void testFrozenIndex() {
Settings.Builder settings = settings(IndexVersion.current());
settings.put(FrozenEngine.INDEX_FROZEN.getKey(), true);
IndexMetadata indexMetadata = IndexMetadata.builder("test").settings(settings).numberOfShards(1).numberOfReplicas(0).build();
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata));
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(
INDEX_SETTINGS_CHECKS,
c -> c.apply(indexMetadata, ClusterState.EMPTY_STATE)
);
assertThat(
issues,
contains(
Expand Down Expand Up @@ -165,6 +234,9 @@ public void testCamelCaseDeprecation() throws IOException {
.numberOfReplicas(1)
.putMapping(simpleMapping)
.build();
ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
.metadata(Metadata.builder().put(simpleIndex, true))
.build();

DeprecationIssue expected = new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
Expand All @@ -175,7 +247,7 @@ public void testCamelCaseDeprecation() throws IOException {
false,
null
);
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(simpleIndex));
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(simpleIndex, clusterState));
assertThat(issues, hasItem(expected));
}
}

0 comments on commit f76eea0

Please sign in to comment.