From 52fee63a3c50d5dcae3401f4619bc6404e87d620 Mon Sep 17 00:00:00 2001 From: Jake Landis Date: Thu, 13 Dec 2018 06:58:54 -0600 Subject: [PATCH] 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 --- .../xpack/deprecation/DeprecationChecks.java | 3 +- .../deprecation/IndexDeprecationChecks.java | 20 +++++++++++++ .../IndexDeprecationChecksTests.java | 30 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index ecb4c789ba81f..63e2c013f5dc3 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -52,7 +52,8 @@ private DeprecationChecks() { IndexDeprecationChecks::oldIndicesCheck, IndexDeprecationChecks::delimitedPayloadFilterCheck, IndexDeprecationChecks::percolatorUnmappedFieldsAsStringCheck, - IndexDeprecationChecks::indexNameCheck + IndexDeprecationChecks::indexNameCheck, + IndexDeprecationChecks::nodeLeftDelayedTimeCheck )); /** diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java index d95c2508106d5..a67e4f2271d7e 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java @@ -11,7 +11,10 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; +import org.elasticsearch.cluster.routing.UnassignedInfo; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.analysis.AnalysisRegistry; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; @@ -128,5 +131,22 @@ static DeprecationIssue percolatorUnmappedFieldsAsStringCheck(IndexMetaData inde "] been removed in favor of [index.percolator.map_unmapped_fields_as_text]."); } return null; + } + + static DeprecationIssue nodeLeftDelayedTimeCheck(IndexMetaData indexMetaData) { + String setting = UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(); + String value = indexMetaData.getSettings().get(setting); + if (Strings.isNullOrEmpty(value) == false) { + TimeValue parsedValue = TimeValue.parseTimeValue(value, setting); + if (parsedValue.getNanos() < 0) { + return new DeprecationIssue(DeprecationIssue.Level.WARNING, + "Negative values for " + setting + " are deprecated and should be set to 0", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" + + "#_literal_index_unassigned_node_left_delayed_timeout_literal_may_no_longer_be_negative", + "The index [" + indexMetaData.getIndex().getName() + "] has [" + setting + "] set to [" + value + + "], but negative values are not allowed"); + } + } + return null; } } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java index 5b13edbc45e29..a01854ea1865e 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java @@ -7,6 +7,7 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.VersionUtils; @@ -106,4 +107,33 @@ public void testPercolatorUnmappedFieldsAsStringCheck() { List noIssues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(goodIndex)); assertTrue(noIssues.isEmpty()); } + + public void testNodeLeftDelayedTimeCheck() { + String negativeTimeValue = "-" + randomPositiveTimeValue(); + String indexName = randomAlphaOfLengthBetween(0, 10); + String setting = UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(); + + final IndexMetaData badIndex = IndexMetaData.builder(indexName) + .settings(settings(Version.CURRENT).put(setting, negativeTimeValue)) + .numberOfShards(randomIntBetween(1, 100)) + .numberOfReplicas(randomIntBetween(1, 15)) + .build(); + DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING, + "Negative values for " + setting + " are deprecated and should be set to 0", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" + + "#_literal_index_unassigned_node_left_delayed_timeout_literal_may_no_longer_be_negative", + "The index [" + indexName + "] has [" + setting + "] set to [" + negativeTimeValue + + "], but negative values are not allowed"); + + List issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(badIndex)); + assertEquals(singletonList(expected), issues); + + final IndexMetaData goodIndex = IndexMetaData.builder(indexName) + .settings(settings(Version.CURRENT)) + .numberOfShards(randomIntBetween(1, 100)) + .numberOfReplicas(randomIntBetween(1, 15)) + .build(); + List noIssues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(goodIndex)); + assertTrue(noIssues.isEmpty()); + } }