Skip to content

Deprecate the ability to update datafeed's job_id. #44691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,10 @@ public void testPutDatafeed() throws Exception {
}

public void testUpdateDatafeed() throws Exception {
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();

String jobId = randomValidJobId();
Job job = buildJob(jobId);
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();
execute(new PutJobRequest(job), machineLearningClient::putJob, machineLearningClient::putJobAsync);

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

public void testUpdateDatafeed_UpdatingJobIdIsDeprecated() throws Exception {
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();

String jobId = randomValidJobId();
Job job = buildJob(jobId);
execute(new PutJobRequest(job), machineLearningClient::putJob, machineLearningClient::putJobAsync);

String anotherJobId = randomValidJobId();
Job anotherJob = buildJob(anotherJobId);
execute(new PutJobRequest(anotherJob), machineLearningClient::putJob, machineLearningClient::putJobAsync);

String datafeedId = "datafeed-" + jobId;
DatafeedConfig datafeedConfig = DatafeedConfig.builder(datafeedId, jobId).setIndices("some_data_index").build();
execute(new PutDatafeedRequest(datafeedConfig), machineLearningClient::putDatafeed, machineLearningClient::putDatafeedAsync);

DatafeedUpdate datafeedUpdateWithChangedJobId = DatafeedUpdate.builder(datafeedId).setJobId(anotherJobId).build();
WarningFailureException exception = expectThrows(
WarningFailureException.class,
() -> execute(
new UpdateDatafeedRequest(datafeedUpdateWithChangedJobId),
machineLearningClient::updateDatafeed,
machineLearningClient::updateDatafeedAsync));
assertThat(exception.getResponse().getWarnings(), contains("The ability to update a datafeed's job_id is deprecated."));
}

public void testGetDatafeed() throws Exception {
String jobId1 = "test-get-datafeed-job-1";
String jobId2 = "test-get-datafeed-job-2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,7 @@ public void testUpdateDatafeed() throws Exception {
.setQuery(QueryBuilders.matchAllQuery()) // <6>
.setQueryDelay(TimeValue.timeValueMinutes(1)) // <7>
.setScriptFields(scriptFields) // <8>
.setScrollSize(1000) // <9>
.setJobId("update-datafeed-job"); // <10>
.setScrollSize(1000); // <9>
// end::update-datafeed-config

// Clearing aggregation to avoid complex validation rules
Expand Down
2 changes: 0 additions & 2 deletions docs/java-rest/high-level/ml/update-datafeed.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ include-tagged::{doc-tests-file}[{api}-config]
<7> Optional, the time interval behind real time that data is queried.
<8> Optional, allows the use of script fields.
<9> Optional, the `size` parameter used in the searches.
<10> Optional, the `jobId` that references the job that the datafeed should be associated with
after the update.

include::../execution.asciidoc[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
*/
package org.elasticsearch.xpack.core.ml.datafeed;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.Version;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ObjectParser;
Expand Down Expand Up @@ -44,6 +46,9 @@
*/
public class DatafeedUpdate implements Writeable, ToXContentObject {

private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(DatafeedUpdate.class));
private static final String DEPRECATION_MESSAGE_ON_JOB_ID_UPDATE = "The ability to update a datafeed's job_id is deprecated.";

public static final ObjectParser<Builder, Void> PARSER = new ObjectParser<>("datafeed_update", Builder::new);

static {
Expand Down Expand Up @@ -105,6 +110,9 @@ private DatafeedUpdate(String id, String jobId, TimeValue queryDelay, TimeValue
this.scrollSize = scrollSize;
this.chunkingConfig = chunkingConfig;
this.delayedDataCheckConfig = delayedDataCheckConfig;
if (jobId != null) {
deprecationLogger.deprecated(DEPRECATION_MESSAGE_ON_JOB_ID_UPDATE);
}
}

public DatafeedUpdate(StreamInput in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void setUpDatafeedId() {

@Override
protected Request createTestInstance() {
return new Request(DatafeedUpdateTests.createRandomized(datafeedId));
return new Request(DatafeedUpdateTests.createRandomized(datafeedId, null, false));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ protected DatafeedUpdate createTestInstance() {
}

public static DatafeedUpdate createRandomized(String datafeedId) {
return createRandomized(datafeedId, null);
return createRandomized(datafeedId, null, true);
}

public static DatafeedUpdate createRandomized(String datafeedId, @Nullable DatafeedConfig datafeed) {
public static DatafeedUpdate createRandomized(String datafeedId, @Nullable DatafeedConfig datafeed, boolean canSetJobId) {
DatafeedUpdate.Builder builder = new DatafeedUpdate.Builder(datafeedId);
if (randomBoolean() && datafeed == null) {
if (randomBoolean() && datafeed == null && canSetJobId) {
builder.setJobId(randomAlphaOfLength(10));
}
if (randomBoolean()) {
Expand Down Expand Up @@ -276,9 +276,9 @@ public void testApply_GivenRandomUpdates_AssertImmutability() {
withoutAggs.setAggProvider(null);
datafeed = withoutAggs.build();
}
DatafeedUpdate update = createRandomized(datafeed.getId(), datafeed);
DatafeedUpdate update = createRandomized(datafeed.getId(), datafeed, true);
while (update.isNoop(datafeed)) {
update = createRandomized(datafeed.getId(), datafeed);
update = createRandomized(datafeed.getId(), datafeed, true);
}

DatafeedConfig updatedDatafeed = update.apply(datafeed, Collections.emptyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ setup:

---
"Test update datafeed to point to different job":
- skip:
features: "warnings"

- do:
ml.put_datafeed:
datafeed_id: test-datafeed-1
Expand All @@ -214,6 +217,8 @@ setup:
}

- do:
warnings:
- The ability to update a datafeed's job_id is deprecated.
ml.update_datafeed:
datafeed_id: test-datafeed-1
body: >
Expand Down