Skip to content

Commit 07265aa

Browse files
committed
Update data stream deprecations warnings to new format
1 parent 8d1f456 commit 07265aa

File tree

2 files changed

+38
-75
lines changed

2 files changed

+38
-75
lines changed

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

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,61 +14,37 @@
1414
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
1515

1616
import java.util.List;
17+
import java.util.Set;
18+
import java.util.stream.Collectors;
1719

1820
import static java.util.Map.entry;
1921
import static java.util.Map.ofEntries;
2022

2123
public class DataStreamDeprecationChecks {
2224
static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
2325
List<Index> backingIndices = dataStream.getIndices();
24-
boolean hasOldIndices = backingIndices.stream()
25-
.anyMatch(index -> clusterState.metadata().index(index).getCompatibilityVersion().before(IndexVersions.V_8_0_0));
26-
if (hasOldIndices) {
27-
long totalIndices = backingIndices.size();
28-
List<Index> oldIndices = backingIndices.stream()
29-
.filter(index -> clusterState.metadata().index(index).getCompatibilityVersion().before(IndexVersions.V_8_0_0))
30-
.toList();
31-
long totalOldIndices = oldIndices.size();
32-
long totalOldSearchableSnapshots = oldIndices.stream()
33-
.filter(index -> clusterState.metadata().index(index).isSearchableSnapshot())
34-
.count();
35-
long totalOldPartiallyMountedSearchableSnapshots = oldIndices.stream()
36-
.filter(index -> clusterState.metadata().index(index).isPartialSearchableSnapshot())
37-
.count();
38-
long totalOldFullyMountedSearchableSnapshots = totalOldSearchableSnapshots - totalOldPartiallyMountedSearchableSnapshots;
26+
27+
Set<String> indiciesNeedingUpgrade = backingIndices.stream()
28+
.filter(index -> clusterState.metadata().index(index).getCompatibilityVersion().before(IndexVersions.V_8_0_0))
29+
.map(Index::getName)
30+
.collect(Collectors.toUnmodifiableSet());
31+
32+
if (indiciesNeedingUpgrade.isEmpty() == false) {
3933
return new DeprecationIssue(
4034
DeprecationIssue.Level.CRITICAL,
4135
"Old data stream with a compatibility version < 8.0",
4236
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
4337
"This data stream has backing indices that were created before Elasticsearch 8.0.0",
4438
false,
4539
ofEntries(
46-
entry(
47-
"backing_indices",
48-
ofEntries(
49-
entry("count", totalIndices),
50-
entry(
51-
"need_upgrading",
52-
ofEntries(
53-
entry("count", totalOldIndices),
54-
entry(
55-
"searchable_snapshots",
56-
ofEntries(
57-
entry("count", totalOldSearchableSnapshots),
58-
entry("fully_mounted", ofEntries(entry("count", totalOldFullyMountedSearchableSnapshots))),
59-
entry(
60-
"partially_mounted",
61-
ofEntries(entry("count", totalOldPartiallyMountedSearchableSnapshots))
62-
)
63-
)
64-
)
65-
)
66-
)
67-
)
68-
)
40+
entry("reindex_required", true),
41+
entry("total_backing_indicies", backingIndices.size()),
42+
entry("indicies_requiring_upgrade_count", indiciesNeedingUpgrade.size()),
43+
entry("indicies_requiring_upgrade", indiciesNeedingUpgrade)
6944
)
7045
);
7146
}
47+
7248
return null;
7349
}
7450
}

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationChecksTests.java

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,25 @@
2424
import java.util.HashMap;
2525
import java.util.List;
2626
import java.util.Map;
27+
import java.util.stream.Collectors;
2728

2829
import static java.util.Collections.singletonList;
30+
import static java.util.Map.entry;
31+
import static java.util.Map.ofEntries;
2932
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.DATA_STREAM_CHECKS;
3033
import static org.hamcrest.Matchers.equalTo;
3134

