[7.x] Separate aliases used for tests in TimeSeriesLifecycleAc… (#51432)

* Separate aliases used for tests in TimeSeriesLifecycleActionsIT

This is related to #51375 and hopes to help illuminate why some of those tests are failing. This
commit switches the aliases used in the test to use a random alias name every time (since there were
some complaints in the tests about aliases having more than one write index). With this we hope to
determine the actual cause of the failure in the test.

This also adds additional information to the exception returned when calling move-to-step with the
incorrect current step.

* Fix rest test
This commit is contained in:
Lee Hinman 2020-01-24 11:05:19 -07:00 committed by GitHub
parent 931b22349f
commit bdb8b6aa0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 29 deletions

View File

@ -79,11 +79,13 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
private String index; private String index;
private String policy; private String policy;
private String alias;
@Before @Before
public void refreshIndex() { public void refreshIndex() {
index = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); index = "index-" + randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
policy = randomAlphaOfLength(5); policy = "policy-" + randomAlphaOfLength(5);
alias = "alias-" + randomAlphaOfLength(5);
} }
public static void updatePolicy(String indexName, String policy) throws IOException { public static void updatePolicy(String indexName, String policy) throws IOException {
@ -101,7 +103,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4) createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put("index.routing.allocation.include._name", "integTest-0") .put("index.routing.allocation.include._name", "integTest-0")
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias")); .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
// create policy // create policy
createFullPolicy(TimeValue.ZERO); createFullPolicy(TimeValue.ZERO);
@ -163,7 +165,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4) createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put("index.routing.allocation.include._name", "integTest-0") .put("index.routing.allocation.include._name", "integTest-0")
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias")); .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
createFullPolicy(TimeValue.timeValueHours(10)); createFullPolicy(TimeValue.timeValueHours(10));
// update policy on index // update policy on index
@ -243,7 +245,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
String secondIndex = index + "-000002"; String secondIndex = index + "-000002";
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias")); .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
// create policy // create policy
createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L)); createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L));
@ -261,7 +263,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
String secondIndex = index + "-000002"; String secondIndex = index + "-000002";
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias")); .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
Request updateSettingsRequest = new Request("PUT", "/" + originalIndex + "/_settings"); Request updateSettingsRequest = new Request("PUT", "/" + originalIndex + "/_settings");
updateSettingsRequest.setJsonEntity("{\n" + updateSettingsRequest.setJsonEntity("{\n" +
@ -276,7 +278,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
" {\n" + " {\n" +
" \"add\": {\n" + " \"add\": {\n" +
" \"index\": \"" + originalIndex + "\",\n" + " \"index\": \"" + originalIndex + "\",\n" +
" \"alias\": \"alias\",\n" + " \"alias\": \"" + alias + "\",\n" +
" \"is_write_index\": false\n" + " \"is_write_index\": false\n" +
" }\n" + " }\n" +
" }\n" + " }\n" +
@ -785,7 +787,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy) .put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias")); .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
// Index a document // Index a document
index(client(), originalIndex, "_id", "foo", "bar"); index(client(), originalIndex, "_id", "foo", "bar");
@ -803,7 +805,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
addPolicyRequest.setJsonEntity("{\n" + addPolicyRequest.setJsonEntity("{\n" +
" \"settings\": {\n" + " \"settings\": {\n" +
" \"index.lifecycle.name\": \"" + policy + "\",\n" + " \"index.lifecycle.name\": \"" + policy + "\",\n" +
" \"index.lifecycle.rollover_alias\": \"alias\"\n" + " \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
" }\n" + " }\n" +
"}"); "}");
client().performRequest(addPolicyRequest); client().performRequest(addPolicyRequest);
@ -820,7 +822,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 3) createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 3)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy) .put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias")); .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(new StepKey("new", "complete", "complete")))); assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(new StepKey("new", "complete", "complete"))));
@ -856,7 +858,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy) .put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"), .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
true); true);
assertBusy(() -> assertThat(getStepKeyForIndex("test-1"), equalTo(new StepKey("hot", "rollover", "check-rollover-ready")))); assertBusy(() -> assertThat(getStepKeyForIndex("test-1"), equalTo(new StepKey("hot", "rollover", "check-rollover-ready"))));
@ -933,7 +935,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
} }
createIndexWithSettings(goodIndex, Settings.builder() createIndexWithSettings(goodIndex, Settings.builder()
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias") .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy) .put(LifecycleSettings.LIFECYCLE_NAME, policy)
); );
@ -992,7 +994,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy) .put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias") .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
.put("index.blocks.read_only", true), .put("index.blocks.read_only", true),
true true
); );
@ -1027,7 +1029,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
" \"number_of_shards\": 1,\n" + " \"number_of_shards\": 1,\n" +
" \"number_of_replicas\": 0,\n" + " \"number_of_replicas\": 0,\n" +
" \"index.lifecycle.name\": \"" + policy + "\", \n" + " \"index.lifecycle.name\": \"" + policy + "\", \n" +
" \"index.lifecycle.rollover_alias\": \"alias\"\n" + " \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
" }\n" + " }\n" +
"}"); "}");
client().performRequest(createIndexTemplate); client().performRequest(createIndexTemplate);
@ -1045,7 +1047,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
client().performRequest(refreshOriginalIndex); client().performRequest(refreshOriginalIndex);
// Manual rollover // Manual rollover
Request rolloverRequest = new Request("POST", "/alias/_rollover"); Request rolloverRequest = new Request("POST", "/" + alias + "/_rollover");
rolloverRequest.setJsonEntity("{\n" + rolloverRequest.setJsonEntity("{\n" +
" \"conditions\": {\n" + " \"conditions\": {\n" +
" \"max_docs\": \"1\"\n" + " \"max_docs\": \"1\"\n" +
@ -1066,9 +1068,9 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
assertBusy(() -> assertTrue((boolean) explainIndex(secondIndex).getOrDefault("managed", true))); assertBusy(() -> assertTrue((boolean) explainIndex(secondIndex).getOrDefault("managed", true)));
// index some documents to trigger an ILM rollover // index some documents to trigger an ILM rollover
index(client(), "alias", "1", "foo", "bar"); index(client(), alias, "1", "foo", "bar");
index(client(), "alias", "2", "foo", "bar"); index(client(), alias, "2", "foo", "bar");
index(client(), "alias", "3", "foo", "bar"); index(client(), alias, "3", "foo", "bar");
Request refreshSecondIndex = new Request("POST", "/" + secondIndex + "/_refresh"); Request refreshSecondIndex = new Request("POST", "/" + secondIndex + "/_refresh");
client().performRequest(refreshSecondIndex).getStatusLine(); client().performRequest(refreshSecondIndex).getStatusLine();
@ -1088,7 +1090,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
rolledIndex, rolledIndex,
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"), .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
false false
); );
@ -1097,7 +1099,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy) .put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"), .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
true true
); );
@ -1160,7 +1162,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy) .put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"), .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
true true
); );
@ -1200,7 +1202,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
// manual rollover the index so the "update-rollover-lifecycle-date" ILM step can continue and finish successfully as the index // manual rollover the index so the "update-rollover-lifecycle-date" ILM step can continue and finish successfully as the index
// will have rollover information now // will have rollover information now
Request rolloverRequest = new Request("POST", "/alias/_rollover"); Request rolloverRequest = new Request("POST", "/" + alias + "/_rollover");
rolloverRequest.setJsonEntity("{\n" + rolloverRequest.setJsonEntity("{\n" +
" \"conditions\": {\n" + " \"conditions\": {\n" +
" \"max_docs\": \"1\"\n" + " \"max_docs\": \"1\"\n" +
@ -1216,7 +1218,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
String secondIndex = index + "-000002"; String secondIndex = index + "-000002";
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"), .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
true); true);
// create policy // create policy
@ -1258,7 +1260,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
" \"number_of_shards\": 1,\n" + " \"number_of_shards\": 1,\n" +
" \"number_of_replicas\": 0,\n" + " \"number_of_replicas\": 0,\n" +
" \"index.lifecycle.name\": \"" + policy+ "\",\n" + " \"index.lifecycle.name\": \"" + policy+ "\",\n" +
" \"index.lifecycle.rollover_alias\": \"alias\"\n" + " \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
" }\n" + " }\n" +
"}"); "}");
client().performRequest(createIndexTemplate); client().performRequest(createIndexTemplate);
@ -1411,7 +1413,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
" \"number_of_shards\": 1,\n" + " \"number_of_shards\": 1,\n" +
" \"number_of_replicas\": 0,\n" + " \"number_of_replicas\": 0,\n" +
" \"index.lifecycle.name\": \"" + policy+ "\",\n" + " \"index.lifecycle.name\": \"" + policy+ "\",\n" +
" \"index.lifecycle.rollover_alias\": \"alias\"\n" + " \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
" }\n" + " }\n" +
"}"); "}");
client().performRequest(createIndexTemplate); client().performRequest(createIndexTemplate);
@ -1593,7 +1595,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
writeIndexSnippet = "\"is_write_index\": true"; writeIndexSnippet = "\"is_write_index\": true";
} }
request.setJsonEntity("{\n \"settings\": " + Strings.toString(settings.build()) request.setJsonEntity("{\n \"settings\": " + Strings.toString(settings.build())
+ ", \"aliases\" : { \"alias\": { " + writeIndexSnippet + " } } }"); + ", \"aliases\" : { \"" + alias + "\": { " + writeIndexSnippet + " } } }");
client().performRequest(request); client().performRequest(request);
// wait for the shards to initialize // wait for the shards to initialize
ensureGreen(index); ensureGreen(index);

