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.
This commit is contained in:
Gordon Brown 2019-04-12 10:43:04 -06:00 committed by GitHub
parent 9f3fae2c59
commit ef310886a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -34,7 +34,8 @@ public class DeprecationChecks {
static List<Function<ClusterState, DeprecationIssue>> CLUSTER_SETTINGS_CHECKS =
Collections.unmodifiableList(Arrays.asList(
ClusterDeprecationChecks::checkUserAgentPipelines,
ClusterDeprecationChecks::checkTemplatesWithTooManyFields
ClusterDeprecationChecks::checkTemplatesWithTooManyFields,
ClusterDeprecationChecks::checkPollIntervalTooLow
));

View File

@ -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<DeprecationIssue> 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<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(okState));
assertThat(noIssues, Matchers.hasSize(0));
}
}
}