From eb71eb1a34eb9874e14b1f0069b18d197081aa3a Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Tue, 23 Jul 2019 11:12:16 -0600 Subject: [PATCH 1/6] Add option to filter ILM explain response In order to make it easier to interpret the output of the ILM Explain API, this commit adds two request parameters to that API: - `only_managed`, which causes the response to only contain indices which have `index.lifecycle.name` set - `only_errors`, which causes the response to contain only indices in an ILM error state "Error state" is defined as either being in the `ERROR` step or having `index.lifecycle.name` set to a policy that does not exist. --- .../ExplainLifecycleRequest.java | 46 ++++++++++++++++-- .../ExplainLifecycleRequestTests.java | 34 ++++++++++---- .../xpack/ilm/IndexLifecycleService.java | 4 ++ .../action/RestExplainLifecycleAction.java | 4 +- .../TransportExplainLifecycleAction.java | 47 ++++++++++++------- 5 files changed, 106 insertions(+), 29 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ExplainLifecycleRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ExplainLifecycleRequest.java index 037de2d505292..01e70dcce0920 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ExplainLifecycleRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ExplainLifecycleRequest.java @@ -6,9 +6,11 @@ package org.elasticsearch.xpack.core.indexlifecycle; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.info.ClusterInfoRequest; import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; import java.util.Arrays; @@ -21,6 +23,10 @@ * {@link #indices(String...)} method */ public class ExplainLifecycleRequest extends ClusterInfoRequest { + private static final Version FILTERS_INTRODUCED_VERSION = Version.V_8_0_0; + + private boolean onlyErrors = false; + private boolean onlyManaged = false; public ExplainLifecycleRequest() { super(); @@ -28,6 +34,37 @@ public ExplainLifecycleRequest() { public ExplainLifecycleRequest(StreamInput in) throws IOException { super(in); + if (in.getVersion().onOrAfter(FILTERS_INTRODUCED_VERSION)) { + onlyErrors = in.readBoolean(); + onlyManaged = in.readBoolean(); + } + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + if (out.getVersion().onOrAfter(FILTERS_INTRODUCED_VERSION)) { + out.writeBoolean(onlyErrors); + out.writeBoolean(onlyManaged); + } + } + + public boolean onlyErrors() { + return onlyErrors; + } + + public ExplainLifecycleRequest onlyErrors(boolean onlyErrors) { + this.onlyErrors = onlyErrors; + return this; + } + + public boolean onlyManaged() { + return onlyManaged; + } + + public ExplainLifecycleRequest onlyManaged(boolean onlyManaged) { + this.onlyManaged = onlyManaged; + return this; } @Override @@ -37,7 +74,7 @@ public ActionRequestValidationException validate() { @Override public int hashCode() { - return Objects.hash(Arrays.hashCode(indices()), indicesOptions()); + return Objects.hash(Arrays.hashCode(indices()), indicesOptions(), onlyErrors, onlyManaged); } @Override @@ -50,12 +87,15 @@ public boolean equals(Object obj) { } ExplainLifecycleRequest other = (ExplainLifecycleRequest) obj; return Objects.deepEquals(indices(), other.indices()) && - Objects.equals(indicesOptions(), other.indicesOptions()); + Objects.equals(indicesOptions(), other.indicesOptions()) && + Objects.equals(onlyErrors(), other.onlyErrors()) && + Objects.equals(onlyManaged(), other.onlyManaged()); } @Override public String toString() { - return "ExplainLifecycleRequest [indices()=" + Arrays.toString(indices()) + ", indicesOptions()=" + indicesOptions() + "]"; + return "ExplainLifecycleRequest [indices()=" + Arrays.toString(indices()) + ", indicesOptions()=" + indicesOptions() + + ", onlyErrors()=" + onlyErrors() + ", onlyManaged()=" + onlyManaged() + "]"; } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ExplainLifecycleRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ExplainLifecycleRequestTests.java index 4c1ffac49a244..e8a96376d739c 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ExplainLifecycleRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ExplainLifecycleRequestTests.java @@ -26,6 +26,12 @@ protected ExplainLifecycleRequest createTestInstance() { randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()); request.indicesOptions(indicesOptions); } + if (randomBoolean()) { + request.onlyErrors(randomBoolean()); + } + if (randomBoolean()) { + request.onlyManaged(randomBoolean()); + } return request; } @@ -33,21 +39,31 @@ protected ExplainLifecycleRequest createTestInstance() { protected ExplainLifecycleRequest mutateInstance(ExplainLifecycleRequest instance) throws IOException { String[] indices = instance.indices(); IndicesOptions indicesOptions = instance.indicesOptions(); - switch (between(0, 1)) { - case 0: - indices = randomValueOtherThanMany(i -> Arrays.equals(i, instance.indices()), + boolean onlyErrors = instance.onlyErrors(); + boolean onlyManaged = instance.onlyManaged(); + switch (between(0, 3)) { + case 0: + indices = randomValueOtherThanMany(i -> Arrays.equals(i, instance.indices()), () -> generateRandomStringArray(20, 10, false, false)); - break; - case 1: - indicesOptions = randomValueOtherThan(indicesOptions, () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), + break; + case 1: + indicesOptions = randomValueOtherThan(indicesOptions, () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean())); - break; - default: - throw new AssertionError("Illegal randomisation branch"); + break; + case 2: + onlyErrors = !onlyErrors; + break; + case 3: + onlyManaged = !onlyManaged; + break; + default: + throw new AssertionError("Illegal randomisation branch"); } ExplainLifecycleRequest newRequest = new ExplainLifecycleRequest(); newRequest.indices(indices); newRequest.indicesOptions(indicesOptions); + newRequest.onlyErrors(onlyErrors); + newRequest.onlyManaged(onlyManaged); return newRequest; } diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java index 97b4bf5504e52..c38419fa9923a 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java @@ -214,6 +214,10 @@ public void triggered(SchedulerEngine.Event event) { } } + public boolean policyExists(String policyId) { + return policyRegistry.policyExists(policyId); + } + /** * executes the policy execution on the appropriate indices by running cluster-state tasks per index. * diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java index 2d6a451b6889a..85807a77dfb07 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java @@ -10,11 +10,11 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xpack.core.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; +import org.elasticsearch.xpack.core.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.xpack.core.indexlifecycle.action.ExplainLifecycleAction; import java.io.IOException; @@ -37,6 +37,8 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient ExplainLifecycleRequest explainLifecycleRequest = new ExplainLifecycleRequest(); explainLifecycleRequest.indices(indexes); explainLifecycleRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, IndicesOptions.strictExpandOpen())); + explainLifecycleRequest.onlyManaged(restRequest.paramAsBoolean("only_managed", false)); + explainLifecycleRequest.onlyErrors(restRequest.paramAsBoolean("only_errors", false)); String masterNodeTimeout = restRequest.param("master_timeout"); if (masterNodeTimeout != null) { explainLifecycleRequest.masterNodeTimeout(masterNodeTimeout); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java index e5e2e051acff3..f19ba30997e41 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.core.indexlifecycle.ErrorStep; import org.elasticsearch.xpack.core.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.xpack.core.indexlifecycle.ExplainLifecycleResponse; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleExplainResponse; @@ -34,6 +35,7 @@ import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; import org.elasticsearch.xpack.core.indexlifecycle.PhaseExecutionInfo; import org.elasticsearch.xpack.core.indexlifecycle.action.ExplainLifecycleAction; +import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleService; import java.io.IOException; import java.util.HashMap; @@ -43,14 +45,16 @@ public class TransportExplainLifecycleAction extends TransportClusterInfoAction { private final NamedXContentRegistry xContentRegistry; + private final IndexLifecycleService indexLifecycleService; @Inject public TransportExplainLifecycleAction(TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, - NamedXContentRegistry xContentRegistry) { + NamedXContentRegistry xContentRegistry, IndexLifecycleService indexLifecycleService) { super(ExplainLifecycleAction.NAME, transportService, clusterService, threadPool, actionFilters, ExplainLifecycleRequest::new, indexNameExpressionResolver); this.xContentRegistry = xContentRegistry; + this.indexLifecycleService = indexLifecycleService; } @Override @@ -73,7 +77,7 @@ protected ClusterBlockException checkBlock(ExplainLifecycleRequest request, Clus @Override protected void doMasterOperation(ExplainLifecycleRequest request, String[] concreteIndices, ClusterState state, ActionListener listener) { - Map indexReponses = new HashMap<>(); + Map indexResponses = new HashMap<>(); for (String index : concreteIndices) { IndexMetaData idxMetadata = state.metaData().index(index); Settings idxSettings = idxMetadata.getSettings(); @@ -100,23 +104,34 @@ protected void doMasterOperation(ExplainLifecycleRequest request, String[] concr } final IndexLifecycleExplainResponse indexResponse; if (Strings.hasLength(policyName)) { - indexResponse = IndexLifecycleExplainResponse.newManagedIndexResponse(index, policyName, - lifecycleState.getLifecycleDate(), - lifecycleState.getPhase(), - lifecycleState.getAction(), - lifecycleState.getStep(), - lifecycleState.getFailedStep(), - lifecycleState.getPhaseTime(), - lifecycleState.getActionTime(), - lifecycleState.getStepTime(), - stepInfoBytes, - phaseExecutionInfo); - } else { + // If this is requesting only errors, only include indices in the error step or which are using a nonexistent policy + if (request.onlyErrors() == false + || (ErrorStep.NAME.equals(lifecycleState.getStep()) || indexLifecycleService.policyExists(policyName) == false)) { + indexResponse = IndexLifecycleExplainResponse.newManagedIndexResponse(index, policyName, + lifecycleState.getLifecycleDate(), + lifecycleState.getPhase(), + lifecycleState.getAction(), + lifecycleState.getStep(), + lifecycleState.getFailedStep(), + lifecycleState.getPhaseTime(), + lifecycleState.getActionTime(), + lifecycleState.getStepTime(), + stepInfoBytes, + phaseExecutionInfo); + } else { + indexResponse = null; + } + } else if (request.onlyManaged() == false && request.onlyErrors() == false) { indexResponse = IndexLifecycleExplainResponse.newUnmanagedIndexResponse(index); + } else { + indexResponse = null; + } + + if (indexResponse != null) { + indexResponses.put(indexResponse.getIndex(), indexResponse); } - indexReponses.put(indexResponse.getIndex(), indexResponse); } - listener.onResponse(new ExplainLifecycleResponse(indexReponses)); + listener.onResponse(new ExplainLifecycleResponse(indexResponses)); } } From 5015eb7b60ae9c85684c2db72a704dc40111872c Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Tue, 23 Jul 2019 11:48:02 -0600 Subject: [PATCH 2/6] Document new parameters --- docs/reference/ilm/apis/explain.asciidoc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/reference/ilm/apis/explain.asciidoc b/docs/reference/ilm/apis/explain.asciidoc index 85855d18beae6..3aa2572175eda 100644 --- a/docs/reference/ilm/apis/explain.asciidoc +++ b/docs/reference/ilm/apis/explain.asciidoc @@ -26,6 +26,15 @@ about any failures. ==== Request Parameters +`only_managed`:: + (boolean) Filters the returned indices to only indices that are managed by + ILM. + +`only_errors`:: + (boolean) Filters the returned indices to only indices that are managed by + ILM and are in an error state, either due to an encountering an error while + executing the policy, or attempting to use a policy that does not exist. + include::{docdir}/rest-api/timeoutparms.asciidoc[] ==== Authorization From 4c13f5464edb9481de33a2c81aaf356916ce724b Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Tue, 23 Jul 2019 13:37:38 -0600 Subject: [PATCH 3/6] Integration test --- .../ilm/TimeSeriesLifecycleActionsIT.java | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java index 21ee948299d1d..38dcbfb0ba7e9 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java @@ -54,9 +54,11 @@ import static java.util.Collections.singletonMap; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; @@ -829,6 +831,45 @@ public void testCanStopILMWithPolicyUsingNonexistentPolicy() throws Exception { assertOK(client().performRequest(startILMReqest)); } + public void testExplainFilters() throws Exception { + String goodIndex = index + "-good-000001"; + String errorIndex = index + "-error"; + String nonexistantPolicyIndex = index + "-nonexistant-policy"; + String unmanagedIndex = index + "-unmanaged"; + + createFullPolicy(TimeValue.ZERO); + + createIndexWithSettings(goodIndex, Settings.builder() + .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias") + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .put(LifecycleSettings.LIFECYCLE_NAME, policy)); + createIndexWithSettingsNoAlias(errorIndex, Settings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .put(LifecycleSettings.LIFECYCLE_NAME, policy)); + createIndexWithSettingsNoAlias(nonexistantPolicyIndex, Settings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .put(LifecycleSettings.LIFECYCLE_NAME, randomValueOtherThan(policy, () -> randomAlphaOfLengthBetween(3,10)))); + createIndexWithSettingsNoAlias(unmanagedIndex, Settings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); + + assertBusy(() -> { + Map> explainResponse = explain(index + "*", false, false); + assertNotNull(explainResponse); + assertThat(explainResponse, + allOf(hasKey(goodIndex), hasKey(errorIndex), hasKey(nonexistantPolicyIndex), hasKey(unmanagedIndex))); + + Map> onlyManagedResponse = explain(index + "*", false, true); + assertNotNull(onlyManagedResponse); + assertThat(onlyManagedResponse, allOf(hasKey(goodIndex), hasKey(errorIndex), hasKey(nonexistantPolicyIndex))); + assertThat(onlyManagedResponse, not(hasKey(unmanagedIndex))); + + Map> onlyErrorsResponse = explain(index + "*", true, randomBoolean()); + assertNotNull(onlyErrorsResponse); + assertThat(onlyErrorsResponse, allOf(hasKey(errorIndex), hasKey(nonexistantPolicyIndex))); + assertThat(onlyErrorsResponse, allOf(not(hasKey(goodIndex)), not(hasKey(unmanagedIndex)))); + }); + } + private void createFullPolicy(TimeValue hotTime) throws IOException { Map hotActions = new HashMap<>(); hotActions.put(SetPriorityAction.NAME, new SetPriorityAction(100)); @@ -948,15 +989,21 @@ private String getReasonForIndex(String indexName) throws IOException { } private Map explainIndex(String indexName) throws IOException { - Request explainRequest = new Request("GET", indexName + "/_ilm/explain"); + return explain(indexName, false, false).get(indexName); + } + + private Map> explain(String indexPattern, boolean onlyErrors, boolean onlyManaged) throws IOException { + Request explainRequest = new Request("GET", indexPattern + "/_ilm/explain"); + explainRequest.addParameter("only_errors", Boolean.toString(onlyErrors)); + explainRequest.addParameter("only_managed", Boolean.toString(onlyManaged)); Response response = client().performRequest(explainRequest); Map responseMap; try (InputStream is = response.getEntity().getContent()) { responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true); } - @SuppressWarnings("unchecked") Map indexResponse = ((Map>) responseMap.get("indices")) - .get(indexName); + @SuppressWarnings("unchecked") Map> indexResponse = + ((Map>) responseMap.get("indices")); return indexResponse; } From ff01d63c5e3695f5f60dd7acbb2abf2c12eb37f6 Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Tue, 23 Jul 2019 14:17:59 -0600 Subject: [PATCH 4/6] Update spec --- .../rest-api-spec/api/ilm.explain_lifecycle.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/ilm.explain_lifecycle.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/ilm.explain_lifecycle.json index 8c48b22a5eba5..9b80525946fca 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/api/ilm.explain_lifecycle.json +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/ilm.explain_lifecycle.json @@ -11,7 +11,16 @@ "description" : "The name of the index to explain" } }, - "params": {} + "params": { + "only_managed": { + "type": "boolean", + "description": "filters the indices included in the response to ones managed by ILM" + }, + "only_errors": { + "type": "boolean", + "description": "filters the indices included in the response to ones in an ILM error state, implies only_managed" + } + } }, "body": null } From e0d72c8010b9dd35075f7fe5ea1f663b0eb8cdf1 Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Tue, 23 Jul 2019 17:03:38 -0600 Subject: [PATCH 5/6] Fix import for indexlifecycle->ilm package change --- .../xpack/ilm/action/TransportExplainLifecycleAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java index f19ba30997e41..460764768dfbe 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java @@ -35,7 +35,7 @@ import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; import org.elasticsearch.xpack.core.indexlifecycle.PhaseExecutionInfo; import org.elasticsearch.xpack.core.indexlifecycle.action.ExplainLifecycleAction; -import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleService; +import org.elasticsearch.xpack.ilm.IndexLifecycleService; import java.io.IOException; import java.util.HashMap; From 4fb56a538f31c0a59b3ceebf181f9d7fb3d4da7e Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Wed, 24 Jul 2019 17:56:15 -0600 Subject: [PATCH 6/6] YAML tests --- .../test/ilm/40_explain_lifecycle.yml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/x-pack/plugin/ilm/qa/rest/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml b/x-pack/plugin/ilm/qa/rest/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml index baa051103d5fa..81f7064f8ce9a 100644 --- a/x-pack/plugin/ilm/qa/rest/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml +++ b/x-pack/plugin/ilm/qa/rest/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml @@ -60,6 +60,12 @@ setup: - do: indices.create: index: my_index_no_policy + - do: + indices.create: + index: index_with_policy_that_doesnt_exist + body: + settings: + index.lifecycle.name: "a_policy_that_doesnt_exist" --- teardown: @@ -81,6 +87,10 @@ teardown: indices.delete: index: my_index_no_policy + - do: + indices.delete: + index: index_with_policy_that_doesnt_exist + - do: ilm.delete_lifecycle: policy: "my_moveable_timeseries_lifecycle" @@ -112,6 +122,7 @@ teardown: - is_false: indices.my_index2 - is_false: indices.another_index - is_false: indices.unmanaged_index + - is_false: indices.index_with_policy_that_doesnt_exist --- "Test Wildcard Index Lifecycle Explain": @@ -146,6 +157,7 @@ teardown: - is_false: indices.another_index - is_false: indices.unmanaged_index + - is_false: indices.index_with_policy_that_doesnt_exist --- @@ -201,6 +213,16 @@ teardown: - is_false: indices.another_index.failed_step - is_false: indices.another_index.step_info + - match: { indices.index_with_policy_that_doesnt_exist.index: "index_with_policy_that_doesnt_exist" } + - match: { indices.index_with_policy_that_doesnt_exist.policy: "a_policy_that_doesnt_exist" } + - match: { indices.index_with_policy_that_doesnt_exist.step_info.reason: "policy [a_policy_that_doesnt_exist] does not exist" } + - is_true: indices.index_with_policy_that_doesnt_exist.managed + - is_false: indices.index_with_policy_that_doesnt_exist.phase + - is_false: indices.index_with_policy_that_doesnt_exist.action + - is_false: indices.index_with_policy_that_doesnt_exist.step + - is_false: indices.index_with_policy_that_doesnt_exist.age + - is_false: indices.index_with_policy_that_doesnt_exist.failed_step + --- "Test Unmanaged Index Lifecycle Explain": @@ -221,3 +243,34 @@ teardown: - is_false: indices.my_index - is_false: indices.my_index2 - is_false: indices.another_index + - is_false: indices.index_with_policy_that_doesnt_exist + +--- +"Test filter for only managed indices": + + - do: + ilm.explain_lifecycle: + index: "*" + only_managed: true + + - match: { indices.my_index.index: "my_index" } + - match: { indices.my_index2.index: "my_index2" } + - match: { indices.another_index.index: "another_index" } + - match: { indices.index_with_policy_that_doesnt_exist.index: "index_with_policy_that_doesnt_exist" } + - is_false: indices.unmanaged_index + - is_false: indices.my_index_no_policy + +--- +"Test filter for only error indices": + + - do: + ilm.explain_lifecycle: + index: "*" + only_errors: true + + - match: { indices.index_with_policy_that_doesnt_exist.index: "index_with_policy_that_doesnt_exist" } + - is_false: indices.unmanaged_index + - is_false: indices.my_index_no_policy + - is_false: indices.my_index + - is_false: indices.my_index2 + - is_false: indices.another_index