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:
parent
9f3fae2c59
commit
ef310886a7
|
@ -10,6 +10,8 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
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.index.IndexSettings;
|
||||||
import org.elasticsearch.ingest.IngestService;
|
import org.elasticsearch.ingest.IngestService;
|
||||||
import org.elasticsearch.ingest.PipelineConfiguration;
|
import org.elasticsearch.ingest.PipelineConfiguration;
|
||||||
|
@ -23,6 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.elasticsearch.search.SearchModule.INDICES_MAX_CLAUSE_COUNT_SETTING;
|
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 {
|
public class ClusterDeprecationChecks {
|
||||||
private static final Logger logger = LogManager.getLogger(ClusterDeprecationChecks.class);
|
private static final Logger logger = LogManager.getLogger(ClusterDeprecationChecks.class);
|
||||||
|
@ -88,4 +91,29 @@ public class ClusterDeprecationChecks {
|
||||||
}
|
}
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,8 @@ public class DeprecationChecks {
|
||||||
static List<Function<ClusterState, DeprecationIssue>> CLUSTER_SETTINGS_CHECKS =
|
static List<Function<ClusterState, DeprecationIssue>> CLUSTER_SETTINGS_CHECKS =
|
||||||
Collections.unmodifiableList(Arrays.asList(
|
Collections.unmodifiableList(Arrays.asList(
|
||||||
ClusterDeprecationChecks::checkUserAgentPipelines,
|
ClusterDeprecationChecks::checkUserAgentPipelines,
|
||||||
ClusterDeprecationChecks::checkTemplatesWithTooManyFields
|
ClusterDeprecationChecks::checkTemplatesWithTooManyFields,
|
||||||
|
ClusterDeprecationChecks::checkPollIntervalTooLow
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.elasticsearch.index.IndexSettings;
|
||||||
import org.elasticsearch.ingest.IngestService;
|
import org.elasticsearch.ingest.IngestService;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
|
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
|
||||||
|
import org.hamcrest.Matchers;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -26,6 +27,7 @@ import java.util.List;
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
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.DeprecationChecks.CLUSTER_SETTINGS_CHECKS;
|
||||||
import static org.elasticsearch.xpack.deprecation.IndexDeprecationChecksTests.addRandomFields;
|
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.");
|
"to fail if fields are not explicitly specified in the query.");
|
||||||
assertEquals(singletonList(expected), issues);
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue