-
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] Job in index: Datafeed node selector #34218
Changes from all commits
5d85418
4c5bf87
b75ebd1
df6857c
5a5f111
2db0fe4
04e3baf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,13 @@ | |
import org.elasticsearch.xpack.core.XPackPlugin; | ||
import org.elasticsearch.xpack.core.ml.MlTasks; | ||
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; | ||
import org.elasticsearch.xpack.core.ml.job.config.Job; | ||
import org.elasticsearch.xpack.core.ml.job.messages.Messages; | ||
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.LongSupplier; | ||
|
||
|
@@ -147,6 +150,8 @@ public boolean equals(Object obj) { | |
|
||
public static class DatafeedParams implements XPackPlugin.XPackPersistentTaskParams { | ||
|
||
public static final ParseField INDICES = new ParseField("indices"); | ||
|
||
public static ObjectParser<DatafeedParams, Void> PARSER = new ObjectParser<>(MlTasks.DATAFEED_TASK_NAME, true, DatafeedParams::new); | ||
static { | ||
PARSER.declareString((params, datafeedId) -> params.datafeedId = datafeedId, DatafeedConfig.ID); | ||
|
@@ -155,6 +160,8 @@ public static class DatafeedParams implements XPackPlugin.XPackPersistentTaskPar | |
PARSER.declareString(DatafeedParams::setEndTime, END_TIME); | ||
PARSER.declareString((params, val) -> | ||
params.setTimeout(TimeValue.parseTimeValue(val, TIMEOUT.getPreferredName())), TIMEOUT); | ||
PARSER.declareString(DatafeedParams::setJobId, Job.ID); | ||
PARSER.declareStringArray(DatafeedParams::setDatafeedIndices, INDICES); | ||
} | ||
|
||
static long parseDateOrThrow(String date, ParseField paramName, LongSupplier now) { | ||
|
@@ -194,6 +201,10 @@ public DatafeedParams(StreamInput in) throws IOException { | |
startTime = in.readVLong(); | ||
endTime = in.readOptionalLong(); | ||
timeout = TimeValue.timeValueMillis(in.readVLong()); | ||
if (in.getVersion().onOrAfter(Version.CURRENT)) { | ||
jobId = in.readOptionalString(); | ||
datafeedIndices = in.readList(StreamInput::readString); | ||
} | ||
} | ||
|
||
DatafeedParams() { | ||
|
@@ -203,6 +214,9 @@ public DatafeedParams(StreamInput in) throws IOException { | |
private long startTime; | ||
private Long endTime; | ||
private TimeValue timeout = TimeValue.timeValueSeconds(20); | ||
private List<String> datafeedIndices = Collections.emptyList(); | ||
private String jobId; | ||
|
||
|
||
public String getDatafeedId() { | ||
return datafeedId; | ||
|
@@ -232,6 +246,22 @@ public void setTimeout(TimeValue timeout) { | |
this.timeout = timeout; | ||
} | ||
|
||
public String getJobId() { | ||
return jobId; | ||
} | ||
|
||
public void setJobId(String jobId) { | ||
this.jobId = jobId; | ||
} | ||
|
||
public List<String> getDatafeedIndices() { | ||
return datafeedIndices; | ||
} | ||
|
||
public void setDatafeedIndices(List<String> datafeedIndices) { | ||
this.datafeedIndices = datafeedIndices; | ||
} | ||
|
||
@Override | ||
public String getWriteableName() { | ||
return MlTasks.DATAFEED_TASK_NAME; | ||
|
@@ -248,6 +278,10 @@ public void writeTo(StreamOutput out) throws IOException { | |
out.writeVLong(startTime); | ||
out.writeOptionalLong(endTime); | ||
out.writeVLong(timeout.millis()); | ||
if (out.getVersion().onOrAfter(Version.CURRENT)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, surely this should be a specific version? |
||
out.writeOptionalString(jobId); | ||
out.writeStringList(datafeedIndices); | ||
} | ||
} | ||
|
||
@Override | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems wrong that However, I think the solution to this problem is not to put the whole datafeed config in the X-Content representation. That creates the same problem we have now where search syntax that's been removed prevents reading the cluster state from disk. This leads to the conclusion that instead of storing the whole datafeed config in the task params we should store just enough fields from it to validate allocation, and definitely not the search or aggregations. Then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is because the params do not have a lenient parser (see #33950), in 7 this won't be the case and the new fields can be written.
The feature branch isn't at a point where the QA tests can be run yet but true. This will have to be handled by the migration process in a future PR but given that the persistent task params cannot be modified the only solution may be to stop and restart the job & datafeed. I choose to put the datafeed in the params as once the datafeed has been validated the same config should be used but this does add weight to the cluster state and is not good for the reasons mentioned above especially deprecated search & aggs config. I've changed it to use the minimal set of fields (job id & datafeed indices). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The migration process will only move datafeeds from cluster state to index when the entire cluster has been upgraded to whatever version this goes into (6.6 or 6.7). So if we can find the minimum node version in the cluster in So if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reasoning is thus:
That seems reasonable enough until we hit a datafeed job created in 6.4 which is not stopped before 8
I can't see a way of doing this and it won't help with full cluster restarts from 6.5 I could add the code to read job_id from the datafeed config in the clusterstate in this PR but I have no mechanism of testing it yet and have not started on the migration code. My preference is to finish the work on making jobs run from the new config and make it stable then tackle this issue (and others) in the migration work. |
||
|
@@ -259,13 +293,19 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par | |
builder.field(END_TIME.getPreferredName(), String.valueOf(endTime)); | ||
} | ||
builder.field(TIMEOUT.getPreferredName(), timeout.getStringRep()); | ||
if (jobId != null) { | ||
builder.field(Job.ID.getPreferredName(), jobId); | ||
} | ||
if (datafeedIndices.isEmpty() == false) { | ||
builder.field(INDICES.getPreferredName(), datafeedIndices); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(datafeedId, startTime, endTime, timeout); | ||
return Objects.hash(datafeedId, startTime, endTime, timeout, jobId, datafeedIndices); | ||
} | ||
|
||
@Override | ||
|
@@ -280,7 +320,9 @@ public boolean equals(Object obj) { | |
return Objects.equals(datafeedId, other.datafeedId) && | ||
Objects.equals(startTime, other.startTime) && | ||
Objects.equals(endTime, other.endTime) && | ||
Objects.equals(timeout, other.timeout); | ||
Objects.equals(timeout, other.timeout) && | ||
Objects.equals(jobId, other.jobId) && | ||
Objects.equals(datafeedIndices, other.datafeedIndices); | ||
} | ||
} | ||
|
||
|
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.
It seems like this should be a specific version, not
Version.CURRENT
. Once we get to a mixed version 7.2/7.3 cluster surely it would be OK for the master node to be on 7.2?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.
CURRENT is a placeholder. This is to be merged into a feature branch that will merge into 6.x at some point in the future into in an unknown version. There is no version constant > 6.5.0 so it's CURRENT for now. OpenJobAction is the same, I'll add a checkbox to the meta issue so this isn't forgotten