Browse Source

[8.19] Fix MixedClusterEsqlSpecIT 8.11 BWC (#129841)

Aurélien FOUCRET 3 months ago
parent
commit
79f81408c4

+ 5 - 7
x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java

@@ -163,7 +163,6 @@ public abstract class EsqlSpecTestCase extends ESRestTestCase {
         }
 
         deleteInferenceEndpoints(adminClient());
-
     }
 
     public boolean logResults() {
@@ -295,13 +294,12 @@ public abstract class EsqlSpecTestCase extends ESRestTestCase {
      * not to emit duplicate warnings but for now it isn't worth fighting with. So! In
      * those environments we override this to deduplicate.
      * <p>
-     *     Note: This only applies to warnings declared as {@code warning:}. Those
-     *     declared as {@code warningRegex:} are always a list of
-     *     <strong>allowed</strong> warnings. {@code warningRegex:} matches 0 or more
-     *     warnings. There is no need to deduplicate because there's no expectation
-     *     of an exact match.
+     * Note: This only applies to warnings declared as {@code warning:}. Those
+     * declared as {@code warningRegex:} are always a list of
+     * <strong>allowed</strong> warnings. {@code warningRegex:} matches 0 or more
+     * warnings. There is no need to deduplicate because there's no expectation
+     * of an exact match.
      * </p>
-     *
      */
     protected boolean deduplicateExactWarnings() {
         return false;

+ 20 - 5
x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestsDataLoader.java

@@ -342,7 +342,22 @@ public class CsvTestsDataLoader {
         }
     }
 
+    @SuppressWarnings("unchecked")
     public static void deleteInferenceEndpoints(RestClient client) throws IOException {
+        Response response = client.performRequest(new Request("GET", "_inference/_all"));
+
+        try (InputStream content = response.getEntity().getContent()) {
+            XContentType xContentType = XContentType.fromMediaType(response.getEntity().getContentType().getValue());
+            Map<String, ?> responseMap = XContentHelper.convertToMap(xContentType.xContent(), content, false);
+            List<Map<String, ?>> endpoints = (List<Map<String, ?>>) responseMap.get("endpoints");
+            for (Map<String, ?> endpoint : endpoints) {
+                String inferenceId = (String) endpoint.get("inference_id");
+                String taskType = (String) endpoint.get("task_type");
+                if (inferenceId != null && taskType != null && inferenceId.startsWith(".") == false) {
+                    deleteInferenceEndpoint(client, inferenceId, TaskType.fromString(taskType));
+                }
+            }
+        }
         deleteSparseEmbeddingInferenceEndpoint(client);
         deleteRerankInferenceEndpoint(client);
         deleteCompletionInferenceEndpoint(client);
@@ -360,7 +375,7 @@ public class CsvTestsDataLoader {
     }
 
     public static void deleteSparseEmbeddingInferenceEndpoint(RestClient client) throws IOException {
-        deleteInferenceEndpoint(client, "test_sparse_inference");
+        deleteInferenceEndpoint(client, "test_sparse_inference", TaskType.SPARSE_EMBEDDING);
     }
 
     public static boolean clusterHasSparseEmbeddingInferenceEndpoint(RestClient client) throws IOException {
@@ -378,7 +393,7 @@ public class CsvTestsDataLoader {
     }
 
     public static void deleteRerankInferenceEndpoint(RestClient client) throws IOException {
-        deleteInferenceEndpoint(client, "test_reranker");
+        deleteInferenceEndpoint(client, "test_reranker", TaskType.RERANK);
     }
 
     public static boolean clusterHasRerankInferenceEndpoint(RestClient client) throws IOException {
@@ -396,7 +411,7 @@ public class CsvTestsDataLoader {
     }
 
     public static void deleteCompletionInferenceEndpoint(RestClient client) throws IOException {
-        deleteInferenceEndpoint(client, "test_completion");
+        deleteInferenceEndpoint(client, "test_completion", TaskType.COMPLETION);
     }
 
     public static boolean clusterHasCompletionInferenceEndpoint(RestClient client) throws IOException {
@@ -423,9 +438,9 @@ public class CsvTestsDataLoader {
         return true;
     }
 
-    private static void deleteInferenceEndpoint(RestClient client, String inferenceId) throws IOException {
+    private static void deleteInferenceEndpoint(RestClient client, String inferenceId, TaskType taskType) throws IOException {
         try {
-            client.performRequest(new Request("DELETE", "_inference/" + inferenceId));
+            client.performRequest(new Request("DELETE", "_inference/" + taskType + "/" + inferenceId));
         } catch (ResponseException e) {
             // 404 here means the endpoint was not created
             if (e.getResponse().getStatusLine().getStatusCode() != 404) {

+ 3 - 1
x-pack/plugin/esql/qa/testFixtures/src/main/resources/mapping-colors.json

@@ -13,7 +13,9 @@
       "type": "dense_vector",
       "similarity": "l2_norm",
       "index_options": {
-        "type": "hnsw"
+        "type": "hnsw",
+        "m": 16,
+        "ef_construction": 100
       }
     }
   }