From ef310886a7860fa5a2b246efff537d6fa1857756 Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Fri, 12 Apr 2019 10:43:04 -0600 Subject: [PATCH] Add deprecation check for ILM poll interval <1s (#41096) ILM poll intervals of less than 1 second will not be allowed, so add a deprecation check for that. Even though I'm pretty sure zero production clusters will do this, it's best to be thorough. --- .../deprecation/ClusterDeprecationChecks.java | 28 +++++++++++++ .../xpack/deprecation/DeprecationChecks.java | 3 +- .../ClusterDeprecationChecksTests.java | 40 +++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecks.java index 1a71f094fc1..57a474744b6 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecks.java @@ -10,6 +10,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.MappingMetaData; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.ingest.IngestService; import org.elasticsearch.ingest.PipelineConfiguration; @@ -23,6 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import static org.elasticsearch.search.SearchModule.INDICES_MAX_CLAUSE_COUNT_SETTING; +import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING; public class ClusterDeprecationChecks { private static final Logger logger = LogManager.getLogger(ClusterDeprecationChecks.class); @@ -88,4 +91,29 @@ public class ClusterDeprecationChecks { } return null; } + + static DeprecationIssue checkPollIntervalTooLow(ClusterState state) { + String pollIntervalString = state.metaData().settings().get(LIFECYCLE_POLL_INTERVAL_SETTING.getKey()); + if (Strings.isNullOrEmpty(pollIntervalString)) { + return null; + } + + TimeValue pollInterval; + try { + pollInterval = TimeValue.parseTimeValue(pollIntervalString, LIFECYCLE_POLL_INTERVAL_SETTING.getKey()); + } catch (IllegalArgumentException e) { + logger.error("Failed to parse [{}] value: [{}]", LIFECYCLE_POLL_INTERVAL_SETTING.getKey(), pollIntervalString); + return null; + } + + if (pollInterval.compareTo(TimeValue.timeValueSeconds(1)) < 0) { + return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, + "Index Lifecycle Management poll interval is set too low", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-8.0.html" + + "#ilm-poll-interval-limit", + "The Index Lifecycle Management poll interval setting [" + LIFECYCLE_POLL_INTERVAL_SETTING.getKey() + "] is " + + "currently set to [" + pollIntervalString + "], but must be 1s or greater"); + } + return null; + } } 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 b70c7c4fa32..3a7dcd786f5 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 @@ -34,7 +34,8 @@ public class DeprecationChecks { static List> CLUSTER_SETTINGS_CHECKS = Collections.unmodifiableList(Arrays.asList( ClusterDeprecationChecks::checkUserAgentPipelines, - ClusterDeprecationChecks::checkTemplatesWithTooManyFields + ClusterDeprecationChecks::checkTemplatesWithTooManyFields, + ClusterDeprecationChecks::checkPollIntervalTooLow )); diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecksTests.java index 990958e766c..14158082f08 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecksTests.java @@ -19,6 +19,7 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.ingest.IngestService; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; +import org.hamcrest.Matchers; import java.io.IOException; import java.util.Collections; @@ -26,6 +27,7 @@ import java.util.List; import static java.util.Collections.singletonList; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING; import static org.elasticsearch.xpack.deprecation.DeprecationChecks.CLUSTER_SETTINGS_CHECKS; import static org.elasticsearch.xpack.deprecation.IndexDeprecationChecksTests.addRandomFields; @@ -155,4 +157,42 @@ public class ClusterDeprecationChecksTests extends ESTestCase { "to fail if fields are not explicitly specified in the query."); assertEquals(singletonList(expected), issues); } + + public void testPollIntervalTooLow() { + { + final String tooLowInterval = randomTimeValue(1, 999, "ms", "micros", "nanos"); + MetaData badMetaDtata = MetaData.builder() + .persistentSettings(Settings.builder() + .put(LIFECYCLE_POLL_INTERVAL_SETTING.getKey(), tooLowInterval) + .build()) + .build(); + ClusterState badState = ClusterState.builder(new ClusterName("test")) + .metaData(badMetaDtata) + .build(); + + DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.CRITICAL, + "Index Lifecycle Management poll interval is set too low", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-8.0.html" + + "#ilm-poll-interval-limit", + "The Index Lifecycle Management poll interval setting [" + LIFECYCLE_POLL_INTERVAL_SETTING.getKey() + "] is " + + "currently set to [" + tooLowInterval + "], but must be 1s or greater"); + List issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(badState)); + assertEquals(singletonList(expected), issues); + } + + // Test that other values are ok + { + final String okInterval = randomTimeValue(1, 9999, "d", "h", "s"); + MetaData okMetaData = MetaData.builder() + .persistentSettings(Settings.builder() + .put(LIFECYCLE_POLL_INTERVAL_SETTING.getKey(), okInterval) + .build()) + .build(); + ClusterState okState = ClusterState.builder(new ClusterName("test")) + .metaData(okMetaData) + .build(); + List noIssues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(okState)); + assertThat(noIssues, Matchers.hasSize(0)); + } + } }