Skip to content

Commit b4f2047

Browse files
authored
[7.6] Separate aliases used for tests in TimeSeriesLifecycleAc… (#51435)
* 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
1 parent ada0616 commit b4f2047

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
7878

7979
private String index;
8080
private String policy;
81+
private String alias;
8182

8283
@Before
8384
public void refreshIndex() {
84-
index = randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
85-
policy = randomAlphaOfLength(5);
85+
index = "index-" + randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
86+
policy = "policy-" + randomAlphaOfLength(5);
87+
alias = "alias-" + randomAlphaOfLength(5);
8688
}
8789

8890
public static void updatePolicy(String indexName, String policy) throws IOException {
@@ -100,7 +102,7 @@ public void testFullPolicy() throws Exception {
100102
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4)
101103
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
102104
.put("index.routing.allocation.include._name", "integTest-0")
103-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
105+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
104106

105107
// create policy
106108
createFullPolicy(TimeValue.ZERO);
@@ -162,7 +164,7 @@ public void testMoveToRolloverStep() throws Exception {
162164
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4)
163165
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
164166
.put("index.routing.allocation.include._name", "integTest-0")
165-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
167+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
166168

167169
createFullPolicy(TimeValue.timeValueHours(10));
168170
// update policy on index
@@ -242,7 +244,7 @@ public void testRolloverAction() throws Exception {
242244
String secondIndex = index + "-000002";
243245
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
244246
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
245-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
247+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
246248

247249
// create policy
248250
createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L));
@@ -260,7 +262,7 @@ public void testRolloverActionWithIndexingComplete() throws Exception {
260262
String secondIndex = index + "-000002";
261263
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
262264
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
263-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
265+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
264266

265267
Request updateSettingsRequest = new Request("PUT", "/" + originalIndex + "/_settings");
266268
updateSettingsRequest.setJsonEntity("{\n" +
@@ -275,7 +277,7 @@ public void testRolloverActionWithIndexingComplete() throws Exception {
275277
" {\n" +
276278
" \"add\": {\n" +
277279
" \"index\": \"" + originalIndex + "\",\n" +
278-
" \"alias\": \"alias\",\n" +
280+
" \"alias\": \"" + alias + "\",\n" +
279281
" \"is_write_index\": false\n" +
280282
" }\n" +
281283
" }\n" +
@@ -784,7 +786,7 @@ public void testRemoveAndReaddPolicy() throws Exception {
784786
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
785787
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
786788
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
787-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
789+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
788790

789791
// Index a document
790792
index(client(), originalIndex, "_id", "foo", "bar");
@@ -802,7 +804,7 @@ public void testRemoveAndReaddPolicy() throws Exception {
802804
addPolicyRequest.setJsonEntity("{\n" +
803805
" \"settings\": {\n" +
804806
" \"index.lifecycle.name\": \"" + policy + "\",\n" +
805-
" \"index.lifecycle.rollover_alias\": \"alias\"\n" +
807+
" \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
806808
" }\n" +
807809
"}");
808810
client().performRequest(addPolicyRequest);
@@ -819,7 +821,7 @@ public void testMoveToInjectedStep() throws Exception {
819821
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 3)
820822
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
821823
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
822-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
824+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));
823825

824826
assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(new StepKey("new", "complete", "complete"))));
825827

@@ -855,7 +857,7 @@ public void testMoveToStepRereadsPolicy() throws Exception {
855857
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
856858
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
857859
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
858-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"),
860+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
859861
true);
860862

861863
assertBusy(() -> assertThat(getStepKeyForIndex("test-1"), equalTo(new StepKey("hot", "rollover", "check-rollover-ready"))));
@@ -932,7 +934,7 @@ public void testExplainFilters() throws Exception {
932934
}
933935

934936
createIndexWithSettings(goodIndex, Settings.builder()
935-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias")
937+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
936938
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
937939
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
938940
);
@@ -991,7 +993,7 @@ public void testILMRolloverRetriesOnReadOnlyBlock() throws Exception {
991993
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
992994
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
993995
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
994-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias")
996+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
995997
.put("index.blocks.read_only", true),
996998
true
997999
);
@@ -1026,7 +1028,7 @@ public void testILMRolloverOnManuallyRolledIndex() throws Exception {
10261028
" \"number_of_shards\": 1,\n" +
10271029
" \"number_of_replicas\": 0,\n" +
10281030
" \"index.lifecycle.name\": \"" + policy + "\", \n" +
1029-
" \"index.lifecycle.rollover_alias\": \"alias\"\n" +
1031+
" \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
10301032
" }\n" +
10311033
"}");
10321034
client().performRequest(createIndexTemplate);
@@ -1044,7 +1046,7 @@ public void testILMRolloverOnManuallyRolledIndex() throws Exception {
10441046
client().performRequest(refreshOriginalIndex);
10451047

10461048
// Manual rollover
1047-
Request rolloverRequest = new Request("POST", "/alias/_rollover");
1049+
Request rolloverRequest = new Request("POST", "/" + alias + "/_rollover");
10481050
rolloverRequest.setJsonEntity("{\n" +
10491051
" \"conditions\": {\n" +
10501052
" \"max_docs\": \"1\"\n" +
@@ -1065,9 +1067,9 @@ public void testILMRolloverOnManuallyRolledIndex() throws Exception {
10651067
assertBusy(() -> assertTrue((boolean) explainIndex(secondIndex).getOrDefault("managed", true)));
10661068

10671069
// index some documents to trigger an ILM rollover
1068-
index(client(), "alias", "1", "foo", "bar");
1069-
index(client(), "alias", "2", "foo", "bar");
1070-
index(client(), "alias", "3", "foo", "bar");
1070+
index(client(), alias, "1", "foo", "bar");
1071+
index(client(), alias, "2", "foo", "bar");
1072+
index(client(), alias, "3", "foo", "bar");
10711073
Request refreshSecondIndex = new Request("POST", "/" + secondIndex + "/_refresh");
10721074
client().performRequest(refreshSecondIndex).getStatusLine();
10731075

@@ -1087,7 +1089,7 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except
10871089
rolledIndex,
10881090
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
10891091
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
1090-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"),
1092+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
10911093
false
10921094
);
10931095

@@ -1096,7 +1098,7 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except
10961098
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
10971099
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
10981100
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
1099-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"),
1101+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
11001102
true
11011103
);
11021104

@@ -1159,7 +1161,7 @@ public void testUpdateRolloverLifecycleDateStepRetriesWhenRolloverInfoIsMissing(
11591161
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
11601162
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
11611163
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
1162-
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"),
1164+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
11631165
true
11641166
);
11651167

@@ -1199,7 +1201,7 @@ public void testUpdateRolloverLifecycleDateStepRetriesWhenRolloverInfoIsMissing(
11991201

12001202
// manual rollover the index so the "update-rollover-lifecycle-date" ILM step can continue and finish successfully as the index
12011203
// will have rollover information now
1202-
Request rolloverRequest = new Request("POST", "/alias/_rollover");
1204+
Request rolloverRequest = new Request("POST", "/" + alias + "/_rollover");
12031205
rolloverRequest.setJsonEntity("{\n" +
12041206
" \"conditions\": {\n" +
12051207
" \"max_docs\": \"1\"\n" +
@@ -1222,7 +1224,7 @@ public void testHistoryIsWrittenWithSuccess() throws Exception {
12221224
" \"number_of_shards\": 1,\n" +
12231225
" \"number_of_replicas\": 0,\n" +
12241226
" \"index.lifecycle.name\": \"" + policy+ "\",\n" +
1225-
" \"index.lifecycle.rollover_alias\": \"alias\"\n" +
1227+
" \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
12261228
" }\n" +
12271229
"}");
12281230
client().performRequest(createIndexTemplate);
@@ -1375,7 +1377,7 @@ public void testRefreshablePhaseJson() throws Exception {
13751377
" \"number_of_shards\": 1,\n" +
13761378
" \"number_of_replicas\": 0,\n" +
13771379
" \"index.lifecycle.name\": \"" + policy+ "\",\n" +
1378-
" \"index.lifecycle.rollover_alias\": \"alias\"\n" +
1380+
" \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
13791381
" }\n" +
13801382
"}");
13811383
client().performRequest(createIndexTemplate);
@@ -1557,7 +1559,7 @@ private void createIndexWithSettings(String index, Settings.Builder settings, bo
15571559
writeIndexSnippet = "\"is_write_index\": true";
15581560
}
15591561
request.setJsonEntity("{\n \"settings\": " + Strings.toString(settings.build())
1560-
+ ", \"aliases\" : { \"alias\": { " + writeIndexSnippet + " } } }");
1562+
+ ", \"aliases\" : { \"" + alias + "\": { " + writeIndexSnippet + " } } }");
15611563
client().performRequest(request);
15621564
// wait for the shards to initialize
15631565
ensureGreen(index);

x-pack/plugin/ilm/qa/rest/src/test/resources/rest-api-spec/test/ilm/20_move_to_step.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ teardown:
102102
action: "forcemerge"
103103
name: "forcemerge"
104104
- match: { error.root_cause.0.type: "illegal_argument_exception" }
105-
- match: { error.root_cause.0.reason: "index [my_index] is not on current step [{\"phase\":\"warm\",\"action\":\"forcemerge\",\"name\":\"forcemerge\"}]" }
105+
- 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\"}]" }
106106

107107

108108
- do:

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ public static void validateTransition(IndexMetaData idxMeta, Step.StepKey curren
7272
}
7373

7474
LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMeta);
75-
if (currentStepKey != null && currentStepKey.equals(LifecycleExecutionState.getCurrentStepKey(lifecycleState)) == false) {
76-
throw new IllegalArgumentException("index [" + indexName + "] is not on current step [" + currentStepKey + "]");
75+
Step.StepKey realKey = LifecycleExecutionState.getCurrentStepKey(lifecycleState);
76+
if (currentStepKey != null && currentStepKey.equals(realKey) == false) {
77+
throw new IllegalArgumentException("index [" + indexName + "] is not on current step [" + currentStepKey +
78+
"], currently: [" + realKey + "]");
7779
}
7880

7981
if (stepRegistry.stepExists(indexPolicySetting, newStepKey) == false) {

0 commit comments

Comments
 (0)