Skip to content

Commit e64e543

Browse files
authored
[ML] Making indices/aliases hidden takes a while after cluster startup (#93148) (#93149)
When a cluster is upgraded from a version that didn't have hidden indices/aliases to one that does, we make the relevant ML indices and aliases hidden. However, the steps to do this are split over 5 actions that run sequentially, so the work might take a second or two after the upgraded cluster starts up. This can cause the test that asserts on the final state to fail if it runs very quickly after the upgraded cluster startup. The solution is to retry the test for a few seconds to give a chance for all the upgrade actions to complete. Relates #93062
1 parent 7cf7e1a commit e64e543

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/MlHiddenIndicesFullClusterRestartIT.java

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,34 +102,41 @@ public void testMlIndicesBecomeHidden() throws Exception {
102102
}
103103
}
104104
} else {
105-
Map<String, Object> indexSettingsMap = contentAsMap(getMlIndicesSettings());
106-
Map<String, Object> aliasesMap = contentAsMap(getMlAliases());
107-
108-
assertThat("Index settings map was: " + indexSettingsMap, indexSettingsMap, is(aMapWithSize(greaterThanOrEqualTo(4))));
109-
for (Map.Entry<String, Object> e : indexSettingsMap.entrySet()) {
110-
String indexName = e.getKey();
111-
@SuppressWarnings("unchecked")
112-
Map<String, Object> settings = (Map<String, Object>) e.getValue();
113-
assertThat(settings, is(notNullValue()));
114-
assertThat(
115-
"Index " + indexName + " expected to be hidden but wasn't, settings = " + settings,
116-
XContentMapValues.extractValue(settings, "settings", "index", "hidden"),
117-
is(equalTo("true"))
118-
);
119-
}
105+
// The 5 operations in MlInitializationService.makeMlInternalIndicesHidden() run sequentially, so might
106+
// not all be finished when this test runs. The desired state should exist within a few seconds of startup,
107+
// hence the assertBusy().
108+
assertBusy(() -> {
109+
Map<String, Object> indexSettingsMap = contentAsMap(getMlIndicesSettings());
110+
Map<String, Object> aliasesMap = contentAsMap(getMlAliases());
120111

121-
for (Tuple<List<String>, String> indexAndAlias : EXPECTED_INDEX_ALIAS_PAIRS) {
122-
List<String> indices = indexAndAlias.v1();
123-
String alias = indexAndAlias.v2();
124-
assertThat(
125-
indexAndAlias + " expected to be hidden but wasn't, aliasesMap = " + aliasesMap,
126-
indices.stream()
127-
.anyMatch(
128-
index -> Boolean.TRUE.equals(XContentMapValues.extractValue(aliasesMap, index, "aliases", alias, "is_hidden"))
129-
),
130-
is(true)
131-
);
132-
}
112+
assertThat("Index settings map was: " + indexSettingsMap, indexSettingsMap, is(aMapWithSize(greaterThanOrEqualTo(4))));
113+
for (Map.Entry<String, Object> e : indexSettingsMap.entrySet()) {
114+
String indexName = e.getKey();
115+
@SuppressWarnings("unchecked")
116+
Map<String, Object> settings = (Map<String, Object>) e.getValue();
117+
assertThat(settings, is(notNullValue()));
118+
assertThat(
119+
"Index " + indexName + " expected to be hidden but wasn't, settings = " + settings,
120+
XContentMapValues.extractValue(settings, "settings", "index", "hidden"),
121+
is(equalTo("true"))
122+
);
123+
}
124+
125+
for (Tuple<List<String>, String> indexAndAlias : EXPECTED_INDEX_ALIAS_PAIRS) {
126+
List<String> indices = indexAndAlias.v1();
127+
String alias = indexAndAlias.v2();
128+
assertThat(
129+
indexAndAlias + " expected to be hidden but wasn't, aliasesMap = " + aliasesMap,
130+
indices.stream()
131+
.anyMatch(
132+
index -> Boolean.TRUE.equals(
133+
XContentMapValues.extractValue(aliasesMap, index, "aliases", alias, "is_hidden")
134+
)
135+
),
136+
is(true)
137+
);
138+
}
139+
});
133140
}
134141
}
135142

0 commit comments

Comments
 (0)