From 4e03c657a3eae6b75289441efe58700de52a31a1 Mon Sep 17 00:00:00 2001 From: Dimitris Athanasiou Date: Thu, 6 Jul 2017 15:40:19 +0100 Subject: [PATCH] [ML] Write model_memory_limit with units into the cluster state (elastic/x-pack-elasticsearch#1934) This is step 2 of elastic/x-pack-elasticsearch#1604 This change stores `model_memory_limit` as a string with `mb` unit. I considered using the `toString` method of `ByteSizeValue` but it can lead to accuracy loss. Adding the fixed `mb` unit maintains the accuracy, while making clear what unit the value is in. Original commit: elastic/x-pack-elasticsearch@4dc48f0ce8515bbde200042dd0df2756b495fef3 --- docs/en/rest-api/ml/update-job.asciidoc | 4 ++-- .../elasticsearch/xpack/ml/job/config/AnalysisLimits.java | 2 +- .../xpack/ml/job/config/AnalysisLimitsTests.java | 6 ++++++ .../elasticsearch/xpack/ml/job/config/JobBuilderTests.java | 3 +-- .../org/elasticsearch/xpack/ml/job/config/JobTests.java | 2 +- .../elasticsearch/xpack/ml/job/config/JobUpdateTests.java | 2 +- .../src/test/resources/rest-api-spec/test/ml/jobs_crud.yml | 6 +++--- 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/en/rest-api/ml/update-job.asciidoc b/docs/en/rest-api/ml/update-job.asciidoc index fee35776cec..a356fbbeeb9 100644 --- a/docs/en/rest-api/ml/update-job.asciidoc +++ b/docs/en/rest-api/ml/update-job.asciidoc @@ -92,7 +92,7 @@ POST _xpack/ml/anomaly_detectors/it_ops_new_logs/_update "enabled": true }, "analysis_limits": { - "model_memory_limit": 1024 + "model_memory_limit": "1024mb" }, "renormalization_window_days": 30, "background_persist_interval": "2h", @@ -135,7 +135,7 @@ information, including the updated property values. For example: "influencers": [] }, "analysis_limits": { - "model_memory_limit": 1024 + "model_memory_limit": "1024mb" }, "data_description": { "time_field": "time", diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/config/AnalysisLimits.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/config/AnalysisLimits.java index 0cf3a22a7f9..9fb159c3355 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/config/AnalysisLimits.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/config/AnalysisLimits.java @@ -126,7 +126,7 @@ public class AnalysisLimits implements ToXContentObject, Writeable { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (modelMemoryLimit != null) { - builder.field(MODEL_MEMORY_LIMIT.getPreferredName(), modelMemoryLimit); + builder.field(MODEL_MEMORY_LIMIT.getPreferredName(), modelMemoryLimit + "mb"); } if (categorizationExamplesLimit != null) { builder.field(CATEGORIZATION_EXAMPLES_LIMIT.getPreferredName(), categorizationExamplesLimit); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/AnalysisLimitsTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/AnalysisLimitsTests.java index a09b3fdab59..876cd705da3 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/AnalysisLimitsTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/AnalysisLimitsTests.java @@ -8,6 +8,8 @@ package org.elasticsearch.xpack.ml.job.config; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.unit.ByteSizeUnit; +import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; @@ -24,6 +26,10 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase { builder.setAnalysisConfig(AnalysisConfigTests.createRandomized()); } if (randomBoolean()) { - builder.setAnalysisLimits(new AnalysisLimits(randomNonNegativeLong(), - randomNonNegativeLong())); + builder.setAnalysisLimits(AnalysisLimitsTests.createRandomized()); } if (randomBoolean()) { DataDescription.Builder dataDescription = new DataDescription.Builder(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobTests.java index ee971febbea..53c25fca109 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobTests.java @@ -508,7 +508,7 @@ public class JobTests extends AbstractSerializingTestCase { builder.setLastDataTime(new Date(randomNonNegativeLong())); } builder.setAnalysisConfig(AnalysisConfigTests.createRandomized()); - builder.setAnalysisLimits(new AnalysisLimits(randomNonNegativeLong(), randomNonNegativeLong())); + builder.setAnalysisLimits(AnalysisLimitsTests.createRandomized()); DataDescription.Builder dataDescription = new DataDescription.Builder(); dataDescription.setFormat(randomFrom(DataDescription.DataFormat.values())); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobUpdateTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobUpdateTests.java index e0ae23011ee..e261b3426a1 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobUpdateTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobUpdateTests.java @@ -51,7 +51,7 @@ public class JobUpdateTests extends AbstractSerializingTestCase { update.setModelPlotConfig(new ModelPlotConfig(randomBoolean(), randomAlphaOfLength(10))); } if (randomBoolean()) { - update.setAnalysisLimits(new AnalysisLimits(randomNonNegativeLong(), randomNonNegativeLong())); + update.setAnalysisLimits(AnalysisLimitsTests.createRandomized()); } if (randomBoolean()) { update.setRenormalizationWindowDays(randomNonNegativeLong()); diff --git a/plugin/src/test/resources/rest-api-spec/test/ml/jobs_crud.yml b/plugin/src/test/resources/rest-api-spec/test/ml/jobs_crud.yml index 07342f5c066..1070cd335d7 100644 --- a/plugin/src/test/resources/rest-api-spec/test/ml/jobs_crud.yml +++ b/plugin/src/test/resources/rest-api-spec/test/ml/jobs_crud.yml @@ -88,7 +88,7 @@ } } - match: { job_id: "job-model-memory-limit-as-number" } - - match: { analysis_limits.model_memory_limit: 2048 } + - match: { analysis_limits.model_memory_limit: "2048mb" } --- "Test put job with model_memory_limit as string": @@ -108,7 +108,7 @@ } } - match: { job_id: "job-model-memory-limit-as-string" } - - match: { analysis_limits.model_memory_limit: 3072 } + - match: { analysis_limits.model_memory_limit: "3072mb" } --- "Test get job API with non existing job id": @@ -302,7 +302,7 @@ - match: { description: "Post update description" } - match: { model_plot_config.enabled: false } - match: { model_plot_config.terms: "foobar" } - - match: { analysis_limits.model_memory_limit: 20 } + - match: { analysis_limits.model_memory_limit: "20mb" } - match: { analysis_config.categorization_filters: ["cat3.*"] } - match: { analysis_config.detectors.0.detector_rules.0.target_field_name: "airline" } - match: { analysis_config.detectors.0.detector_index: 0 }