Skip to content

Commit 52fee63

Browse files
authored
deprecation info API: negative index.unassigned.node_left.delayed_timeout (#36454)
This commit adds support to check for negative values for index setting `index.unassigned.node_left.delayed_timeout` for the deprecation info API. relates #36024 relates #26828
1 parent d36ee09 commit 52fee63

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ private DeprecationChecks() {
5252
IndexDeprecationChecks::oldIndicesCheck,
5353
IndexDeprecationChecks::delimitedPayloadFilterCheck,
5454
IndexDeprecationChecks::percolatorUnmappedFieldsAsStringCheck,
55-
IndexDeprecationChecks::indexNameCheck
55+
IndexDeprecationChecks::indexNameCheck,
56+
IndexDeprecationChecks::nodeLeftDelayedTimeCheck
5657
));
5758

5859
/**

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import org.elasticsearch.Version;
1212
import org.elasticsearch.cluster.metadata.IndexMetaData;
1313
import org.elasticsearch.cluster.metadata.MappingMetaData;
14+
import org.elasticsearch.cluster.routing.UnassignedInfo;
15+
import org.elasticsearch.common.Strings;
1416
import org.elasticsearch.common.settings.Settings;
17+
import org.elasticsearch.common.unit.TimeValue;
1518
import org.elasticsearch.index.analysis.AnalysisRegistry;
1619
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
1720

@@ -128,5 +131,22 @@ static DeprecationIssue percolatorUnmappedFieldsAsStringCheck(IndexMetaData inde
128131
"] been removed in favor of [index.percolator.map_unmapped_fields_as_text].");
129132
}
130133
return null;
134+
}
135+
136+
static DeprecationIssue nodeLeftDelayedTimeCheck(IndexMetaData indexMetaData) {
137+
String setting = UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey();
138+
String value = indexMetaData.getSettings().get(setting);
139+
if (Strings.isNullOrEmpty(value) == false) {
140+
TimeValue parsedValue = TimeValue.parseTimeValue(value, setting);
141+
if (parsedValue.getNanos() < 0) {
142+
return new DeprecationIssue(DeprecationIssue.Level.WARNING,
143+
"Negative values for " + setting + " are deprecated and should be set to 0",
144+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
145+
"#_literal_index_unassigned_node_left_delayed_timeout_literal_may_no_longer_be_negative",
146+
"The index [" + indexMetaData.getIndex().getName() + "] has [" + setting + "] set to [" + value +
147+
"], but negative values are not allowed");
148+
}
149+
}
150+
return null;
131151
}
132152
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.elasticsearch.Version;
99
import org.elasticsearch.cluster.metadata.IndexMetaData;
10+
import org.elasticsearch.cluster.routing.UnassignedInfo;
1011
import org.elasticsearch.common.settings.Settings;
1112
import org.elasticsearch.test.ESTestCase;
1213
import org.elasticsearch.test.VersionUtils;
@@ -106,4 +107,33 @@ public void testPercolatorUnmappedFieldsAsStringCheck() {
106107
List<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(goodIndex));
107108
assertTrue(noIssues.isEmpty());
108109
}
110+
111+
public void testNodeLeftDelayedTimeCheck() {
112+
String negativeTimeValue = "-" + randomPositiveTimeValue();
113+
String indexName = randomAlphaOfLengthBetween(0, 10);
114+
String setting = UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey();
115+
116+
final IndexMetaData badIndex = IndexMetaData.builder(indexName)
117+
.settings(settings(Version.CURRENT).put(setting, negativeTimeValue))
118+
.numberOfShards(randomIntBetween(1, 100))
119+
.numberOfReplicas(randomIntBetween(1, 15))
120+
.build();
121+
DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING,
122+
"Negative values for " + setting + " are deprecated and should be set to 0",
123+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
124+
"#_literal_index_unassigned_node_left_delayed_timeout_literal_may_no_longer_be_negative",
125+
"The index [" + indexName + "] has [" + setting + "] set to [" + negativeTimeValue +
126+
"], but negative values are not allowed");
127+
128+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(badIndex));
129+
assertEquals(singletonList(expected), issues);
130+
131+
final IndexMetaData goodIndex = IndexMetaData.builder(indexName)
132+
.settings(settings(Version.CURRENT))
133+
.numberOfShards(randomIntBetween(1, 100))
134+
.numberOfReplicas(randomIntBetween(1, 15))
135+
.build();
136+
List<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(goodIndex));
137+
assertTrue(noIssues.isEmpty());
138+
}
109139
}

0 commit comments

Comments
 (0)