From 00c391602d39d07bf4b7241ee5f53db96265a8ff Mon Sep 17 00:00:00 2001 From: Dimitris Athanasiou Date: Wed, 28 Mar 2018 16:05:42 +0100 Subject: [PATCH] [ML] Cap default model_memory_limit in the ML info API (elastic/x-pack-elasticsearch#4249) Original commit: elastic/x-pack-elasticsearch@dc614ad37087ab72c89be5c95bff3d16d78acfb9 --- .../xpack/ml/action/TransportMlInfoAction.java | 13 +++++++++++-- .../rest-api-spec/test/ml/ml_info.yml | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportMlInfoAction.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportMlInfoAction.java index f799e204799..ddd7d691b3e 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportMlInfoAction.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportMlInfoAction.java @@ -55,13 +55,22 @@ public class TransportMlInfoAction extends HandledTransportAction anomalyDetectorsDefaults() { Map defaults = new HashMap<>(); - defaults.put(AnalysisLimits.MODEL_MEMORY_LIMIT.getPreferredName(), - new ByteSizeValue(AnalysisLimits.DEFAULT_MODEL_MEMORY_LIMIT_MB, ByteSizeUnit.MB)); + defaults.put(AnalysisLimits.MODEL_MEMORY_LIMIT.getPreferredName(), defaultModelMemoryLimit()); defaults.put(AnalysisLimits.CATEGORIZATION_EXAMPLES_LIMIT.getPreferredName(), AnalysisLimits.DEFAULT_CATEGORIZATION_EXAMPLES_LIMIT); defaults.put(Job.MODEL_SNAPSHOT_RETENTION_DAYS.getPreferredName(), Job.DEFAULT_MODEL_SNAPSHOT_RETENTION_DAYS); return defaults; } + private ByteSizeValue defaultModelMemoryLimit() { + ByteSizeValue defaultLimit = new ByteSizeValue(AnalysisLimits.DEFAULT_MODEL_MEMORY_LIMIT_MB, ByteSizeUnit.MB); + ByteSizeValue maxModelMemoryLimit = clusterService.getClusterSettings().get(MachineLearningField.MAX_MODEL_MEMORY_LIMIT); + if (maxModelMemoryLimit != null && maxModelMemoryLimit.getBytes() > 0 + && maxModelMemoryLimit.getBytes() < defaultLimit.getBytes()) { + return maxModelMemoryLimit; + } + return defaultLimit; + } + private Map datafeedsDefaults() { Map anomalyDetectorsDefaults = new HashMap<>(); anomalyDetectorsDefaults.put(DatafeedConfig.SCROLL_SIZE.getPreferredName(), DatafeedConfig.DEFAULT_SCROLL_SIZE); diff --git a/plugin/src/test/resources/rest-api-spec/test/ml/ml_info.yml b/plugin/src/test/resources/rest-api-spec/test/ml/ml_info.yml index 1ec2b5ea7a6..ce934c1d2f6 100644 --- a/plugin/src/test/resources/rest-api-spec/test/ml/ml_info.yml +++ b/plugin/src/test/resources/rest-api-spec/test/ml/ml_info.yml @@ -12,7 +12,21 @@ cluster.put_settings: body: persistent: - xpack.ml.max_model_memory_limit: "4gb" + xpack.ml.max_model_memory_limit: "512mb" + + - do: + xpack.ml.info: {} + - match: { defaults.anomaly_detectors.model_memory_limit: "512mb" } + - match: { defaults.anomaly_detectors.categorization_examples_limit: 4 } + - match: { defaults.anomaly_detectors.model_snapshot_retention_days: 1 } + - match: { defaults.datafeeds.scroll_size: 1000 } + - match: { limits.max_model_memory_limit: "512mb" } + + - do: + cluster.put_settings: + body: + persistent: + xpack.ml.max_model_memory_limit: "6gb" - do: xpack.ml.info: {} @@ -20,4 +34,4 @@ - match: { defaults.anomaly_detectors.categorization_examples_limit: 4 } - match: { defaults.anomaly_detectors.model_snapshot_retention_days: 1 } - match: { defaults.datafeeds.scroll_size: 1000 } - - match: { limits.max_model_memory_limit: "4gb" } + - match: { limits.max_model_memory_limit: "6gb" }