Browse Source

[CI] DocsClientYamlTestSuiteIT test {yaml=reference/watcher/example-watches/example-watch-clusterstatus/line_137} failing - (#115809) (#117354) (#117972)

* Ignore system index access errors in YAML test index cleanup method

* Remove test mute

* Swap the logic back as it was right the first time

* Resolve conflict with latest merge

* Move warning handler into it's own method to reduce nesting

(cherry picked from commit cda2fe68a3a549e2443ca7137b4df431af6f2ba7)
Luke Whiting 10 months ago
parent
commit
9abeeeaf12

+ 19 - 21
test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

@@ -26,6 +26,8 @@ import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
 import org.apache.http.ssl.SSLContextBuilder;
 import org.apache.http.ssl.SSLContexts;
 import org.apache.http.util.EntityUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.elasticsearch.Build;
 import org.elasticsearch.TransportVersion;
 import org.elasticsearch.TransportVersions;
@@ -158,6 +160,8 @@ public abstract class ESRestTestCase extends ESTestCase {
 
     private static final Pattern SEMANTIC_VERSION_PATTERN = Pattern.compile("^(\\d+\\.\\d+\\.\\d+)\\D?.*");
 
+    private static final Logger SUITE_LOGGER = LogManager.getLogger(ESRestTestCase.class);
+
     /**
      * Convert the entity from a {@link Response} into a map of maps.
      * Consumes the underlying HttpEntity, releasing any resources it may be holding.
@@ -1171,7 +1175,13 @@ public abstract class ESRestTestCase extends ESTestCase {
             }
             final Request deleteRequest = new Request("DELETE", Strings.collectionToCommaDelimitedString(indexPatterns));
             deleteRequest.addParameter("expand_wildcards", "open,closed" + (includeHidden ? ",hidden" : ""));
-            deleteRequest.setOptions(deleteRequest.getOptions().toBuilder().setWarningsHandler(ignoreAsyncSearchWarning()).build());
+
+            // If system index warning, ignore but log
+            // See: https://github.com/elastic/elasticsearch/issues/117099
+            // and: https://github.com/elastic/elasticsearch/issues/115809
+            deleteRequest.setOptions(
+                RequestOptions.DEFAULT.toBuilder().setWarningsHandler(ESRestTestCase::ignoreSystemIndexAccessWarnings)
+            );
             final Response response = adminClient().performRequest(deleteRequest);
             try (InputStream is = response.getEntity().getContent()) {
                 assertTrue((boolean) XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true).get("acknowledged"));
@@ -1184,28 +1194,16 @@ public abstract class ESRestTestCase extends ESTestCase {
         }
     }
 
-    // Make warnings handler that ignores the .async-search warning since .async-search may randomly appear when async requests are slow
-    // See: https://github.com/elastic/elasticsearch/issues/117099
-    protected static WarningsHandler ignoreAsyncSearchWarning() {
-        return new WarningsHandler() {
-            @Override
-            public boolean warningsShouldFailRequest(List<String> warnings) {
-                if (warnings.isEmpty()) {
-                    return false;
-                }
-                return warnings.equals(
-                    List.of(
-                        "this request accesses system indices: [.async-search], "
-                            + "but in a future major version, direct access to system indices will be prevented by default"
-                    )
-                ) == false;
+    private static boolean ignoreSystemIndexAccessWarnings(List<String> warnings) {
+        for (String warning : warnings) {
+            if (warning.startsWith("this request accesses system indices:")) {
+                SUITE_LOGGER.warn("Ignoring system index access warning during test cleanup: {}", warning);
+            } else {
+                return true;
             }
+        }
 
-            @Override
-            public String toString() {
-                return "ignore .async-search warning";
-            }
-        };
+        return false;
     }
 
     protected static void wipeDataStreams() throws IOException {