From 3fc0f7695b5e2952da3981b8b66b447c96b7fbd3 Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Tue, 9 Apr 2019 16:27:03 +0200 Subject: [PATCH 1/3] Add YML test for too large forecast duration. --- .../src/test/resources/rest-api-spec/test/ml/forecast.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml index 998f70de9d35d..f777559ac3df7 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml @@ -47,6 +47,14 @@ setup: job_id: "forecast-job" duration: "-1s" +--- +"Test forecast given duration is too large": + - do: + catch: /\[duration\] must be 56d or less[:] \[57d\]/ + ml.forecast: + job_id: "forecast-job" + duration: "57d" + --- "Test forecast given expires_in is negative": - do: From a8d4d16614a41e4af620c575d929f593d8692d96 Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Tue, 9 Apr 2019 17:12:14 +0200 Subject: [PATCH 2/3] Remove validation that restricts forecast job duration to 8 weeks. --- .../xpack/core/ml/action/ForecastJobAction.java | 7 ------- .../src/test/resources/rest-api-spec/test/ml/forecast.yml | 8 -------- 2 files changed, 15 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java index 0ea66ad0937c2..da0aec1a9eef8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java @@ -48,9 +48,6 @@ public static class Request extends JobTaskRequest implements ToXConten public static final ParseField DURATION = new ParseField("duration"); public static final ParseField EXPIRES_IN = new ParseField("expires_in"); - // Max allowed duration: 8 weeks - private static final TimeValue MAX_DURATION = TimeValue.parseTimeValue("56d", ""); - private static final ObjectParser PARSER = new ObjectParser<>(NAME, Request::new); static { @@ -104,10 +101,6 @@ public void setDuration(TimeValue duration) { throw new IllegalArgumentException("[" + DURATION.getPreferredName() + "] must be positive: [" + duration.getStringRep() + "]"); } - if (this.duration.compareTo(MAX_DURATION) > 0) { - throw new IllegalArgumentException("[" + DURATION.getPreferredName() + "] must be " - + MAX_DURATION.getStringRep() + " or less: [" + duration.getStringRep() + "]"); - } } public TimeValue getExpiresIn() { diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml index f777559ac3df7..998f70de9d35d 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml @@ -47,14 +47,6 @@ setup: job_id: "forecast-job" duration: "-1s" ---- -"Test forecast given duration is too large": - - do: - catch: /\[duration\] must be 56d or less[:] \[57d\]/ - ml.forecast: - job_id: "forecast-job" - duration: "57d" - --- "Test forecast given expires_in is negative": - do: From 49b799184c6edb89318ff46c0ae4de2138e2cabb Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Wed, 10 Apr 2019 17:26:11 +0200 Subject: [PATCH 3/3] Increase the maximum duration to ~10 years (3650 days). --- .../xpack/core/ml/action/ForecastJobAction.java | 7 +++++++ .../src/test/resources/rest-api-spec/test/ml/forecast.yml | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java index da0aec1a9eef8..fb107579c6e66 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java @@ -48,6 +48,9 @@ public static class Request extends JobTaskRequest implements ToXConten public static final ParseField DURATION = new ParseField("duration"); public static final ParseField EXPIRES_IN = new ParseField("expires_in"); + // Max allowed duration: 10 years + private static final TimeValue MAX_DURATION = TimeValue.parseTimeValue("3650d", ""); + private static final ObjectParser PARSER = new ObjectParser<>(NAME, Request::new); static { @@ -101,6 +104,10 @@ public void setDuration(TimeValue duration) { throw new IllegalArgumentException("[" + DURATION.getPreferredName() + "] must be positive: [" + duration.getStringRep() + "]"); } + if (this.duration.compareTo(MAX_DURATION) > 0) { + throw new IllegalArgumentException("[" + DURATION.getPreferredName() + "] must be " + + MAX_DURATION.getStringRep() + " or less: [" + duration.getStringRep() + "]"); + } } public TimeValue getExpiresIn() { diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml index 998f70de9d35d..a81b6dba08e48 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/forecast.yml @@ -47,6 +47,14 @@ setup: job_id: "forecast-job" duration: "-1s" +--- +"Test forecast given duration is too large": + - do: + catch: /\[duration\] must be 3650d or less[:] \[3651d\]/ + ml.forecast: + job_id: "forecast-job" + duration: "3651d" + --- "Test forecast given expires_in is negative": - do: