Skip to content

Commit 2ca70f7

Browse files
authored
Deprecate the ability to update datafeed's job_id. (#44691)
1 parent a40ccd9 commit 2ca70f7

File tree

7 files changed

+47
-11
lines changed

7 files changed

+47
-11
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/MachineLearningIT.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,10 @@ public void testPutDatafeed() throws Exception {
436436
}
437437

438438
public void testUpdateDatafeed() throws Exception {
439+
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();
440+
439441
String jobId = randomValidJobId();
440442
Job job = buildJob(jobId);
441-
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();
442443
execute(new PutJobRequest(job), machineLearningClient::putJob, machineLearningClient::putJobAsync);
443444

444445
String datafeedId = "datafeed-" + jobId;
@@ -462,6 +463,31 @@ public void testUpdateDatafeed() throws Exception {
462463
assertThat(datafeedUpdate.getScrollSize(), equalTo(updatedDatafeed.getScrollSize()));
463464
}
464465

466+
public void testUpdateDatafeed_UpdatingJobIdIsDeprecated() throws Exception {
467+
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();
468+
469+
String jobId = randomValidJobId();
470+
Job job = buildJob(jobId);
471+
execute(new PutJobRequest(job), machineLearningClient::putJob, machineLearningClient::putJobAsync);
472+
473+
String anotherJobId = randomValidJobId();
474+
Job anotherJob = buildJob(anotherJobId);
475+
execute(new PutJobRequest(anotherJob), machineLearningClient::putJob, machineLearningClient::putJobAsync);
476+
477+
String datafeedId = "datafeed-" + jobId;
478+
DatafeedConfig datafeedConfig = DatafeedConfig.builder(datafeedId, jobId).setIndices("some_data_index").build();
479+
execute(new PutDatafeedRequest(datafeedConfig), machineLearningClient::putDatafeed, machineLearningClient::putDatafeedAsync);
480+
481+
DatafeedUpdate datafeedUpdateWithChangedJobId = DatafeedUpdate.builder(datafeedId).setJobId(anotherJobId).build();
482+
WarningFailureException exception = expectThrows(
483+
WarningFailureException.class,
484+
() -> execute(
485+
new UpdateDatafeedRequest(datafeedUpdateWithChangedJobId),
486+
machineLearningClient::updateDatafeed,
487+
machineLearningClient::updateDatafeedAsync));
488+
assertThat(exception.getResponse().getWarnings(), contains("The ability to update a datafeed's job_id is deprecated."));
489+
}
490+
465491
public void testGetDatafeed() throws Exception {
466492
String jobId1 = "test-get-datafeed-job-1";
467493
String jobId2 = "test-get-datafeed-job-2";

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MlClientDocumentationIT.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,7 @@ public void testUpdateDatafeed() throws Exception {
730730
.setQuery(QueryBuilders.matchAllQuery()) // <6>
731731
.setQueryDelay(TimeValue.timeValueMinutes(1)) // <7>
732732
.setScriptFields(scriptFields) // <8>
733-
.setScrollSize(1000) // <9>
734-
.setJobId("update-datafeed-job"); // <10>
733+
.setScrollSize(1000); // <9>
735734
// end::update-datafeed-config
736735

737736
// Clearing aggregation to avoid complex validation rules

docs/java-rest/high-level/ml/update-datafeed.asciidoc

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ include-tagged::{doc-tests-file}[{api}-config]
4040
<7> Optional, the time interval behind real time that data is queried.
4141
<8> Optional, allows the use of script fields.
4242
<9> Optional, the `size` parameter used in the searches.
43-
<10> Optional, the `jobId` that references the job that the datafeed should be associated with
44-
after the update.
4543

4644
include::../execution.asciidoc[]
4745

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java

+8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
*/
66
package org.elasticsearch.xpack.core.ml.datafeed;
77

8+
import org.apache.logging.log4j.LogManager;
89
import org.elasticsearch.Version;
910
import org.elasticsearch.common.ParseField;
1011
import org.elasticsearch.common.Strings;
1112
import org.elasticsearch.common.io.stream.StreamInput;
1213
import org.elasticsearch.common.io.stream.StreamOutput;
1314
import org.elasticsearch.common.io.stream.Writeable;
15+
import org.elasticsearch.common.logging.DeprecationLogger;
1416
import org.elasticsearch.common.unit.TimeValue;
1517
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
1618
import org.elasticsearch.common.xcontent.ObjectParser;
@@ -44,6 +46,9 @@
4446
*/
4547
public class DatafeedUpdate implements Writeable, ToXContentObject {
4648

49+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(DatafeedUpdate.class));
50+
private static final String DEPRECATION_MESSAGE_ON_JOB_ID_UPDATE = "The ability to update a datafeed's job_id is deprecated.";
51+
4752
public static final ObjectParser<Builder, Void> PARSER = new ObjectParser<>("datafeed_update", Builder::new);
4853

4954
static {
@@ -105,6 +110,9 @@ private DatafeedUpdate(String id, String jobId, TimeValue queryDelay, TimeValue
105110
this.scrollSize = scrollSize;
106111
this.chunkingConfig = chunkingConfig;
107112
this.delayedDataCheckConfig = delayedDataCheckConfig;
113+
if (jobId != null) {
114+
deprecationLogger.deprecated(DEPRECATION_MESSAGE_ON_JOB_ID_UPDATE);
115+
}
108116
}
109117

110118
public DatafeedUpdate(StreamInput in) throws IOException {

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateDatafeedActionRequestTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void setUpDatafeedId() {
3030

3131
@Override
3232
protected Request createTestInstance() {
33-
return new Request(DatafeedUpdateTests.createRandomized(datafeedId));
33+
return new Request(DatafeedUpdateTests.createRandomized(datafeedId, null, false));
3434
}
3535

3636
@Override

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdateTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ protected DatafeedUpdate createTestInstance() {
7777
}
7878

7979
public static DatafeedUpdate createRandomized(String datafeedId) {
80-
return createRandomized(datafeedId, null);
80+
return createRandomized(datafeedId, null, true);
8181
}
8282

83-
public static DatafeedUpdate createRandomized(String datafeedId, @Nullable DatafeedConfig datafeed) {
83+
public static DatafeedUpdate createRandomized(String datafeedId, @Nullable DatafeedConfig datafeed, boolean canSetJobId) {
8484
DatafeedUpdate.Builder builder = new DatafeedUpdate.Builder(datafeedId);
85-
if (randomBoolean() && datafeed == null) {
85+
if (randomBoolean() && datafeed == null && canSetJobId) {
8686
builder.setJobId(randomAlphaOfLength(10));
8787
}
8888
if (randomBoolean()) {
@@ -276,9 +276,9 @@ public void testApply_GivenRandomUpdates_AssertImmutability() {
276276
withoutAggs.setAggProvider(null);
277277
datafeed = withoutAggs.build();
278278
}
279-
DatafeedUpdate update = createRandomized(datafeed.getId(), datafeed);
279+
DatafeedUpdate update = createRandomized(datafeed.getId(), datafeed, true);
280280
while (update.isNoop(datafeed)) {
281-
update = createRandomized(datafeed.getId(), datafeed);
281+
update = createRandomized(datafeed.getId(), datafeed, true);
282282
}
283283

284284
DatafeedConfig updatedDatafeed = update.apply(datafeed, Collections.emptyMap());

x-pack/plugin/src/test/resources/rest-api-spec/test/ml/datafeeds_crud.yml

+5
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ setup:
203203

204204
---
205205
"Test update datafeed to point to different job":
206+
- skip:
207+
features: "warnings"
208+
206209
- do:
207210
ml.put_datafeed:
208211
datafeed_id: test-datafeed-1
@@ -214,6 +217,8 @@ setup:
214217
}
215218
216219
- do:
220+
warnings:
221+
- The ability to update a datafeed's job_id is deprecated.
217222
ml.update_datafeed:
218223
datafeed_id: test-datafeed-1
219224
body: >

0 commit comments

Comments
 (0)