[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@4dc48f0ce8
This commit is contained in:
Dimitris Athanasiou 2017-07-06 15:40:19 +01:00 committed by GitHub
parent 984d2ca2ba
commit 4e03c657a3
7 changed files with 15 additions and 10 deletions

View File

@ -92,7 +92,7 @@ POST _xpack/ml/anomaly_detectors/it_ops_new_logs/_update
"enabled": true "enabled": true
}, },
"analysis_limits": { "analysis_limits": {
"model_memory_limit": 1024 "model_memory_limit": "1024mb"
}, },
"renormalization_window_days": 30, "renormalization_window_days": 30,
"background_persist_interval": "2h", "background_persist_interval": "2h",
@ -135,7 +135,7 @@ information, including the updated property values. For example:
"influencers": [] "influencers": []
}, },
"analysis_limits": { "analysis_limits": {
"model_memory_limit": 1024 "model_memory_limit": "1024mb"
}, },
"data_description": { "data_description": {
"time_field": "time", "time_field": "time",

View File

@ -126,7 +126,7 @@ public class AnalysisLimits implements ToXContentObject, Writeable {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(); builder.startObject();
if (modelMemoryLimit != null) { if (modelMemoryLimit != null) {
builder.field(MODEL_MEMORY_LIMIT.getPreferredName(), modelMemoryLimit); builder.field(MODEL_MEMORY_LIMIT.getPreferredName(), modelMemoryLimit + "mb");
} }
if (categorizationExamplesLimit != null) { if (categorizationExamplesLimit != null) {
builder.field(CATEGORIZATION_EXAMPLES_LIMIT.getPreferredName(), categorizationExamplesLimit); builder.field(CATEGORIZATION_EXAMPLES_LIMIT.getPreferredName(), categorizationExamplesLimit);

View File

@ -8,6 +8,8 @@ package org.elasticsearch.xpack.ml.job.config;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.io.stream.Writeable; 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.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -24,6 +26,10 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLim
@Override @Override
protected AnalysisLimits createTestInstance() { protected AnalysisLimits createTestInstance() {
return createRandomized();
}
public static AnalysisLimits createRandomized() {
return new AnalysisLimits(randomBoolean() ? (long) randomIntBetween(1, 1000000) : null, return new AnalysisLimits(randomBoolean() ? (long) randomIntBetween(1, 1000000) : null,
randomBoolean() ? randomNonNegativeLong() : null); randomBoolean() ? randomNonNegativeLong() : null);
} }

View File

@ -38,8 +38,7 @@ public class JobBuilderTests extends AbstractSerializingTestCase<Job.Builder> {
builder.setAnalysisConfig(AnalysisConfigTests.createRandomized()); builder.setAnalysisConfig(AnalysisConfigTests.createRandomized());
} }
if (randomBoolean()) { if (randomBoolean()) {
builder.setAnalysisLimits(new AnalysisLimits(randomNonNegativeLong(), builder.setAnalysisLimits(AnalysisLimitsTests.createRandomized());
randomNonNegativeLong()));
} }
if (randomBoolean()) { if (randomBoolean()) {
DataDescription.Builder dataDescription = new DataDescription.Builder(); DataDescription.Builder dataDescription = new DataDescription.Builder();

View File

@ -508,7 +508,7 @@ public class JobTests extends AbstractSerializingTestCase<Job> {
builder.setLastDataTime(new Date(randomNonNegativeLong())); builder.setLastDataTime(new Date(randomNonNegativeLong()));
} }
builder.setAnalysisConfig(AnalysisConfigTests.createRandomized()); builder.setAnalysisConfig(AnalysisConfigTests.createRandomized());
builder.setAnalysisLimits(new AnalysisLimits(randomNonNegativeLong(), randomNonNegativeLong())); builder.setAnalysisLimits(AnalysisLimitsTests.createRandomized());
DataDescription.Builder dataDescription = new DataDescription.Builder(); DataDescription.Builder dataDescription = new DataDescription.Builder();
dataDescription.setFormat(randomFrom(DataDescription.DataFormat.values())); dataDescription.setFormat(randomFrom(DataDescription.DataFormat.values()));

View File

@ -51,7 +51,7 @@ public class JobUpdateTests extends AbstractSerializingTestCase<JobUpdate> {
update.setModelPlotConfig(new ModelPlotConfig(randomBoolean(), randomAlphaOfLength(10))); update.setModelPlotConfig(new ModelPlotConfig(randomBoolean(), randomAlphaOfLength(10)));
} }
if (randomBoolean()) { if (randomBoolean()) {
update.setAnalysisLimits(new AnalysisLimits(randomNonNegativeLong(), randomNonNegativeLong())); update.setAnalysisLimits(AnalysisLimitsTests.createRandomized());
} }
if (randomBoolean()) { if (randomBoolean()) {
update.setRenormalizationWindowDays(randomNonNegativeLong()); update.setRenormalizationWindowDays(randomNonNegativeLong());

View File

@ -88,7 +88,7 @@
} }
} }
- match: { job_id: "job-model-memory-limit-as-number" } - 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": "Test put job with model_memory_limit as string":
@ -108,7 +108,7 @@
} }
} }
- match: { job_id: "job-model-memory-limit-as-string" } - 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": "Test get job API with non existing job id":
@ -302,7 +302,7 @@
- match: { description: "Post update description" } - match: { description: "Post update description" }
- match: { model_plot_config.enabled: false } - match: { model_plot_config.enabled: false }
- match: { model_plot_config.terms: "foobar" } - 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.categorization_filters: ["cat3.*"] }
- match: { analysis_config.detectors.0.detector_rules.0.target_field_name: "airline" } - match: { analysis_config.detectors.0.detector_rules.0.target_field_name: "airline" }
- match: { analysis_config.detectors.0.detector_index: 0 } - match: { analysis_config.detectors.0.detector_index: 0 }