-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
ML: add migrate anomalies assistant #36643
Merged
benwtrent
merged 28 commits into
elastic:master
from
benwtrent:feature/ml-migrate-anomalies-assistent
Jan 9, 2019
+1,826
−111
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7effc73
ML: add migrate anomalies assistant
benwtrent d578d1b
adjusting failure handling for reindex
benwtrent a74bcfe
Fixing request and tests
benwtrent 9a43a54
Adding tests to blacklist
benwtrent b3fccc6
adjusting test
benwtrent 07ed2a1
test fix: posting data directly to the job instead of relying on data…
benwtrent bf9e223
adjusting API usage
benwtrent 4a92d35
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent 064ac69
adding Todos and adjusting endpoint
benwtrent ba0df3a
Adding types to reindexRequest
benwtrent a4c5e86
removing unreliable "live" data test
benwtrent 28576fd
adding index refresh to test
benwtrent 8e9451e
adding index refresh to test
benwtrent cb9607d
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent 1d6c66c
adding index refresh to yaml test
benwtrent fa56850
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent b341424
fixing bad exists call
benwtrent 3f47ce0
removing todo
benwtrent 5c1683c
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent 02603ef
Addressing remove comments
benwtrent 4e926f9
Adjusting rest endpoint name
benwtrent 1661c45
making service have its own logger
benwtrent cd9c747
adjusting validity check for newindex names
benwtrent 1594b49
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent 0650294
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent 674463c
fixing typos
benwtrent c4cf94f
Merge branch 'master' into feature/ml-migrate-anomalies-assistent
benwtrent 2d67895
fixing renaming
benwtrent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/MlUpgradeAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.ml.action; | ||
|
||
import org.elasticsearch.action.Action; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; | ||
import org.elasticsearch.action.support.master.MasterNodeReadRequest; | ||
import org.elasticsearch.client.ElasticsearchClient; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.xcontent.ObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.tasks.CancellableTask; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.tasks.TaskId; | ||
import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
|
||
public class MlUpgradeAction extends Action<AcknowledgedResponse> { | ||
public static final MlUpgradeAction INSTANCE = new MlUpgradeAction(); | ||
public static final String NAME = "cluster:admin/xpack/ml/upgrade"; | ||
|
||
private MlUpgradeAction() { | ||
super(NAME); | ||
} | ||
|
||
@Override | ||
public AcknowledgedResponse newResponse() { | ||
return new AcknowledgedResponse(); | ||
} | ||
|
||
public static class Request extends MasterNodeReadRequest<Request> implements ToXContentObject { | ||
|
||
private static final ParseField REINDEX_BATCH_SIZE = new ParseField("reindex_batch_size"); | ||
|
||
public static ObjectParser<Request, Void> PARSER = new ObjectParser<>("ml_upgrade", true, Request::new); | ||
static { | ||
PARSER.declareInt(Request::setReindexBatchSize, REINDEX_BATCH_SIZE); | ||
} | ||
|
||
static final String INDEX = AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*"; | ||
private int reindexBatchSize = 1000; | ||
|
||
/** | ||
* Should this task store its result? | ||
*/ | ||
private boolean shouldStoreResult; | ||
|
||
// for serialization | ||
public Request() { | ||
} | ||
|
||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
reindexBatchSize = in.readInt(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeInt(reindexBatchSize); | ||
} | ||
|
||
public String[] indices() { | ||
return new String[]{INDEX}; | ||
} | ||
|
||
public IndicesOptions indicesOptions() { | ||
return IndicesOptions.strictExpandOpenAndForbidClosed(); | ||
} | ||
|
||
/** | ||
* Should this task store its result after it has finished? | ||
*/ | ||
public Request setShouldStoreResult(boolean shouldStoreResult) { | ||
this.shouldStoreResult = shouldStoreResult; | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean getShouldStoreResult() { | ||
return shouldStoreResult; | ||
} | ||
|
||
public Request setReindexBatchSize(int reindexBatchSize) { | ||
this.reindexBatchSize = reindexBatchSize; | ||
return this; | ||
} | ||
|
||
public int getReindexBatchSize() { | ||
return reindexBatchSize; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
if (reindexBatchSize <= 0) { | ||
ActionRequestValidationException validationException = new ActionRequestValidationException(); | ||
validationException.addValidationError("["+ REINDEX_BATCH_SIZE.getPreferredName()+"] must be greater than 0."); | ||
return validationException; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
Request request = (Request) o; | ||
return Objects.equals(reindexBatchSize, request.reindexBatchSize); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(reindexBatchSize); | ||
} | ||
|
||
@Override | ||
public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) { | ||
return new CancellableTask(id, type, action, "ml-upgrade", parentTaskId, headers) { | ||
@Override | ||
public boolean shouldCancelChildrenOnCancellation() { | ||
return true; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(REINDEX_BATCH_SIZE.getPreferredName(), reindexBatchSize); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} | ||
|
||
public static class RequestBuilder extends MasterNodeReadOperationRequestBuilder<Request, AcknowledgedResponse, RequestBuilder> { | ||
|
||
public RequestBuilder(ElasticsearchClient client) { | ||
super(client, INSTANCE, new Request()); | ||
} | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...ugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/MlUpgradeRequestTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.ml.action; | ||
|
||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
|
||
|
||
public class MlUpgradeRequestTests extends AbstractWireSerializingTestCase<MlUpgradeAction.Request> { | ||
|
||
@Override | ||
protected MlUpgradeAction.Request createTestInstance() { | ||
MlUpgradeAction.Request request = new MlUpgradeAction.Request(); | ||
if (randomBoolean()) { | ||
request.setReindexBatchSize(randomIntBetween(1, 10_000)); | ||
} | ||
return request; | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<MlUpgradeAction.Request> instanceReader() { | ||
return MlUpgradeAction.Request::new; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we test the lower limit, we should also test the upper limit which is default 10000 but can be changed (
index.max_result_window
)(That's one reason why I am thinking it's better not to expose the batch size but rather use a good default)