3235
public class DataStreamDeprecationChecksTests extends ESTestCase {
3336

3437
public void testOldIndicesCheck() {
35-
long oldIndexCount = randomIntBetween(1, 100);
36-
long newIndexCount = randomIntBetween(1, 100);
37-
long oldSearchableSnapshotCount = 0;
38-
long oldFullyManagedSearchableSnapshotCount = 0;
39-
long oldPartiallyManagedSearchableSnapshotCount = 0;
38+
int oldIndexCount = randomIntBetween(1, 100);
39+
int newIndexCount = randomIntBetween(1, 100);
40+
4041
List<Index> allIndices = new ArrayList<>();
4142
Map<String, IndexMetadata> nameToIndexMetadata = new HashMap<>();
43+
4244
for (int i = 0; i < oldIndexCount; i++) {
4345
Settings.Builder settingsBuilder = settings(IndexVersion.fromId(7170099));
44-
if (randomBoolean()) {
45-
settingsBuilder.put("index.store.type", "snapshot");
46-
if (randomBoolean()) {
47-
oldFullyManagedSearchableSnapshotCount++;
48-
} else {
49-
settingsBuilder.put("index.store.snapshot.partial", true);
50-
oldPartiallyManagedSearchableSnapshotCount++;
51-
}
52-
oldSearchableSnapshotCount++;
53-
}
5446
IndexMetadata oldIndexMetadata = IndexMetadata.builder("old-data-stream-index-" + i)
5547
.settings(settingsBuilder)
5648
.numberOfShards(1)
@@ -59,11 +51,9 @@ public void testOldIndicesCheck() {
5951
allIndices.add(oldIndexMetadata.getIndex());
6052
nameToIndexMetadata.put(oldIndexMetadata.getIndex().getName(), oldIndexMetadata);
6153
}
54+
6255
for (int i = 0; i < newIndexCount; i++) {
6356
Settings.Builder settingsBuilder = settings(IndexVersion.current());
64-
if (randomBoolean()) {
65-
settingsBuilder.put("index.store.type", "snapshot");
66-
}
6757
IndexMetadata newIndexMetadata = IndexMetadata.builder("new-data-stream-index-" + i)
6858
.settings(settingsBuilder)
6959
.numberOfShards(1)
@@ -72,6 +62,7 @@ public void testOldIndicesCheck() {
7262
allIndices.add(newIndexMetadata.getIndex());
7363
nameToIndexMetadata.put(newIndexMetadata.getIndex().getName(), newIndexMetadata);
7464
}
65+
7566
DataStream dataStream = new DataStream(
7667
randomAlphaOfLength(10),
7768
allIndices,
@@ -88,37 +79,33 @@ public void testOldIndicesCheck() {
8879
randomBoolean(),
8980
null
9081
);
82+
9183
Metadata metadata = Metadata.builder().indices(nameToIndexMetadata).build();
9284
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();
85+
9386
DeprecationIssue expected = new DeprecationIssue(
9487
DeprecationIssue.Level.CRITICAL,
9588
"Old data stream with a compatibility version < 8.0",
9689
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
9790
"This data stream has backing indices that were created before Elasticsearch 8.0.0",
9891
false,
99-
Map.of(
100-
"backing_indices",
101-
Map.of(
102-
"count",
103-
oldIndexCount + newIndexCount,
104-
"need_upgrading",
105-
Map.of(
106-
"count",
107-
oldIndexCount,
108-
"searchable_snapshots",
109-
Map.of(
110-
"count",
111-
oldSearchableSnapshotCount,
112-
"fully_mounted",
113-
Map.of("count", oldFullyManagedSearchableSnapshotCount),
114-
"partially_mounted",
115-
Map.of("count", oldPartiallyManagedSearchableSnapshotCount)
116-
)
117-
)
92+
ofEntries(
93+
entry("reindex_required", true),
94+
entry("total_backing_indicies", oldIndexCount + newIndexCount),
95+
entry("indicies_requiring_upgrade_count", oldIndexCount),
96+
entry(
97+
"indicies_requiring_upgrade",
98+
nameToIndexMetadata.keySet()
99+
.stream()
100+
.filter(name -> name.startsWith("old-data-stream-index-"))
101+
.collect(Collectors.toUnmodifiableSet())
118102
)
119103
)
120104
);
105+
121106
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(DATA_STREAM_CHECKS, c -> c.apply(dataStream, clusterState));
107+
122108
assertThat(issues, equalTo(singletonList(expected)));
123109
}
110+
124111
}

0 commit comments

Comments
 (0)