Skip to content

Commit ef31088

Browse files
authored
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.
1 parent 9f3fae2 commit ef31088

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecks.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.apache.logging.log4j.Logger;
1111
import org.elasticsearch.cluster.ClusterState;
1212
import org.elasticsearch.cluster.metadata.MappingMetaData;
13+
import org.elasticsearch.common.Strings;
14+
import org.elasticsearch.common.unit.TimeValue;
1315
import org.elasticsearch.index.IndexSettings;
1416
import org.elasticsearch.ingest.IngestService;
1517
import org.elasticsearch.ingest.PipelineConfiguration;
@@ -23,6 +25,7 @@
2325
import java.util.stream.Collectors;
2426

2527
import static org.elasticsearch.search.SearchModule.INDICES_MAX_CLAUSE_COUNT_SETTING;
28+
import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING;
2629

2730
public class ClusterDeprecationChecks {
2831
private static final Logger logger = LogManager.getLogger(ClusterDeprecationChecks.class);
@@ -88,4 +91,29 @@ static DeprecationIssue checkTemplatesWithTooManyFields(ClusterState state) {
8891
}
8992
return null;
9093
}
94+
95+
static DeprecationIssue checkPollIntervalTooLow(ClusterState state) {
96+
String pollIntervalString = state.metaData().settings().get(LIFECYCLE_POLL_INTERVAL_SETTING.getKey());
97+
if (Strings.isNullOrEmpty(pollIntervalString)) {
98+
return null;
99+
}
100+
101+
TimeValue pollInterval;
102+
try {
103+
pollInterval = TimeValue.parseTimeValue(pollIntervalString, LIFECYCLE_POLL_INTERVAL_SETTING.getKey());
104+
} catch (IllegalArgumentException e) {
105+
logger.error("Failed to parse [{}] value: [{}]", LIFECYCLE_POLL_INTERVAL_SETTING.getKey(), pollIntervalString);
106+
return null;
107+
}
108+
109+
if (pollInterval.compareTo(TimeValue.timeValueSeconds(1)) < 0) {
110+
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
111+
"Index Lifecycle Management poll interval is set too low",
112+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-8.0.html" +
113+
"#ilm-poll-interval-limit",
114+
"The Index Lifecycle Management poll interval setting [" + LIFECYCLE_POLL_INTERVAL_SETTING.getKey() + "] is " +
115+
"currently set to [" + pollIntervalString + "], but must be 1s or greater");
116+
}
117+
return null;
118+
}
91119
}

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ private DeprecationChecks() {
3434
static List<Function<ClusterState, DeprecationIssue>> CLUSTER_SETTINGS_CHECKS =
3535
Collections.unmodifiableList(Arrays.asList(
3636
ClusterDeprecationChecks::checkUserAgentPipelines,
37-
ClusterDeprecationChecks::checkTemplatesWithTooManyFields
37+
ClusterDeprecationChecks::checkTemplatesWithTooManyFields,
38+
ClusterDeprecationChecks::checkPollIntervalTooLow
3839
));
3940

4041

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecksTests.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
import org.elasticsearch.ingest.IngestService;
2020
import org.elasticsearch.test.ESTestCase;
2121
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
22+
import org.hamcrest.Matchers;
2223

2324
import java.io.IOException;
2425
import java.util.Collections;
2526
import java.util.List;
2627

2728
import static java.util.Collections.singletonList;
2829
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
30+
import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING;
2931
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.CLUSTER_SETTINGS_CHECKS;
3032
import static org.elasticsearch.xpack.deprecation.IndexDeprecationChecksTests.addRandomFields;
3133

@@ -155,4 +157,42 @@ public void testTemplateWithTooManyFields() throws IOException {
155157
"to fail if fields are not explicitly specified in the query.");
156158
assertEquals(singletonList(expected), issues);
157159
}
160+
161+
public void testPollIntervalTooLow() {
162+
{
163+
final String tooLowInterval = randomTimeValue(1, 999, "ms", "micros", "nanos");
164+
MetaData badMetaDtata = MetaData.builder()
165+
.persistentSettings(Settings.builder()
166+
.put(LIFECYCLE_POLL_INTERVAL_SETTING.getKey(), tooLowInterval)
167+
.build())
168+
.build();
169+
ClusterState badState = ClusterState.builder(new ClusterName("test"))
170+
.metaData(badMetaDtata)
171+
.build();
172+
173+
DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
174+
"Index Lifecycle Management poll interval is set too low",
175+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-8.0.html" +
176+
"#ilm-poll-interval-limit",
177+
"The Index Lifecycle Management poll interval setting [" + LIFECYCLE_POLL_INTERVAL_SETTING.getKey() + "] is " +
178+
"currently set to [" + tooLowInterval + "], but must be 1s or greater");
179+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(badState));
180+
assertEquals(singletonList(expected), issues);
181+
}
182+
183+
// Test that other values are ok
184+
{
185+
final String okInterval = randomTimeValue(1, 9999, "d", "h", "s");
186+
MetaData okMetaData = MetaData.builder()
187+
.persistentSettings(Settings.builder()
188+
.put(LIFECYCLE_POLL_INTERVAL_SETTING.getKey(), okInterval)
189+
.build())
190+
.build();
191+
ClusterState okState = ClusterState.builder(new ClusterName("test"))
192+
.metaData(okMetaData)
193+
.build();
194+
List<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(okState));
195+
assertThat(noIssues, Matchers.hasSize(0));
196+
}
197+
}
158198
}

0 commit comments

Comments
 (0)