From c5a264e77f2bc577b2ede77b1c1156c2aa33e66d Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Tue, 23 Oct 2018 15:20:41 -0600 Subject: [PATCH] Ensure phase_time is set when in the "new" phase (#34280) Since there's no transition into the "new" phase it wasn't set until the "hot" phase, so now we initialize it when initializing the policy context. Resolves #34277 --- x-pack/docs/en/ilm/apis/explain.asciidoc | 2 +- .../indexlifecycle/IndexLifecycleRunner.java | 8 +++ .../test/ilm/40_explain_lifecycle.yml | 56 +++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/x-pack/docs/en/ilm/apis/explain.asciidoc b/x-pack/docs/en/ilm/apis/explain.asciidoc index 30a94d61e88..5c4855fad85 100644 --- a/x-pack/docs/en/ilm/apis/explain.asciidoc +++ b/x-pack/docs/en/ilm/apis/explain.asciidoc @@ -115,7 +115,7 @@ When the index is first taken over by ILM you will see a response like the follo -------------------------------------------------- // CONSOLE // TESTRESPONSE[s/"lifecycle_date": 1538475653281/"lifecycle_date": $body.indices.my_index.lifecycle_date/] -// TESTRESPONSE[s/"phase_time": 1538475653317/"phase_time": null/] +// TESTRESPONSE[s/"phase_time": 1538475653317/"phase_time": $body.indices.my_index.phase_time/] // TESTRESPONSE[s/"action_time": 1538475653317/"action_time": $body.indices.my_index.action_time/] // TESTRESPONSE[s/"step_time": 1538475653317/"step_time": $body.indices.my_index.step_time/] <1> Shows if the index is being managed by ILM. If the index is not managed by diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java index 6251980fc21..e5f74175c5a 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java @@ -29,6 +29,7 @@ import org.elasticsearch.xpack.core.indexlifecycle.ClusterStateActionStep; import org.elasticsearch.xpack.core.indexlifecycle.ClusterStateWaitStep; import org.elasticsearch.xpack.core.indexlifecycle.ErrorStep; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; +import org.elasticsearch.xpack.core.indexlifecycle.InitializePolicyContextStep; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState; import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; @@ -396,7 +397,14 @@ public class IndexLifecycleRunner { newPhaseDefinition = Strings.toString(phaseExecutionInfo, false, false); updatedState.setPhaseDefinition(newPhaseDefinition); updatedState.setPhaseTime(nowAsMillis); + } else if (currentStep.getPhase().equals(InitializePolicyContextStep.INITIALIZATION_PHASE)) { + // The "new" phase is the initialization phase, usually the phase + // time would be set on phase transition, but since there is no + // transition into the "new" phase, we set it any time in the "new" + // phase + updatedState.setPhaseTime(nowAsMillis); } + if (currentStep.getAction().equals(nextStep.getAction()) == false) { updatedState.setActionTime(nowAsMillis); } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml index 25800465164..18248189917 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml @@ -112,6 +112,7 @@ teardown: - match: { indices.my_index.phase: "new" } - match: { indices.my_index.action: "complete" } - match: { indices.my_index.step: "complete" } + - is_true: indices.my_index.phase_time - is_false: indices.my_index.failed_step - is_false: indices.my_index.step_info - is_false: indices.my_index.phase_execution @@ -134,6 +135,7 @@ teardown: - match: { indices.my_index.phase: "new" } - match: { indices.my_index.action: "complete" } - match: { indices.my_index.step: "complete" } + - is_true: indices.my_index.phase_time - is_false: indices.my_index.failed_step - is_false: indices.my_index.step_info - is_false: indices.my_index.phase_execution @@ -144,6 +146,7 @@ teardown: - match: { indices.my_index2.phase: "new" } - match: { indices.my_index2.action: "complete" } - match: { indices.my_index2.step: "complete" } + - is_true: indices.my_index2.phase_time - is_false: indices.my_index2.failed_step - is_false: indices.my_index2.step_info - is_false: indices.my_index2.phase_execution @@ -166,6 +169,7 @@ teardown: - match: { indices.my_index.phase: "new" } - match: { indices.my_index.action: "complete" } - match: { indices.my_index.step: "complete" } + - is_true: indices.my_index.phase_time - is_false: indices.my_index.failed_step - is_false: indices.my_index.step_info - is_false: indices.my_index.phase_execution @@ -176,6 +180,7 @@ teardown: - match: { indices.my_index2.phase: "new" } - match: { indices.my_index2.action: "complete" } - match: { indices.my_index2.step: "complete" } + - is_true: indices.my_index2.phase_time - is_false: indices.my_index2.failed_step - is_false: indices.my_index2.step_info - is_false: indices.my_index2.phase_execution @@ -186,6 +191,7 @@ teardown: - match: { indices.another_index.phase: "new" } - match: { indices.another_index.action: "complete" } - match: { indices.another_index.step: "complete" } + - is_true: indices.another_index.phase_time - is_false: indices.another_index.failed_step - is_false: indices.another_index.step_info - is_false: indices.another_index.phase_execution @@ -219,3 +225,53 @@ teardown: - is_false: indices.my_index - is_false: indices.my_index2 - is_false: indices.another_index + +--- +"Test new phase still has phase_time": + + - do: + acknowlege: true + ilm.put_lifecycle: + policy: "mypolicy" + body: | + { + "policy": { + "phases": { + "hot": { + "minimum_age": "1000s", + "actions": {} + }, + "warm": { + "minimum_age": "2000s", + "actions": { + "forcemerge": { + "max_num_segments": 10000 + } + } + } + } + } + } + + - do: + indices.create: + index: foo + body: + settings: + index.lifecycle.name: "mypolicy" + + - do: + acknowledge: true + ilm.explain_lifecycle: + index: "foo" + + - is_true: indices.foo.managed + - match: { indices.foo.index: "foo" } + - match: { indices.foo.policy: "mypolicy" } + - match: { indices.foo.phase: "new" } + - match: { indices.foo.action: "complete" } + - match: { indices.foo.step: "complete" } + - is_true: indices.foo.phase_time + - is_false: indices.foo.failed_step + - is_false: indices.foo.step_info + - is_false: indices.foo.phase_execution