-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[ML] adding running_state to datafeed stats object #73926
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
benwtrent
merged 4 commits into
elastic:master
from
benwtrent:feature/ml-is-df-realtime
Jun 10, 2021
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ff479e7
[ML] adding running_state to datafeed stats object
benwtrent 3947806
Merge remote-tracking branch 'upstream/master' into feature/ml-is-df-…
benwtrent 99f2319
addressig pr comments
benwtrent 25ed1f9
Merge branch 'master' into feature/ml-is-df-realtime
elasticmachine 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 hidden or 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 | ||||
---|---|---|---|---|---|---|
|
@@ -24,7 +24,7 @@ Retrieves usage information for {dfeeds}. | |||||
[[ml-get-datafeed-stats-prereqs]] | ||||||
== {api-prereq-title} | ||||||
|
||||||
Requires the `monitor_ml` cluster privilege. This privilege is included in the | ||||||
Requires the `monitor_ml` cluster privilege. This privilege is included in the | ||||||
`machine_learning_user` built-in role. | ||||||
|
||||||
[[ml-get-datafeed-stats-desc]] | ||||||
|
@@ -103,6 +103,24 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=node-transport-address] | |||||
==== | ||||||
-- | ||||||
|
||||||
`running_state`:: | ||||||
(object) An object containing the running state for this {dfeed}. It is only | ||||||
provided if the {dfeed} is started. | ||||||
+ | ||||||
-- | ||||||
[%collapsible%open] | ||||||
==== | ||||||
`is_real_time`::: | ||||||
(boolean) Indicates if the {dfeed} is "real-time"; meaning that the {dfeed} | ||||||
has no configured `end` time. | ||||||
|
||||||
`finished_look_back`::: | ||||||
(boolean) Has the {dfeed} finished running on the available past data. For {dfeeds} | ||||||
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.
Suggested change
|
||||||
that without a configured `end` time, this means that the {dfeed} is now running on | ||||||
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.
Suggested change
|
||||||
"real-time" data. | ||||||
==== | ||||||
-- | ||||||
|
||||||
`state`:: | ||||||
(string) | ||||||
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=state-datafeed] | ||||||
|
170 changes: 170 additions & 0 deletions
170
...e/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedRunningStateAction.java
This file contains hidden or 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,170 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.core.ml.action; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.tasks.BaseTasksRequest; | ||
import org.elasticsearch.action.support.tasks.BaseTasksResponse; | ||
import org.elasticsearch.common.collect.MapBuilder; | ||
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.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.xpack.core.ml.MlTasks; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
|
||
/** | ||
* Internal only action to get the current running state of a datafeed | ||
*/ | ||
public class GetDatafeedRunningStateAction extends ActionType<GetDatafeedRunningStateAction.Response> { | ||
|
||
public static final GetDatafeedRunningStateAction INSTANCE = new GetDatafeedRunningStateAction(); | ||
public static final String NAME = "cluster:internal/xpack/ml/datafeed/running_state"; | ||
|
||
private GetDatafeedRunningStateAction() { | ||
super(NAME, GetDatafeedRunningStateAction.Response::new); | ||
} | ||
|
||
public static class Request extends BaseTasksRequest<Request> { | ||
|
||
private final Set<String> datafeedTaskIds; | ||
|
||
public Request(List<String> datafeedIds) { | ||
this.datafeedTaskIds = datafeedIds.stream().map(MlTasks::datafeedTaskId).collect(Collectors.toSet()); | ||
} | ||
|
||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
this.datafeedTaskIds = in.readSet(StreamInput::readString); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeStringCollection(datafeedTaskIds); | ||
} | ||
|
||
public Set<String> getDatafeedTaskIds() { | ||
return datafeedTaskIds; | ||
} | ||
|
||
@Override | ||
public boolean match(Task task) { | ||
return task instanceof StartDatafeedAction.DatafeedTaskMatcher && datafeedTaskIds.contains(task.getDescription()); | ||
} | ||
} | ||
|
||
public static class Response extends BaseTasksResponse { | ||
|
||
public static class RunningState implements Writeable, ToXContentObject { | ||
|
||
// Is the datafeed a "realtime" datafeed, meaning it was started without an end_time | ||
private final boolean isRealTime; | ||
// Has the look back finished. | ||
private final boolean finishedLookBack; | ||
|
||
public RunningState(boolean isRealTime, boolean finishedLookBack) { | ||
this.isRealTime = isRealTime; | ||
this.finishedLookBack = finishedLookBack; | ||
} | ||
|
||
public RunningState(StreamInput in) throws IOException { | ||
this.isRealTime = in.readBoolean(); | ||
this.finishedLookBack = in.readBoolean(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
RunningState that = (RunningState) o; | ||
return isRealTime == that.isRealTime && finishedLookBack == that.finishedLookBack; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(isRealTime, finishedLookBack); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeBoolean(isRealTime); | ||
out.writeBoolean(finishedLookBack); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field("is_real_time", isRealTime); | ||
builder.field("finished_look_back", finishedLookBack); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} | ||
|
||
private final Map<String, RunningState> datafeedRunningState; | ||
|
||
public static Response fromResponses(List<Response> responses) { | ||
return new Response(responses.stream() | ||
.flatMap(r -> r.datafeedRunningState.entrySet().stream()) | ||
.filter(entry -> entry.getValue() != null) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); | ||
} | ||
|
||
public static Response fromTaskAndState(String datafeedId, RunningState runningState) { | ||
return new Response(MapBuilder.<String, RunningState>newMapBuilder().put(datafeedId, runningState).map()); | ||
} | ||
|
||
public Response(StreamInput in) throws IOException { | ||
super(in); | ||
datafeedRunningState = in.readMap(StreamInput::readString, RunningState::new); | ||
} | ||
|
||
public Response(Map<String, RunningState> runtimeStateMap) { | ||
super(null, null); | ||
this.datafeedRunningState = runtimeStateMap; | ||
} | ||
|
||
public Optional<RunningState> getRunningState(String datafeedId) { | ||
return Optional.ofNullable(datafeedRunningState.get(datafeedId)); | ||
} | ||
|
||
public Map<String, RunningState> getDatafeedRunningState() { | ||
return datafeedRunningState; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeMap(datafeedRunningState, StreamOutput::writeString, (o, w) -> w.writeTo(o)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Response response = (Response) o; | ||
return Objects.equals(this.datafeedRunningState, response.datafeedRunningState); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(datafeedRunningState); | ||
} | ||
} | ||
|
||
} |
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.
Our existing docs don't use the term "lookback". I am not sure we should introduce it now.
One solution would be to rename
is_real_time
toreal_time_configured
andfinished_look_back
toreal_time_running
. Then that doesn't involve introducing a new public term.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.
@droberts195
While its true that we don't use it in docs,
lookback
is used in audit messages: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.
I am happy to change to both to indicate
real_time
. But we do use lookback in user facing things.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.
Oh, interesting. I think we made the decision in 2016 not to use it anywhere user-facing, but those audit messages were added in 2017, by which time the 2016 decision had been forgotten. I guess the lesson is that we should change our terminology in internal code as well as what's immediately user-facing to stop internal terminology leaking out later on.
I still think there is a benefit in not propagating the term to fields that will appear in every high level client's public API. At the moment we could change the wording of those audit messages without making a breaking change, but the REST responses are harder to change once published.
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.
okey dokey, I will rename the variables.
100%. Renaming things everywhere prevents this sort of thing.