Explorar o código

[ML] Add logging for failing PyTorch test (#81044)

For #80819
David Kyle %!s(int64=3) %!d(string=hai) anos
pai
achega
1abbf4b387

+ 7 - 5
x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/PyTorchModelIT.java

@@ -241,20 +241,22 @@ public class PyTorchModelIT extends ESRestTestCase {
         CheckedBiConsumer<String, AllocationStatus.State, IOException> assertAtLeast = (modelId, state) -> {
             startDeployment(modelId, state.toString());
             Response response = getTrainedModelStats(modelId);
-            List<Map<String, Object>> stats = (List<Map<String, Object>>) entityAsMap(response).get("trained_model_stats");
+            var responseMap = entityAsMap(response);
+            List<Map<String, Object>> stats = (List<Map<String, Object>>) responseMap.get("trained_model_stats");
             assertThat(stats, hasSize(1));
             String statusState = (String) XContentMapValues.extractValue("deployment_stats.allocation_status.state", stats.get(0));
-            assertThat(stats.toString(), statusState, is(not(nullValue())));
+            assertThat(responseMap.toString(), statusState, is(not(nullValue())));
             assertThat(AllocationStatus.State.fromString(statusState), greaterThanOrEqualTo(state));
             Integer byteSize = (Integer) XContentMapValues.extractValue("deployment_stats.model_size_bytes", stats.get(0));
-            assertThat(byteSize, is(not(nullValue())));
+            assertThat(responseMap.toString(), byteSize, is(not(nullValue())));
             assertThat(byteSize, equalTo((int) RAW_MODEL_SIZE));
 
             Response humanResponse = client().performRequest(new Request("GET", "/_ml/trained_models/" + modelId + "/_stats?human"));
-            stats = (List<Map<String, Object>>) entityAsMap(humanResponse).get("trained_model_stats");
+            var humanResponseMap = entityAsMap(humanResponse);
+            stats = (List<Map<String, Object>>) humanResponseMap.get("trained_model_stats");
             assertThat(stats, hasSize(1));
             String stringBytes = (String) XContentMapValues.extractValue("deployment_stats.model_size", stats.get(0));
-            assertThat(stringBytes, is(not(nullValue())));
+            assertThat("stats response: " + responseMap + " human stats response" + humanResponseMap, stringBytes, is(not(nullValue())));
             assertThat(stringBytes, equalTo("1.5kb"));
             stopDeployment(model);
         };

+ 7 - 5
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetDeploymentStatsAction.java

@@ -7,6 +7,8 @@
 
 package org.elasticsearch.xpack.ml.action;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.elasticsearch.action.ActionListener;
 import org.elasticsearch.action.FailedNodeException;
 import org.elasticsearch.action.TaskOperationFailure;
@@ -54,6 +56,8 @@ public class TransportGetDeploymentStatsAction extends TransportTasksAction<
     GetDeploymentStatsAction.Response,
     AllocationStats> {
 
+    private static final Logger logger = LogManager.getLogger(TransportGetDeploymentStatsAction.class);
+
     @Inject
     public TransportGetDeploymentStatsAction(
         TransportService transportService,
@@ -129,9 +133,6 @@ public class TransportGetDeploymentStatsAction extends TransportTasksAction<
             }
         }
 
-        // check request has been satisfied
-        ExpandedIdsMatcher requiredIdsMatcher = new ExpandedIdsMatcher(tokenizedRequestIds, true);
-        requiredIdsMatcher.filterMatchedIds(matchedDeploymentIds);
         if (matchedDeploymentIds.isEmpty()) {
             listener.onResponse(
                 new GetDeploymentStatsAction.Response(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), 0L)
@@ -154,8 +155,7 @@ public class TransportGetDeploymentStatsAction extends TransportTasksAction<
                 .collect(Collectors.toList());
             // Set the allocation state and reason if we have it
             for (AllocationStats stats : updatedResponse.getStats().results()) {
-                Optional<TrainedModelAllocation> modelAllocation = Optional.ofNullable(allocation.getModelAllocation(stats.getModelId()));
-                TrainedModelAllocation trainedModelAllocation = modelAllocation.orElse(null);
+                TrainedModelAllocation trainedModelAllocation = allocation.getModelAllocation(stats.getModelId());
                 if (trainedModelAllocation != null) {
                     stats.setState(trainedModelAllocation.getAllocationState()).setReason(trainedModelAllocation.getReason().orElse(null));
                     if (trainedModelAllocation.getAllocationState().isAnyOf(AllocationState.STARTED, AllocationState.STARTING)) {
@@ -274,6 +274,8 @@ public class TransportGetDeploymentStatsAction extends TransportTasksAction<
 
                 nodeStats.sort(Comparator.comparing(n -> n.getNode().getId()));
 
+                // debug logging added for https://github.com/elastic/elasticsearch/issues/80819
+                logger.debug("[{}] deployment stats for non-started deployment", modelId);
                 updatedAllocationStats.add(new AllocationStats(modelId, null, null, null, null, allocation.getStartTime(), nodeStats));
             }
         }