Skip to content

Commit 5adbf67

Browse files
authored
Add ILM histore store index (#50287)
* Add ILM histore store index This commit adds an ILM history store that tracks the lifecycle execution state as an index progresses through its ILM policy. ILM history documents store output similar to what the ILM explain API returns. An example document with ALL fields (not all documents will have all fields) would look like: ```json { "@timestamp": 1203012389, "policy": "my-ilm-policy", "index": "index-2019.1.1-000023", "index_age":123120, "success": true, "state": { "phase": "warm", "action": "allocate", "step": "ERROR", "failed_step": "update-settings", "is_auto-retryable_error": true, "creation_date": 12389012039, "phase_time": 12908389120, "action_time": 1283901209, "step_time": 123904107140, "phase_definition": "{\"policy\":\"ilm-history-ilm-policy\",\"phase_definition\":{\"min_age\":\"0ms\",\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}},\"version\":1,\"modified_date_in_millis\":1576517253463}", "step_info": "{... etc step info here as json ...}" }, "error_details": "java.lang.RuntimeException: etc\n\tcaused by:etc etc etc full stacktrace" } ``` These documents go into the `ilm-history-1-00000N` index to provide an audit trail of the operations ILM has performed. This history storage is enabled by default but can be disabled by setting `index.lifecycle.history_index_enabled` to `false.` Resolves #49180
1 parent a3ca04d commit 5adbf67

File tree

27 files changed

+1419
-75
lines changed

27 files changed

+1419
-75
lines changed

client/rest-high-level/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ testClusters.all {
138138
setting 'xpack.security.authc.realms.pki.pki1.delegation.enabled', 'true'
139139

140140
setting 'indices.lifecycle.poll_interval', '1000ms'
141+
setting 'index.lifecycle.history_index_enabled', 'false'
141142
keystore 'xpack.security.transport.ssl.truststore.secure_password', 'testnode'
142143
extraConfigFile 'roles.yml', file('roles.yml')
143144
user username: System.getProperty('tests.rest.cluster.username', 'test_user'),

docs/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ testClusters.integTest {
6060
extraConfigFile 'hunspell/en_US/en_US.dic', project(":server").file('src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.dic')
6161
// Whitelist reindexing from the local node so we can test it.
6262
setting 'reindex.remote.whitelist', '127.0.0.1:*'
63+
setting 'index.lifecycle.history_index_enabled', 'false'
6364

6465
// TODO: remove this once cname is prepended to transport.publish_address by default in 8.0
6566
systemProperty 'es.transport.cname_in_publish_address', 'true'

docs/plugins/analysis-icu.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ PUT my_index
368368
}
369369
}
370370
371-
GET _search <3>
371+
GET /my_index/_search <3>
372372
{
373373
"query": {
374374
"match": {

docs/reference/indices/rollover-index.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ PUT logs/_doc/2 <2>
428428
//////////////////////////
429429
[source,console]
430430
--------------------------------------------------
431-
GET _alias
431+
GET my_logs_index-000001,my_logs_index-000002/_alias
432432
--------------------------------------------------
433433
// TEST[continued]
434434
//////////////////////////

docs/reference/settings/ilm-settings.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ ILM REST API endpoints and functionality. Defaults to `true`.
1414
(<<time-units, time units>>) How often {ilm} checks for indices that meet policy
1515
criteria. Defaults to `10m`.
1616

17+
`index.lifecycle.history_index_enabled`::
18+
Whether ILM's history index is enabled. If enabled, ILM will record the
19+
history of actions taken as part of ILM policies to the `ilm-history-*`
20+
indices. Defaults to `true`.
21+
1722
==== Index level settings
1823
These index-level {ilm-init} settings are typically configured through index
1924
templates. For more information, see <<ilm-gs-create-policy>>.

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import java.security.cert.CertificateException;
7676
import java.util.ArrayList;
7777
import java.util.Arrays;
78+
import java.util.Collections;
7879
import java.util.HashMap;
7980
import java.util.HashSet;
8081
import java.util.List;
@@ -448,6 +449,13 @@ protected boolean preserveILMPoliciesUponCompletion() {
448449
return false;
449450
}
450451

452+
/**
453+
* A set of ILM policies that should be preserved between runs.
454+
*/
455+
protected Set<String> preserveILMPolicyIds() {
456+
return Collections.singleton("ilm-history-ilm-policy");
457+
}
458+
451459
/**
452460
* Returns whether to preserve auto-follow patterns. Defaults to not
453461
* preserving them. Only runs at all if xpack is installed on the cluster
@@ -545,7 +553,7 @@ private void wipeCluster() throws Exception {
545553
}
546554

547555
if (hasXPack && false == preserveILMPoliciesUponCompletion()) {
548-
deleteAllILMPolicies();
556+
deleteAllILMPolicies(preserveILMPolicyIds());
549557
}
550558

551559
if (hasXPack && false == preserveAutoFollowPatternsUponCompletion()) {
@@ -680,7 +688,7 @@ private void waitForPendingRollupTasks() throws Exception {
680688
waitForPendingTasks(adminClient(), taskName -> taskName.startsWith("xpack/rollup/job") == false);
681689
}
682690

683-
private static void deleteAllILMPolicies() throws IOException {
691+
private static void deleteAllILMPolicies(Set<String> exclusions) throws IOException {
684692
Map<String, Object> policies;
685693

686694
try {
@@ -699,9 +707,15 @@ private static void deleteAllILMPolicies() throws IOException {
699707
return;
700708
}
701709

702-
for (String policyName : policies.keySet()) {
703-
adminClient().performRequest(new Request("DELETE", "/_ilm/policy/" + policyName));
704-
}
710+
policies.keySet().stream()
711+
.filter(p -> exclusions.contains(p) == false)
712+
.forEach(policyName -> {
713+
try {
714+
adminClient().performRequest(new Request("DELETE", "/_ilm/policy/" + policyName));
715+
} catch (IOException e) {
716+
throw new RuntimeException("failed to delete policy: " + policyName, e);
717+
}
718+
});
705719
}
706720

707721
private static void deleteAllSLMPolicies() throws IOException {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleSettings.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class LifecycleSettings {
1919
public static final String LIFECYCLE_INDEXING_COMPLETE = "index.lifecycle.indexing_complete";
2020
public static final String LIFECYCLE_ORIGINATION_DATE = "index.lifecycle.origination_date";
2121
public static final String LIFECYCLE_PARSE_ORIGINATION_DATE = "index.lifecycle.parse_origination_date";
22+
public static final String LIFECYCLE_HISTORY_INDEX_ENABLED = "index.lifecycle.history_index_enabled";
2223

2324
public static final String SLM_HISTORY_INDEX_ENABLED = "slm.history_index_enabled";
2425
public static final String SLM_RETENTION_SCHEDULE = "slm.retention_schedule";
@@ -35,6 +36,8 @@ public class LifecycleSettings {
3536
Setting.longSetting(LIFECYCLE_ORIGINATION_DATE, -1, -1, Setting.Property.Dynamic, Setting.Property.IndexScope);
3637
public static final Setting<Boolean> LIFECYCLE_PARSE_ORIGINATION_DATE_SETTING = Setting.boolSetting(LIFECYCLE_PARSE_ORIGINATION_DATE,
3738
false, Setting.Property.Dynamic, Setting.Property.IndexScope);
39+
public static final Setting<Boolean> LIFECYCLE_HISTORY_INDEX_ENABLED_SETTING = Setting.boolSetting(LIFECYCLE_HISTORY_INDEX_ENABLED,
40+
true, Setting.Property.NodeScope);
3841

3942

4043
public static final Setting<Boolean> SLM_HISTORY_INDEX_ENABLED_SETTING = Setting.boolSetting(SLM_HISTORY_INDEX_ENABLED, true,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"phases": {
3+
"hot": {
4+
"actions": {
5+
"rollover": {
6+
"max_size": "50GB",
7+
"max_age": "30d"
8+
}
9+
}
10+
},
11+
"delete": {
12+
"min_age": "90d",
13+
"actions": {
14+
"delete": {}
15+
}
16+
}
17+
}
18+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"index_patterns": [
3+
"ilm-history-${xpack.ilm_history.template.version}*"
4+
],
5+
"order": 2147483647,
6+
"settings": {
7+
"index.number_of_shards": 1,
8+
"index.number_of_replicas": 0,
9+
"index.auto_expand_replicas": "0-1",
10+
"index.lifecycle.name": "ilm-history-ilm-policy",
11+
"index.lifecycle.rollover_alias": "ilm-history-${xpack.ilm_history.template.version}",
12+
"index.format": 1
13+
},
14+
"mappings": {
15+
"_doc": {
16+
"dynamic": false,
17+
"properties": {
18+
"@timestamp": {
19+
"type": "date",
20+
"format": "epoch_millis"
21+
},
22+
"policy": {
23+
"type": "keyword"
24+
},
25+
"index": {
26+
"type": "keyword"
27+
},
28+
"index_age":{
29+
"type": "long"
30+
},
31+
"success": {
32+
"type": "boolean"
33+
},
34+
"state": {
35+
"type": "object",
36+
"dynamic": true,
37+
"properties": {
38+
"phase": {
39+
"type": "keyword"
40+
},
41+
"action": {
42+
"type": "keyword"
43+
},
44+
"step": {
45+
"type": "keyword"
46+
},
47+
"failed_step": {
48+
"type": "keyword"
49+
},
50+
"is_auto-retryable_error": {
51+
"type": "keyword"
52+
},
53+
"creation_date": {
54+
"type": "date",
55+
"format": "epoch_millis"
56+
},
57+
"phase_time": {
58+
"type": "date",
59+
"format": "epoch_millis"
60+
},
61+
"action_time": {
62+
"type": "date",
63+
"format": "epoch_millis"
64+
},
65+
"step_time": {
66+
"type": "date",
67+
"format": "epoch_millis"
68+
},
69+
"phase_definition": {
70+
"type": "text"
71+
},
72+
"step_info": {
73+
"type": "text"
74+
}
75+
}
76+
},
77+
"error_details": {
78+
"type": "text"
79+
}
80+
}
81+
}
82+
}
83+
}

x-pack/plugin/ilm/qa/multi-node/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ testClusters.integTest {
2525
setting 'xpack.ml.enabled', 'false'
2626
setting 'xpack.license.self_generated.type', 'trial'
2727
setting 'indices.lifecycle.poll_interval', '1000ms'
28+
setting 'logger.org.elasticsearch.xpack.core.ilm', 'TRACE'
29+
setting 'logger.org.elasticsearch.xpack.ilm', 'TRACE'
2830
}

0 commit comments

Comments
 (0)