Skip to content

Commit ed36694

Browse files
authored
Handle 404s from the _cat/indices api in FullClusterRestartIT (#122537) (#122564)
1 parent 76bcb98 commit ed36694

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

modules/ingest-geoip/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/ingest/geoip/FullClusterRestartIT.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.elasticsearch.common.settings.Settings;
2121
import org.elasticsearch.common.util.concurrent.ThreadContext;
2222
import org.elasticsearch.core.Nullable;
23+
import org.elasticsearch.rest.RestStatus;
2324
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2425
import org.elasticsearch.test.cluster.FeatureFlag;
2526
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
@@ -168,7 +169,7 @@ public void testGeoIpSystemFeaturesMigration() throws Exception {
168169
@SuppressWarnings("unchecked")
169170
private void testDatabasesLoaded() throws IOException {
170171
Request getTaskState = new Request("GET", "/_cluster/state");
171-
ObjectPath state = ObjectPath.createFromResponse(client().performRequest(getTaskState));
172+
ObjectPath state = ObjectPath.createFromResponse(assertOK(client().performRequest(getTaskState)));
172173

173174
List<?> tasks = state.evaluate("metadata.persistent_tasks.tasks");
174175
// Short-circuit to avoid using steams if the list is empty
@@ -194,7 +195,10 @@ private void testDatabasesLoaded() throws IOException {
194195

195196
private void testCatIndices(List<String> indexNames, @Nullable List<String> additionalIndexNames) throws IOException {
196197
Request catIndices = new Request("GET", "_cat/indices/*?s=index&h=index&expand_wildcards=all");
197-
String response = EntityUtils.toString(client().performRequest(catIndices).getEntity());
198+
// the cat APIs can sometimes 404, erroneously
199+
// see https://github.com/elastic/elasticsearch/issues/104371
200+
setIgnoredErrorResponseCodes(catIndices, RestStatus.NOT_FOUND);
201+
String response = EntityUtils.toString(assertOK(client().performRequest(catIndices)).getEntity());
198202
List<String> indices = List.of(response.trim().split("\\s+"));
199203

200204
if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) {
@@ -213,7 +217,7 @@ private void testIndexGeoDoc() throws IOException {
213217
assertOK(client().performRequest(putDoc));
214218

215219
Request getDoc = new Request("GET", "/my-index-00001/_doc/my_id");
216-
ObjectPath doc = ObjectPath.createFromResponse(client().performRequest(getDoc));
220+
ObjectPath doc = ObjectPath.createFromResponse(assertOK(client().performRequest(getDoc)));
217221
assertNull(doc.evaluate("_source.tags"));
218222
assertEquals("Sweden", doc.evaluate("_source.geo.country_name"));
219223
}
@@ -223,8 +227,7 @@ private void testGetStar(List<String> indexNames, @Nullable List<String> additio
223227
getStar.setOptions(
224228
RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE) // we don't care about warnings, just errors
225229
);
226-
Response response = client().performRequest(getStar);
227-
assertOK(response);
230+
Response response = assertOK(client().performRequest(getStar));
228231

229232
if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) {
230233
indexNames = new ArrayList<>(indexNames); // recopy into a mutable list
@@ -242,8 +245,7 @@ private void testGetStarAsKibana(List<String> indexNames, @Nullable List<String>
242245
.addHeader("X-elastic-product-origin", "kibana")
243246
.setWarningsHandler(WarningsHandler.PERMISSIVE) // we don't care about warnings, just errors
244247
);
245-
Response response = client().performRequest(getStar);
246-
assertOK(response);
248+
Response response = assertOK(client().performRequest(getStar));
247249

248250
if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) {
249251
indexNames = new ArrayList<>(indexNames); // recopy into a mutable list

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,6 @@ tests:
459459
- class: org.elasticsearch.xpack.transform.integration.TransformAuditorIT
460460
method: testAuditorWritesAudits
461461
issue: https://github.com/elastic/elasticsearch/issues/121241
462-
- class: org.elasticsearch.ingest.geoip.FullClusterRestartIT
463-
method: testGeoIpSystemFeaturesMigration {cluster=UPGRADED}
464-
issue: https://github.com/elastic/elasticsearch/issues/121115
465462
- class: org.elasticsearch.xpack.security.authc.jwt.JwtRealmSingleNodeTests
466463
method: testGrantApiKeyForJWT
467464
issue: https://github.com/elastic/elasticsearch/issues/121039

qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.index.IndexVersion;
3434
import org.elasticsearch.index.IndexVersions;
3535
import org.elasticsearch.index.mapper.DateFieldMapper;
36+
import org.elasticsearch.rest.RestStatus;
3637
import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction;
3738
import org.elasticsearch.test.NotEqualMessageBuilder;
3839
import org.elasticsearch.test.XContentTestUtils;
@@ -633,13 +634,14 @@ public void testRollover() throws Exception {
633634
)
634635
);
635636

636-
// assertBusy to work around https://github.com/elastic/elasticsearch/issues/104371
637-
assertBusy(
638-
() -> assertThat(
639-
EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices?v&error_trace")).getEntity()),
640-
containsString("testrollover-000002")
641-
)
642-
);
637+
assertBusy(() -> {
638+
Request catIndices = new Request("GET", "/_cat/indices?v&error_trace");
639+
// the cat APIs can sometimes 404, erroneously
640+
// see https://github.com/elastic/elasticsearch/issues/104371
641+
setIgnoredErrorResponseCodes(catIndices, RestStatus.NOT_FOUND);
642+
Response response = assertOK(client().performRequest(catIndices));
643+
assertThat(EntityUtils.toString(response.getEntity()), containsString("testrollover-000002"));
644+
});
643645
}
644646

645647
Request countRequest = new Request("POST", "/" + index + "-*/_search");

0 commit comments

Comments
 (0)