Skip to content

Commit cea1ca2

Browse files
authored
Add rollover to watcher history ILM policy (#82603)
In `7.x` watcher history was kept for 7 days with daily index pattern and ILM policy that had only delete phase. In `8.x` we've moved to data stream but policy was not updated so watcher history index would grow forever. This change fixes that by adding rollover. 3 days rollover and 4 days delete mean that data will be kept for 7 days as before.
1 parent 4348a94 commit cea1ca2

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ protected Set<String> preserveILMPolicyIds() {
571571
"ilm-history-ilm-policy",
572572
"slm-history-ilm-policy",
573573
"watch-history-ilm-policy",
574+
"watch-history-ilm-policy-16",
574575
"ml-size-based-ilm-policy",
575576
"logs",
576577
"metrics",

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/WatcherIndexTemplateRegistryField.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public final class WatcherIndexTemplateRegistryField {
2121
// version 13: add `allow_auto_create` setting
2222
// version 14: move watch history to data stream
2323
// version 15: remove watches and triggered watches, these are now system indices
24+
// version 16: change watch history ILM policy
2425
// Note: if you change this, also inform the kibana team around the watcher-ui
25-
public static final int INDEX_TEMPLATE_VERSION = 14;
26+
public static final int INDEX_TEMPLATE_VERSION = 16;
2627
public static final String HISTORY_TEMPLATE_NAME = ".watch-history-" + INDEX_TEMPLATE_VERSION;
2728
public static final String HISTORY_TEMPLATE_NAME_NO_ILM = ".watch-history-no-ilm-" + INDEX_TEMPLATE_VERSION;
2829
public static final String[] TEMPLATE_NAMES = new String[] { HISTORY_TEMPLATE_NAME };

x-pack/plugin/core/src/main/resources/watch-history-ilm-policy.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
22
"phases": {
3+
"hot": {
4+
"actions": {
5+
"rollover": {
6+
"max_age": "3d",
7+
"max_primary_shard_size": "50gb"
8+
}
9+
}
10+
},
311
"delete": {
4-
"min_age": "7d",
12+
"min_age": "4d",
513
"actions": {
614
"delete": {}
715
}

x-pack/plugin/core/src/main/resources/watch-history.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"index.number_of_shards": 1,
1010
"index.number_of_replicas": 0,
1111
"index.auto_expand_replicas": "0-1",
12-
"index.lifecycle.name": "watch-history-ilm-policy",
12+
"index.lifecycle.name": "watch-history-ilm-policy-16",
1313
"index.hidden": true,
1414
"index.format": 6
1515
},

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected Map<String, ComposableIndexTemplate> getComposableTemplateConfigs() {
6767
}
6868

6969
private static final List<LifecyclePolicy> LIFECYCLE_POLICIES = List.of(
70-
new LifecyclePolicyConfig("watch-history-ilm-policy", "/watch-history-ilm-policy.json").load(
70+
new LifecyclePolicyConfig("watch-history-ilm-policy-16", "/watch-history-ilm-policy.json").load(
7171
LifecyclePolicyConfig.DEFAULT_X_CONTENT_REGISTRY
7272
)
7373
);

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void testThatNonExistingTemplatesAreAddedImmediately() {
140140
.filter(r -> r.name().equals(WatcherIndexTemplateRegistryField.HISTORY_TEMPLATE_NAME))
141141
.findFirst()
142142
.orElseThrow(() -> new AssertionError("expected the watch history template to be put"));
143-
assertThat(req.indexTemplate().template().settings().get("index.lifecycle.name"), equalTo("watch-history-ilm-policy"));
143+
assertThat(req.indexTemplate().template().settings().get("index.lifecycle.name"), equalTo("watch-history-ilm-policy-16"));
144144
}
145145

146146
public void testThatNonExistingTemplatesAreAddedEvenWithILMUsageDisabled() {

0 commit comments

Comments
 (0)