/
IndexDeprecationChecksTests.java
181 lines (168 loc) · 8.91 KB
/
IndexDeprecationChecksTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* 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.metadata.IndexMetadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.engine.frozen.FrozenEngine;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
import java.io.IOException;
import java.util.List;
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.hasItem;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
public class IndexDeprecationChecksTests extends ESTestCase {
public void testOldIndicesCheck() {
IndexVersion createdWith = IndexVersion.fromId(1000099);
IndexMetadata indexMetadata = IndexMetadata.builder("test")
.settings(settings(createdWith))
.numberOfShards(1)
.numberOfReplicas(0)
.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",
"This index has version: " + createdWith.toReleaseVersion(),
false,
null
);
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata));
assertEquals(singletonList(expected), issues);
}
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));
assertThat(
issues,
contains(
new DeprecationIssue(
DeprecationIssue.Level.WARNING,
"translog retention settings are ignored",
"https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-translog.html",
"translog retention settings [index.translog.retention.size] and [index.translog.retention.age] are ignored "
+ "because translog is no longer used in peer recoveries with soft-deletes enabled (default in 7.0 or later)",
false,
DeprecationIssue.createMetaMapForRemovableSettings(
List.of(
IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.getKey(),
IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.getKey()
)
)
)
)
);
}
public void testDefaultTranslogRetentionSettings() {
Settings.Builder settings = settings(IndexVersion.current());
if (randomBoolean()) {
settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.getKey(), randomPositiveTimeValue());
settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.getKey(), between(1, 1024) + "b");
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));
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));
final String expectedUrl =
"https://www.elastic.co/guide/en/elasticsearch/reference/7.13/breaking-changes-7.13.html#deprecate-shared-data-path-setting";
assertThat(
issues,
contains(
new DeprecationIssue(
DeprecationIssue.Level.WARNING,
"setting [index.data_path] is deprecated and will be removed in a future version",
expectedUrl,
"Found index data path configured. Discontinue use of this setting.",
false,
null
)
)
);
}
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));
assertThat(
issues,
contains(
new DeprecationIssue(
DeprecationIssue.Level.WARNING,
"[simplefs] is deprecated and will be removed in future versions",
"https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-store.html",
"[simplefs] is deprecated and will be removed in 8.0. Use [niofs] or other file systems instead. "
+ "Elasticsearch 7.15 or later uses [niofs] for the [simplefs] store type "
+ "as it offers superior or equivalent performance to [simplefs].",
false,
null
)
)
);
}
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));
assertThat(
issues,
contains(
new DeprecationIssue(
DeprecationIssue.Level.WARNING,
"index [test] is a frozen index. The frozen indices feature is deprecated and will be removed in a future version",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/frozen-indices.html",
"Frozen indices no longer offer any advantages. Consider cold or frozen tiers in place of frozen indices.",
false,
null
)
)
);
}
public void testCamelCaseDeprecation() throws IOException {
String simpleMapping = "{\n\"_doc\": {"
+ "\"properties\" : {\n"
+ " \"date_time_field\" : {\n"
+ " \"type\" : \"date\",\n"
+ " \"format\" : \"strictDateOptionalTime\"\n"
+ " }\n"
+ " }"
+ "} }";
IndexMetadata simpleIndex = IndexMetadata.builder(randomAlphaOfLengthBetween(5, 10))
.settings(settings(IndexVersions.V_7_0_0))
.numberOfShards(1)
.numberOfReplicas(1)
.putMapping(simpleMapping)
.build();
DeprecationIssue expected = new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
"Date fields use deprecated camel case formats",
"https://ela.st/es-deprecation-7-camel-case-format",
"Convert [date_time_field] format [strictDateOptionalTime] "
+ "which contains deprecated camel case to snake case. [strictDateOptionalTime] to [strict_date_optional_time].",
false,
null
);
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(simpleIndex));
assertThat(issues, hasItem(expected));
}
}