|
@@ -10,9 +10,11 @@ import org.elasticsearch.action.ActionListener;
|
|
|
import org.elasticsearch.action.support.ActionFilters;
|
|
|
import org.elasticsearch.action.support.PlainActionFuture;
|
|
|
import org.elasticsearch.client.internal.Client;
|
|
|
+import org.elasticsearch.cluster.ClusterName;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|
|
import org.elasticsearch.cluster.metadata.Metadata;
|
|
|
+import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|
@@ -46,6 +48,7 @@ import org.elasticsearch.xpack.core.ml.action.GetDatafeedsStatsAction;
|
|
|
import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction;
|
|
|
import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction;
|
|
|
import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsStatsAction;
|
|
|
+import org.elasticsearch.xpack.core.ml.action.MlMemoryAction;
|
|
|
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
|
|
|
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedState;
|
|
|
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsConfig;
|
|
@@ -134,6 +137,27 @@ public class MachineLearningInfoTransportActionTests extends ESTestCase {
|
|
|
new QueryPage<>(Collections.emptyList(), 0, GetTrainedModelsStatsAction.Response.RESULTS_FIELD)
|
|
|
)
|
|
|
);
|
|
|
+ givenMlMemory(
|
|
|
+ new MlMemoryAction.Response(
|
|
|
+ new ClusterName("cluster_foo"),
|
|
|
+ List.of(
|
|
|
+ new MlMemoryAction.Response.MlMemoryStats(
|
|
|
+ mock(DiscoveryNode.class),
|
|
|
+ ByteSizeValue.ofBytes(100L),
|
|
|
+ ByteSizeValue.ofBytes(1L),
|
|
|
+ ByteSizeValue.ofBytes(1L),
|
|
|
+ ByteSizeValue.ofBytes(1L),
|
|
|
+ ByteSizeValue.ofBytes(20L),
|
|
|
+ ByteSizeValue.ofBytes(30L),
|
|
|
+ ByteSizeValue.ofBytes(40L),
|
|
|
+ ByteSizeValue.ofBytes(1L),
|
|
|
+ ByteSizeValue.ofBytes(1L),
|
|
|
+ ByteSizeValue.ofBytes(1L)
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ List.of()
|
|
|
+ )
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
@After
|
|
@@ -343,6 +367,8 @@ public class MachineLearningInfoTransportActionTests extends ESTestCase {
|
|
|
assertThat(source.getValue("inference.deployments.inference_counts.avg"), equalTo(4.0));
|
|
|
assertThat(source.getValue("inference.deployments.stats_by_model.0.model_id"), equalTo("model_3"));
|
|
|
assertThat(source.getValue("inference.deployments.stats_by_model.0.task_type"), equalTo("ner"));
|
|
|
+ assertThat(source.getValue("inference.deployments.stats_by_model.0.num_allocations"), equalTo(8));
|
|
|
+ assertThat(source.getValue("inference.deployments.stats_by_model.0.num_threads"), equalTo(1));
|
|
|
assertThat(source.getValue("inference.deployments.stats_by_model.0.last_access"), equalTo(lastAccess(3).toString()));
|
|
|
assertThat(source.getValue("inference.deployments.stats_by_model.0.inference_counts.total"), equalTo(3.0));
|
|
|
assertThat(source.getValue("inference.deployments.stats_by_model.0.inference_counts.min"), equalTo(3.0));
|
|
@@ -350,6 +376,8 @@ public class MachineLearningInfoTransportActionTests extends ESTestCase {
|
|
|
assertThat(source.getValue("inference.deployments.stats_by_model.0.inference_counts.avg"), equalTo(3.0));
|
|
|
assertThat(source.getValue("inference.deployments.stats_by_model.1.model_id"), equalTo("model_4"));
|
|
|
assertThat(source.getValue("inference.deployments.stats_by_model.1.task_type"), equalTo("text_expansion"));
|
|
|
+ assertThat(source.getValue("inference.deployments.stats_by_model.1.num_allocations"), equalTo(2));
|
|
|
+ assertThat(source.getValue("inference.deployments.stats_by_model.1.num_threads"), equalTo(2));
|
|
|
assertThat(source.getValue("inference.deployments.stats_by_model.1.last_access"), equalTo(lastAccess(44).toString()));
|
|
|
assertThat(source.getValue("inference.deployments.stats_by_model.1.inference_counts.total"), equalTo(9.0));
|
|
|
assertThat(source.getValue("inference.deployments.stats_by_model.1.inference_counts.min"), equalTo(4.0));
|
|
@@ -360,6 +388,11 @@ public class MachineLearningInfoTransportActionTests extends ESTestCase {
|
|
|
assertThat(source.getValue("inference.deployments.model_sizes_bytes.max"), equalTo(1000.0));
|
|
|
assertThat(source.getValue("inference.deployments.model_sizes_bytes.avg"), equalTo(650.0));
|
|
|
assertThat(source.getValue("inference.deployments.time_ms.avg"), closeTo(44.0, 1e-10));
|
|
|
+
|
|
|
+ assertThat(source.getValue("memory.anomaly_detectors_memory_bytes"), equalTo(20));
|
|
|
+ assertThat(source.getValue("memory.data_frame_analytics_memory_bytes"), equalTo(30));
|
|
|
+ assertThat(source.getValue("memory.pytorch_inference_memory_bytes"), equalTo(40));
|
|
|
+ assertThat(source.getValue("memory.total_used_memory_bytes"), equalTo(91));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -566,6 +599,8 @@ public class MachineLearningInfoTransportActionTests extends ESTestCase {
|
|
|
Job closed1 = buildJob("closed1", Arrays.asList(buildMinDetector("foo"), buildMinDetector("bar"), buildMinDetector("foobar")));
|
|
|
GetJobsStatsAction.Response.JobStats closed1JobStats = buildJobStats("closed1", JobState.CLOSED, 300L, 0);
|
|
|
givenJobs(Arrays.asList(opened1, closed1), Arrays.asList(opened1JobStats, opened2JobStats, closed1JobStats));
|
|
|
+ MlMemoryAction.Response memory = new MlMemoryAction.Response(new ClusterName("foo"), List.of(), List.of());
|
|
|
+ givenMlMemory(memory);
|
|
|
|
|
|
var usageAction = newUsageAction(settings.build(), true, true, true);
|
|
|
PlainActionFuture<XPackUsageFeatureResponse> future = new PlainActionFuture<>();
|
|
@@ -590,6 +625,11 @@ public class MachineLearningInfoTransportActionTests extends ESTestCase {
|
|
|
assertThat(source.getValue("jobs._all.model_size.avg"), equalTo(200.0));
|
|
|
assertThat(source.getValue("jobs._all.created_by.a_cool_module"), equalTo(1));
|
|
|
assertThat(source.getValue("jobs._all.created_by.unknown"), equalTo(1));
|
|
|
+
|
|
|
+ assertThat(source.getValue("memory.anomaly_detectors_memory_bytes"), equalTo(0));
|
|
|
+ assertThat(source.getValue("memory.data_frame_analytics_memory_bytes"), equalTo(0));
|
|
|
+ assertThat(source.getValue("memory.pytorch_inference_memory_bytes"), equalTo(0));
|
|
|
+ assertThat(source.getValue("memory.total_used_memory_bytes"), equalTo(0));
|
|
|
}
|
|
|
|
|
|
public void testUsageDisabledML() throws Exception {
|
|
@@ -802,6 +842,15 @@ public class MachineLearningInfoTransportActionTests extends ESTestCase {
|
|
|
}).when(client).execute(same(GetTrainedModelsStatsAction.INSTANCE), any(), any());
|
|
|
}
|
|
|
|
|
|
+ private void givenMlMemory(MlMemoryAction.Response memoryUsage) {
|
|
|
+ doAnswer(invocationOnMock -> {
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ ActionListener<MlMemoryAction.Response> listener = (ActionListener<MlMemoryAction.Response>) invocationOnMock.getArguments()[2];
|
|
|
+ listener.onResponse(memoryUsage);
|
|
|
+ return Void.TYPE;
|
|
|
+ }).when(client).execute(same(MlMemoryAction.INSTANCE), any(), any());
|
|
|
+ }
|
|
|
+
|
|
|
private static Detector buildMinDetector(String fieldName) {
|
|
|
Detector.Builder detectorBuilder = new Detector.Builder();
|
|
|
detectorBuilder.setFunction("min");
|
|
@@ -1004,8 +1053,8 @@ public class MachineLearningInfoTransportActionTests extends ESTestCase {
|
|
|
new AssignmentStats(
|
|
|
"deployment_3",
|
|
|
"model_3",
|
|
|
- null,
|
|
|
- null,
|
|
|
+ 1,
|
|
|
+ 8,
|
|
|
null,
|
|
|
null,
|
|
|
null,
|
|
@@ -1111,6 +1160,29 @@ public class MachineLearningInfoTransportActionTests extends ESTestCase {
|
|
|
)
|
|
|
)
|
|
|
);
|
|
|
+
|
|
|
+ givenMlMemory(
|
|
|
+ new MlMemoryAction.Response(
|
|
|
+ new ClusterName("cluster_foo"),
|
|
|
+ List.of(
|
|
|
+ new MlMemoryAction.Response.MlMemoryStats(
|
|
|
+ mock(DiscoveryNode.class),
|
|
|
+ ByteSizeValue.ofBytes(100L),
|
|
|
+ ByteSizeValue.ofBytes(1L),
|
|
|
+ ByteSizeValue.ofBytes(1L),
|
|
|
+ ByteSizeValue.ofBytes(1L),
|
|
|
+ ByteSizeValue.ofBytes(20L),
|
|
|
+ ByteSizeValue.ofBytes(30L),
|
|
|
+ ByteSizeValue.ofBytes(40L),
|
|
|
+ ByteSizeValue.ofBytes(1L),
|
|
|
+ ByteSizeValue.ofBytes(1L),
|
|
|
+ ByteSizeValue.ofBytes(1L)
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ List.of()
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
return expectedDfaCountByAnalysis;
|
|
|
}
|
|
|
|