forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a deprecation info API warning for data streams with old indices
- Loading branch information
Showing
8 changed files
with
290 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...cation/src/main/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationChecks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.deprecation; | ||
|
||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.DataStream; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.IndexVersions; | ||
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Map.entry; | ||
import static java.util.Map.ofEntries; | ||
|
||
public class DataStreamDeprecationChecks { | ||
static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clusterState) { | ||
List<Index> backingIndices = dataStream.getIndices(); | ||
boolean hasOldIndices = backingIndices.stream() | ||
.anyMatch(index -> clusterState.metadata().index(index).getCompatibilityVersion().before(IndexVersions.V_8_0_0)); | ||
if (hasOldIndices) { | ||
long totalIndices = backingIndices.size(); | ||
List<Index> oldIndices = backingIndices.stream() | ||
.filter(index -> clusterState.metadata().index(index).getCompatibilityVersion().before(IndexVersions.V_8_0_0)) | ||
.toList(); | ||
long totalOldIndices = oldIndices.size(); | ||
long totalOldSearchableSnapshots = oldIndices.stream() | ||
.filter(index -> clusterState.metadata().index(index).isSearchableSnapshot()) | ||
.count(); | ||
long totalOldPartiallyMountedSearchableSnapshots = oldIndices.stream() | ||
.filter(index -> clusterState.metadata().index(index).isPartialSearchableSnapshot()) | ||
.count(); | ||
long totalOldFullyMountedSearchableSnapshots = totalOldSearchableSnapshots - totalOldPartiallyMountedSearchableSnapshots; | ||
return new DeprecationIssue( | ||
DeprecationIssue.Level.CRITICAL, | ||
"Old data stream with a compatibility version < 8.0", | ||
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-8.0.html", | ||
"This data stream has backing indices that were created before Elasticsearch 8.0.0", | ||
false, | ||
ofEntries( | ||
entry( | ||
"backing_indices", | ||
ofEntries( | ||
entry("count", totalIndices), | ||
entry( | ||
"need_upgrading", | ||
ofEntries( | ||
entry("count", totalOldIndices), | ||
entry( | ||
"searchable_snapshots", | ||
ofEntries( | ||
entry("count", totalOldSearchableSnapshots), | ||
entry("fully_mounted", ofEntries(entry("count", totalOldFullyMountedSearchableSnapshots))), | ||
entry( | ||
"partially_mounted", | ||
ofEntries(entry("count", totalOldPartiallyMountedSearchableSnapshots)) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...n/src/test/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationChecksTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.deprecation; | ||
|
||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.DataStream; | ||
import org.elasticsearch.cluster.metadata.DataStreamOptions; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.metadata.Metadata; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.IndexMode; | ||
import org.elasticsearch.index.IndexVersion; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.DATA_STREAM_CHECKS; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class DataStreamDeprecationChecksTests extends ESTestCase { | ||
|
||
public void testOldIndicesCheck() { | ||
long oldIndexCount = randomIntBetween(1, 100); | ||
long newIndexCount = randomIntBetween(1, 100); | ||
long oldSearchableSnapshotCount = 0; | ||
long oldFullyManagedSearchableSnapshotCount = 0; | ||
long oldPartiallyManagedSearchableSnapshotCount = 0; | ||
List<Index> allIndices = new ArrayList<>(); | ||
Map<String, IndexMetadata> nameToIndexMetadata = new HashMap<>(); | ||
for (int i = 0; i < oldIndexCount; i++) { | ||
Settings.Builder settingsBuilder = settings(IndexVersion.fromId(7170099)); | ||
if (randomBoolean()) { | ||
settingsBuilder.put("index.store.type", "snapshot"); | ||
if (randomBoolean()) { | ||
oldFullyManagedSearchableSnapshotCount++; | ||
} else { | ||
settingsBuilder.put("index.store.snapshot.partial", true); | ||
oldPartiallyManagedSearchableSnapshotCount++; | ||
} | ||
oldSearchableSnapshotCount++; | ||
} | ||
IndexMetadata oldIndexMetadata = IndexMetadata.builder("old-data-stream-index-" + i) | ||
.settings(settingsBuilder) | ||
.numberOfShards(1) | ||
.numberOfReplicas(0) | ||
.build(); | ||
allIndices.add(oldIndexMetadata.getIndex()); | ||
nameToIndexMetadata.put(oldIndexMetadata.getIndex().getName(), oldIndexMetadata); | ||
} | ||
for (int i = 0; i < newIndexCount; i++) { | ||
Settings.Builder settingsBuilder = settings(IndexVersion.current()); | ||
if (randomBoolean()) { | ||
settingsBuilder.put("index.store.type", "snapshot"); | ||
} | ||
IndexMetadata newIndexMetadata = IndexMetadata.builder("new-data-stream-index-" + i) | ||
.settings(settingsBuilder) | ||
.numberOfShards(1) | ||
.numberOfReplicas(0) | ||
.build(); | ||
allIndices.add(newIndexMetadata.getIndex()); | ||
nameToIndexMetadata.put(newIndexMetadata.getIndex().getName(), newIndexMetadata); | ||
} | ||
DataStream dataStream = new DataStream( | ||
randomAlphaOfLength(10), | ||
allIndices, | ||
randomNegativeLong(), | ||
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 | ||
); | ||
Metadata metadata = Metadata.builder().indices(nameToIndexMetadata).build(); | ||
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build(); | ||
DeprecationIssue expected = new DeprecationIssue( | ||
DeprecationIssue.Level.CRITICAL, | ||
"Old data stream with a compatibility version < 8.0", | ||
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-8.0.html", | ||
"This data stream has backing indices that were created before Elasticsearch 8.0.0", | ||
false, | ||
Map.of( | ||
"backing_indices", | ||
Map.of( | ||
"count", | ||
oldIndexCount + newIndexCount, | ||
"need_upgrading", | ||
Map.of( | ||
"count", | ||
oldIndexCount, | ||
"searchable_snapshots", | ||
Map.of( | ||
"count", | ||
oldSearchableSnapshotCount, | ||
"fully_mounted", | ||
Map.of("count", oldFullyManagedSearchableSnapshotCount), | ||
"partially_mounted", | ||
Map.of("count", oldPartiallyManagedSearchableSnapshotCount) | ||
) | ||
) | ||
) | ||
) | ||
); | ||
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(DATA_STREAM_CHECKS, c -> c.apply(dataStream, clusterState)); | ||
assertThat(issues, equalTo(singletonList(expected))); | ||
} | ||
} |
Oops, something went wrong.