|
@@ -230,6 +230,37 @@ public class AutodetectMemoryLimitIT extends MlNativeAutodetectIntegTestCase {
|
|
|
assertThat(modelSizeStats.getMemoryStatus(), equalTo(ModelSizeStats.MemoryStatus.HARD_LIMIT));
|
|
|
}
|
|
|
|
|
|
+ public void testOpenJobShouldHaveModelSizeStats() throws Exception {
|
|
|
+ // When a job is opened, it should have non-zero model stats that indicate the memory limit and the assignment basis
|
|
|
+ Detector.Builder detector = new Detector.Builder("sum", "value");
|
|
|
+ detector.setOverFieldName("user");
|
|
|
+
|
|
|
+ TimeValue bucketSpan = TimeValue.timeValueHours(1);
|
|
|
+ AnalysisConfig.Builder analysisConfig = new AnalysisConfig.Builder(Collections.singletonList(detector.build()));
|
|
|
+ analysisConfig.setBucketSpan(bucketSpan);
|
|
|
+ DataDescription.Builder dataDescription = new DataDescription.Builder();
|
|
|
+ dataDescription.setTimeFormat("epoch");
|
|
|
+ Job.Builder job = new Job.Builder("autodetect-open-job-should-have-model-size-stats");
|
|
|
+ job.setAnalysisConfig(analysisConfig);
|
|
|
+ job.setDataDescription(dataDescription);
|
|
|
+
|
|
|
+ // Set the memory limit to 110MB
|
|
|
+ AnalysisLimits limits = new AnalysisLimits(110L, null);
|
|
|
+ job.setAnalysisLimits(limits);
|
|
|
+
|
|
|
+ putJob(job);
|
|
|
+ openJob(job.getId());
|
|
|
+ GetJobsStatsAction.Response.JobStats jobStats = getJobStats(job.getId()).get(0);
|
|
|
+ ModelSizeStats modelSizeStats = jobStats.getModelSizeStats();
|
|
|
+ closeJob(job.getId());
|
|
|
+
|
|
|
+ assertThat(modelSizeStats.getModelBytes(), equalTo(0L));
|
|
|
+ assertThat(modelSizeStats.getModelBytesMemoryLimit(), equalTo(110L));
|
|
|
+ assertThat(modelSizeStats.getMemoryStatus(), equalTo(ModelSizeStats.MemoryStatus.OK));
|
|
|
+ assertThat(modelSizeStats.getAssignmentMemoryBasis(), equalTo(ModelSizeStats.AssignmentMemoryBasis.MODEL_MEMORY_LIMIT));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private static Map<String, Object> createRecord(long timestamp, String user, String department) {
|
|
|
Map<String, Object> record = new HashMap<>();
|
|
|
record.put("time", timestamp);
|