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
This commit is contained in:
Lee Hinman 2018-10-23 15:20:41 -06:00 committed by GitHub
parent 62ac2fa5ec
commit c5a264e77f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 1 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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