From df3979823dcc13bd9d436ede9301e6d17b9cc8dd Mon Sep 17 00:00:00 2001 From: Max Hniebergall <137079448+maxhniebergall@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:43:04 -0500 Subject: [PATCH] [Inference API] Fix model field in OpenAI Upgrade IT (#119362) (#119371) * Fix NPE by getting request once and defaulting to empty list * Fix error in OpenAIUpgrade test which used the wrong field name for certain versions * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine --- .../xpack/application/OpenAiServiceUpgradeIT.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/inference/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/xpack/application/OpenAiServiceUpgradeIT.java b/x-pack/plugin/inference/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/xpack/application/OpenAiServiceUpgradeIT.java index 7b43a5b86e619..b6dcfcb84a77f 100644 --- a/x-pack/plugin/inference/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/xpack/application/OpenAiServiceUpgradeIT.java +++ b/x-pack/plugin/inference/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/xpack/application/OpenAiServiceUpgradeIT.java @@ -16,6 +16,8 @@ import org.junit.BeforeClass; import java.io.IOException; +import java.util.Collection; +import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -83,8 +85,9 @@ public void testOpenAiEmbeddings() throws IOException { assertEquals("openai", configs.get(0).get("service")); var serviceSettings = (Map) configs.get(0).get("service_settings"); var taskSettings = (Map) configs.get(0).get("task_settings"); - var modelIdFound = serviceSettings.containsKey("model_id") || taskSettings.containsKey("model_id"); - assertTrue("model_id not found in config: " + configs.toString(), modelIdFound); + var modelIdFound = serviceSettings.containsKey("model_id") + || (taskSettings.containsKey("model") && getOldClusterTestVersion().onOrBefore(OPEN_AI_EMBEDDINGS_MODEL_SETTING_MOVED)); + assertTrue("model_id not found in config: " + configs, modelIdFound); assertEmbeddingInference(oldClusterId); } else if (isUpgradedCluster()) { @@ -139,9 +142,11 @@ public void testOpenAiCompletions() throws IOException { assertCompletionInference(oldClusterId); } else if (isMixedCluster()) { - var configs = (List>) get(testTaskType, oldClusterId).get("endpoints"); + List> configs = new LinkedList<>(); + var request = get(testTaskType, oldClusterId); + configs.addAll((Collection>) request.getOrDefault("endpoints", List.of())); if (oldClusterHasFeature("gte_v" + MODELS_RENAMED_TO_ENDPOINTS) == false) { - configs.addAll((List>) get(testTaskType, oldClusterId).get(old_cluster_endpoint_identifier)); + configs.addAll((List>) request.getOrDefault(old_cluster_endpoint_identifier, List.of())); // in version 8.15, there was a breaking change where "models" was renamed to "endpoints" } assertEquals("openai", configs.get(0).get("service"));