From d9d85563bd7ba0d9aebd01a880224fe347f3a8da Mon Sep 17 00:00:00 2001 From: Jake Landis Date: Mon, 10 Dec 2018 15:19:00 -0600 Subject: [PATCH 1/3] deprecation info API: negative index.unassigned.node_left.delayed_timeout 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 | 19 +++++++++++++ .../IndexDeprecationChecksTests.java | 28 +++++++++++++++++++ 3 files changed, 49 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 164f0ec77b146..58a131ba9f66d 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 @@ -48,7 +48,8 @@ private DeprecationChecks() { Collections.unmodifiableList(Arrays.asList( IndexDeprecationChecks::oldIndicesCheck, IndexDeprecationChecks::delimitedPayloadFilterCheck, - 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 5134d86f51891..0ed6ecb3042e2 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; @@ -116,4 +119,20 @@ static DeprecationIssue indexNameCheck(IndexMetaData indexMetaData) { } 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 index.unassigned.node_left.delayed_timeout 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() + " is set to " + value); + } + } + 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 8255461c1bcdd..2afb7b679499f 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; @@ -76,4 +77,31 @@ public void testIndexNameCheck(){ 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); + + final IndexMetaData badIndex = IndexMetaData.builder(indexName) + .settings(settings(Version.CURRENT).put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), negativeTimeValue)) + .numberOfShards(randomIntBetween(1, 100)) + .numberOfReplicas(randomIntBetween(1, 15)) + .build(); + DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING, + "Negative values for index.unassigned.node_left.delayed_timeout 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 + " is set to " + negativeTimeValue); + + 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()); + } } From dabf08726e092d78584b56344e7758066502ad2b Mon Sep 17 00:00:00 2001 From: Jake Landis Date: Mon, 10 Dec 2018 17:00:19 -0600 Subject: [PATCH 2/3] minor: add [ ] around index name --- .../elasticsearch/xpack/deprecation/IndexDeprecationChecks.java | 2 +- .../xpack/deprecation/IndexDeprecationChecksTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 0ed6ecb3042e2..e7fccb5991ed3 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 @@ -130,7 +130,7 @@ static DeprecationIssue nodeLeftDelayedTimeCheck(IndexMetaData indexMetaData) { "Negative values for index.unassigned.node_left.delayed_timeout 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() + " is set to " + value); + "The index [" + indexMetaData.getIndex().getName() + "] is set to " + value); } } 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 2afb7b679499f..7f9bb8b52cb0e 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 @@ -91,7 +91,7 @@ public void testNodeLeftDelayedTimeCheck() { "Negative values for index.unassigned.node_left.delayed_timeout 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 + " is set to " + negativeTimeValue); + "The index [" + indexName + "] is set to " + negativeTimeValue); List issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(badIndex)); assertEquals(singletonList(expected), issues); From fadef9b8e85c25d5c51fcc1ca421a8e598b85420 Mon Sep 17 00:00:00 2001 From: Jake Landis Date: Tue, 11 Dec 2018 08:50:58 -0600 Subject: [PATCH 3/3] review changes: use variable and fix message --- .../xpack/deprecation/IndexDeprecationChecks.java | 5 +++-- .../xpack/deprecation/IndexDeprecationChecksTests.java | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) 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 e7fccb5991ed3..8976963292093 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 @@ -127,10 +127,11 @@ static DeprecationIssue nodeLeftDelayedTimeCheck(IndexMetaData indexMetaData) { TimeValue parsedValue = TimeValue.parseTimeValue(value, setting); if (parsedValue.getNanos() < 0) { return new DeprecationIssue(DeprecationIssue.Level.WARNING, - "Negative values for index.unassigned.node_left.delayed_timeout are deprecated and should be set to 0", + "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() + "] is set to " + value); + "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 7f9bb8b52cb0e..0305e82940c43 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 @@ -81,17 +81,19 @@ public void testIndexNameCheck(){ 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(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), negativeTimeValue)) + .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 index.unassigned.node_left.delayed_timeout are deprecated and should be set to 0", + "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 + "] is set to " + negativeTimeValue); + "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);