View File

@ -102,7 +102,7 @@ teardown:
action: "forcemerge" action: "forcemerge"
name: "forcemerge" name: "forcemerge"
- match: { error.root_cause.0.type: "illegal_argument_exception" } - match: { error.root_cause.0.type: "illegal_argument_exception" }
- match: { error.root_cause.0.reason: "index [my_index] is not on current step [{\"phase\":\"warm\",\"action\":\"forcemerge\",\"name\":\"forcemerge\"}]" } - match: { error.root_cause.0.reason: "index [my_index] is not on current step [{\"phase\":\"warm\",\"action\":\"forcemerge\",\"name\":\"forcemerge\"}], currently: [{\"phase\":\"new\",\"action\":\"complete\",\"name\":\"complete\"}]" }
- do: - do:

View File

@ -72,8 +72,10 @@ public final class IndexLifecycleTransition {
} }
LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMeta); LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMeta);
if (currentStepKey != null && currentStepKey.equals(LifecycleExecutionState.getCurrentStepKey(lifecycleState)) == false) { Step.StepKey realKey = LifecycleExecutionState.getCurrentStepKey(lifecycleState);
throw new IllegalArgumentException("index [" + indexName + "] is not on current step [" + currentStepKey + "]"); if (currentStepKey != null && currentStepKey.equals(realKey) == false) {
throw new IllegalArgumentException("index [" + indexName + "] is not on current step [" + currentStepKey +
"], currently: [" + realKey + "]");
} }
if (stepRegistry.stepExists(indexPolicySetting, newStepKey) == false) { if (stepRegistry.stepExists(indexPolicySetting, newStepKey) == false) {