Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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;
Expand All @@ -23,6 +25,7 @@
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);
Expand Down Expand Up @@ -88,4 +91,29 @@ static DeprecationIssue checkTemplatesWithTooManyFields(ClusterState state) {
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ private DeprecationChecks() {
static List<Function<ClusterState, DeprecationIssue>> CLUSTER_SETTINGS_CHECKS =
Collections.unmodifiableList(Arrays.asList(
ClusterDeprecationChecks::checkUserAgentPipelines,
ClusterDeprecationChecks::checkTemplatesWithTooManyFields
ClusterDeprecationChecks::checkTemplatesWithTooManyFields,
ClusterDeprecationChecks::checkPollIntervalTooLow
));


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
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;
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;

Expand Down Expand Up @@ -155,4 +157,42 @@ public void testTemplateWithTooManyFields() throws IOException {
"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));
}
}
}