Browse Source

[ML] this adds support for the `human` flag for byte size values in the deployment stats API (#79569)

We should allow the raw bytes and the human readable size given the
`human` flag.
Benjamin Trent 4 years ago
parent
commit
7c0dbe6e09

+ 1 - 1
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDeploymentStatsAction.java

@@ -312,7 +312,7 @@ public class GetDeploymentStatsAction extends ActionType<GetDeploymentStatsActio
                 builder.startObject();
                 builder.field("model_id", modelId);
                 if (modelSize != null) {
-                    builder.field("model_size", modelSize);
+                    builder.humanReadableField("model_size_bytes", "model_size", modelSize);
                 }
                 if (inferenceThreads != null) {
                     builder.field(StartTrainedModelDeploymentAction.TaskParams.INFERENCE_THREADS.getPreferredName(), inferenceThreads);

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

@@ -42,6 +42,7 @@ import java.util.stream.Collectors;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.empty;
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.is;
@@ -234,6 +235,17 @@ public class PyTorchModelIT extends ESRestTestCase {
             String statusState = (String)XContentMapValues.extractValue("allocation_status.state", stats.get(0));
             assertThat(stats.toString(), statusState, is(not(nullValue())));
             assertThat(AllocationStatus.State.fromString(statusState), greaterThanOrEqualTo(state));
+            Integer byteSize = (Integer)XContentMapValues.extractValue("model_size_bytes", stats.get(0));
+            assertThat(byteSize, is(not(nullValue())));
+            assertThat(byteSize, equalTo((int)RAW_MODEL_SIZE));
+
+            Response humanResponse = client()
+                .performRequest(new Request("GET", "/_ml/trained_models/" + modelId + "/deployment/_stats?human"));
+            stats = (List<Map<String, Object>>)entityAsMap(humanResponse).get("deployment_stats");
+            assertThat(stats, hasSize(1));
+            String stringBytes = (String)XContentMapValues.extractValue("model_size", stats.get(0));
+            assertThat(stringBytes, is(not(nullValue())));
+            assertThat(stringBytes, equalTo("1.5kb"));
             stopDeployment(model);
         };
 
@@ -242,7 +254,6 @@ public class PyTorchModelIT extends ESRestTestCase {
         assertAtLeast.accept(modelStarted, AllocationStatus.State.FULLY_ALLOCATED);
     }
 
-    @AwaitsFix(bugUrl = "https://github.com/elastic/ml-cpp/pull/1961")
     @SuppressWarnings("unchecked")
     public void testLiveDeploymentStats() throws IOException {
         String modelA = "model_a";
@@ -257,7 +268,7 @@ public class PyTorchModelIT extends ESRestTestCase {
         List<Map<String, Object>> stats = (List<Map<String, Object>>)entityAsMap(response).get("deployment_stats");
         assertThat(stats, hasSize(1));
         assertThat(stats.get(0).get("model_id"), equalTo(modelA));
-        assertThat(stats.get(0).get("model_size"), equalTo("1.5kb"));
+        assertThat(stats.get(0).get("model_size_bytes"), equalTo((int)RAW_MODEL_SIZE));
         List<Map<String, Object>> nodes = (List<Map<String, Object>>)stats.get(0).get("nodes");
         // 2 of the 3 nodes in the cluster are ML nodes
         assertThat(nodes, hasSize(2));