Handle 404s from the _cat/indices api in FullClusterRestartIT (#122537)

This commit is contained in:
Joe Gallo 2025-02-13 21:14:04 -05:00 committed by GitHub
parent 5d48ded537
commit 5c00341c2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 17 deletions

View file

@ -20,6 +20,7 @@ import org.elasticsearch.client.WarningsHandler;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.Nullable; import org.elasticsearch.core.Nullable;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.FeatureFlag; import org.elasticsearch.test.cluster.FeatureFlag;
import org.elasticsearch.test.cluster.local.distribution.DistributionType; import org.elasticsearch.test.cluster.local.distribution.DistributionType;
@ -170,7 +171,7 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void testDatabasesLoaded() throws IOException { private void testDatabasesLoaded() throws IOException {
Request getTaskState = new Request("GET", "/_cluster/state"); Request getTaskState = new Request("GET", "/_cluster/state");
ObjectPath state = ObjectPath.createFromResponse(client().performRequest(getTaskState)); ObjectPath state = ObjectPath.createFromResponse(assertOK(client().performRequest(getTaskState)));
List<?> tasks = state.evaluate("metadata.persistent_tasks.tasks"); List<?> tasks = state.evaluate("metadata.persistent_tasks.tasks");
// Short-circuit to avoid using steams if the list is empty // Short-circuit to avoid using steams if the list is empty
@ -196,7 +197,10 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
private void testCatIndices(List<String> indexNames, @Nullable List<String> additionalIndexNames) throws IOException { private void testCatIndices(List<String> indexNames, @Nullable List<String> additionalIndexNames) throws IOException {
Request catIndices = new Request("GET", "_cat/indices/*?s=index&h=index&expand_wildcards=all"); Request catIndices = new Request("GET", "_cat/indices/*?s=index&h=index&expand_wildcards=all");
String response = EntityUtils.toString(client().performRequest(catIndices).getEntity()); // the cat APIs can sometimes 404, erroneously
// see https://github.com/elastic/elasticsearch/issues/104371
setIgnoredErrorResponseCodes(catIndices, RestStatus.NOT_FOUND);
String response = EntityUtils.toString(assertOK(client().performRequest(catIndices)).getEntity());
List<String> indices = List.of(response.trim().split("\\s+")); List<String> indices = List.of(response.trim().split("\\s+"));
if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) { if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) {
@ -215,7 +219,7 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
assertOK(client().performRequest(putDoc)); assertOK(client().performRequest(putDoc));
Request getDoc = new Request("GET", "/my-index-00001/_doc/my_id"); Request getDoc = new Request("GET", "/my-index-00001/_doc/my_id");
ObjectPath doc = ObjectPath.createFromResponse(client().performRequest(getDoc)); ObjectPath doc = ObjectPath.createFromResponse(assertOK(client().performRequest(getDoc)));
assertNull(doc.evaluate("_source.tags")); assertNull(doc.evaluate("_source.tags"));
assertEquals("Sweden", doc.evaluate("_source.geo.country_name")); assertEquals("Sweden", doc.evaluate("_source.geo.country_name"));
} }
@ -225,8 +229,7 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
getStar.setOptions( getStar.setOptions(
RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE) // we don't care about warnings, just errors RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE) // we don't care about warnings, just errors
); );
Response response = client().performRequest(getStar); Response response = assertOK(client().performRequest(getStar));
assertOK(response);
if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) { if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) {
indexNames = new ArrayList<>(indexNames); // recopy into a mutable list indexNames = new ArrayList<>(indexNames); // recopy into a mutable list
@ -244,8 +247,7 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
.addHeader("X-elastic-product-origin", "kibana") .addHeader("X-elastic-product-origin", "kibana")
.setWarningsHandler(WarningsHandler.PERMISSIVE) // we don't care about warnings, just errors .setWarningsHandler(WarningsHandler.PERMISSIVE) // we don't care about warnings, just errors
); );
Response response = client().performRequest(getStar); Response response = assertOK(client().performRequest(getStar));
assertOK(response);
if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) { if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) {
indexNames = new ArrayList<>(indexNames); // recopy into a mutable list indexNames = new ArrayList<>(indexNames); // recopy into a mutable list

View file

@ -323,9 +323,6 @@ tests:
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests - class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testSuggestProfileWithData method: testSuggestProfileWithData
issue: https://github.com/elastic/elasticsearch/issues/121258 issue: https://github.com/elastic/elasticsearch/issues/121258
- class: org.elasticsearch.ingest.geoip.FullClusterRestartIT
method: testGeoIpSystemFeaturesMigration {cluster=UPGRADED}
issue: https://github.com/elastic/elasticsearch/issues/121115
- class: org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT - class: org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT
method: test {yaml=reference/cat/health/cat-health-no-timestamp-example} method: test {yaml=reference/cat/health/cat-health-no-timestamp-example}
issue: https://github.com/elastic/elasticsearch/issues/121867 issue: https://github.com/elastic/elasticsearch/issues/121867

View file

@ -31,6 +31,7 @@ import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions; import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction; import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction;
import org.elasticsearch.search.SearchFeatures; import org.elasticsearch.search.SearchFeatures;
import org.elasticsearch.test.NotEqualMessageBuilder; import org.elasticsearch.test.NotEqualMessageBuilder;
@ -628,13 +629,14 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
) )
); );
// assertBusy to work around https://github.com/elastic/elasticsearch/issues/104371 assertBusy(() -> {
assertBusy( Request catIndices = new Request("GET", "/_cat/indices?v&error_trace");
() -> assertThat( // the cat APIs can sometimes 404, erroneously
EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices?v&error_trace")).getEntity()), // see https://github.com/elastic/elasticsearch/issues/104371
containsString("testrollover-000002") setIgnoredErrorResponseCodes(catIndices, RestStatus.NOT_FOUND);
) Response response = assertOK(client().performRequest(catIndices));
); assertThat(EntityUtils.toString(response.getEntity()), containsString("testrollover-000002"));
});
} }
Request countRequest = new Request("POST", "/" + index + "-*/_search"); Request countRequest = new Request("POST", "/" + index + "-*/_search");