-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ML-DataFrame] add a stats endpoint #35911
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
hendrikmuhs
merged 6 commits into
elastic:feature/fib
from
hendrikmuhs:feature/fib-stats-jobs
Nov 28, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
103 changes: 103 additions & 0 deletions
103
...java/org/elasticsearch/xpack/ml/featureindexbuilder/action/DataFrameJobStateAndStats.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,103 @@ | ||
| /* | ||
| * 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.ml.featureindexbuilder.action; | ||
|
|
||
| import org.elasticsearch.common.ParseField; | ||
| 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.ConstructingObjectParser; | ||
| import org.elasticsearch.common.xcontent.ToXContentObject; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
| import org.elasticsearch.xpack.ml.featureindexbuilder.job.FeatureIndexBuilderJobState; | ||
| import org.elasticsearch.xpack.ml.featureindexbuilder.job.DataFrameIndexerJobStats; | ||
| import org.elasticsearch.xpack.ml.featureindexbuilder.job.FeatureIndexBuilderJob; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| public class DataFrameJobStateAndStats implements Writeable, ToXContentObject { | ||
|
|
||
| public static final ParseField STATE_FIELD = new ParseField("state"); | ||
| public static final ParseField STATS_FIELD = new ParseField("stats"); | ||
|
|
||
| private final String id; | ||
| private final FeatureIndexBuilderJobState jobState; | ||
| private final DataFrameIndexerJobStats jobStats; | ||
|
|
||
| public static final ConstructingObjectParser<DataFrameJobStateAndStats, Void> PARSER = new ConstructingObjectParser<>( | ||
| GetDataFrameJobsAction.NAME, | ||
| a -> new DataFrameJobStateAndStats((String) a[0], (FeatureIndexBuilderJobState) a[1], (DataFrameIndexerJobStats) a[2])); | ||
|
|
||
| static { | ||
| PARSER.declareString(ConstructingObjectParser.constructorArg(), FeatureIndexBuilderJob.ID); | ||
| PARSER.declareObject(ConstructingObjectParser.constructorArg(), FeatureIndexBuilderJobState.PARSER::apply, STATE_FIELD); | ||
| PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> DataFrameIndexerJobStats.fromXContent(p), STATS_FIELD); | ||
| } | ||
|
|
||
| public DataFrameJobStateAndStats(String id, FeatureIndexBuilderJobState state, DataFrameIndexerJobStats stats) { | ||
| this.id = Objects.requireNonNull(id); | ||
| this.jobState = Objects.requireNonNull(state); | ||
| this.jobStats = Objects.requireNonNull(stats); | ||
| } | ||
|
|
||
| public DataFrameJobStateAndStats(StreamInput in) throws IOException { | ||
| this.id = in.readString(); | ||
| this.jobState = new FeatureIndexBuilderJobState(in); | ||
| this.jobStats = new DataFrameIndexerJobStats(in); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.field(FeatureIndexBuilderJob.ID.getPreferredName(), id); | ||
| builder.field(STATE_FIELD.getPreferredName(), jobState); | ||
| builder.field(STATS_FIELD.getPreferredName(), jobStats); | ||
| builder.endObject(); | ||
| return builder; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeString(id); | ||
| jobState.writeTo(out); | ||
| jobStats.writeTo(out); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(id, jobState, jobStats); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object other) { | ||
| if (this == other) { | ||
| return true; | ||
| } | ||
|
|
||
| if (other == null || getClass() != other.getClass()) { | ||
| return false; | ||
| } | ||
|
|
||
| DataFrameJobStateAndStats that = (DataFrameJobStateAndStats) other; | ||
|
|
||
| return Objects.equals(this.id, that.id) && Objects.equals(this.jobState, that.jobState) | ||
| && Objects.equals(this.jobStats, that.jobStats); | ||
| } | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public DataFrameIndexerJobStats getJobStats() { | ||
| return jobStats; | ||
| } | ||
|
|
||
| public FeatureIndexBuilderJobState getJobState() { | ||
| return jobState; | ||
| } | ||
| } |
198 changes: 198 additions & 0 deletions
198
...va/org/elasticsearch/xpack/ml/featureindexbuilder/action/GetDataFrameJobsStatsAction.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,198 @@ | ||
| /* | ||
| * 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.ml.featureindexbuilder.action; | ||
|
|
||
| import org.elasticsearch.action.Action; | ||
| import org.elasticsearch.action.ActionRequestBuilder; | ||
| import org.elasticsearch.action.ActionRequestValidationException; | ||
| import org.elasticsearch.action.FailedNodeException; | ||
| import org.elasticsearch.action.TaskOperationFailure; | ||
| import org.elasticsearch.action.support.tasks.BaseTasksRequest; | ||
| import org.elasticsearch.action.support.tasks.BaseTasksResponse; | ||
| import org.elasticsearch.client.ElasticsearchClient; | ||
| import org.elasticsearch.cluster.metadata.MetaData; | ||
| 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.xcontent.XContentBuilder; | ||
| import org.elasticsearch.common.xcontent.ToXContent; | ||
| import org.elasticsearch.common.xcontent.ToXContentObject; | ||
| import org.elasticsearch.tasks.Task; | ||
| import org.elasticsearch.xpack.ml.featureindexbuilder.job.FeatureIndexBuilderJob; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| public class GetDataFrameJobsStatsAction extends Action<GetDataFrameJobsStatsAction.Response> { | ||
|
|
||
| public static final GetDataFrameJobsStatsAction INSTANCE = new GetDataFrameJobsStatsAction(); | ||
| public static final String NAME = "cluster:monitor/data_frame_stats/get"; | ||
| public static final ParseField COUNT = new ParseField("count"); | ||
| public static final ParseField JOBS = new ParseField("jobs"); | ||
|
|
||
| public GetDataFrameJobsStatsAction() { | ||
| super(NAME); | ||
| } | ||
|
|
||
| @Override | ||
| public Response newResponse() { | ||
| return new Response(); | ||
| } | ||
|
|
||
| public static class Request extends BaseTasksRequest<Request> implements ToXContent { | ||
| private String id; | ||
|
|
||
| public Request(String id) { | ||
| if (Strings.isNullOrEmpty(id) || id.equals("*")) { | ||
| this.id = MetaData.ALL; | ||
| } else { | ||
| this.id = id; | ||
| } | ||
| } | ||
|
|
||
| public Request() {} | ||
|
|
||
| @Override | ||
| public boolean match(Task task) { | ||
| // If we are retrieving all the jobs, the task description does not contain the id | ||
| if (id.equals(MetaData.ALL)) { | ||
| return task.getDescription().startsWith(FeatureIndexBuilderJob.PERSISTENT_TASK_DESCRIPTION_PREFIX); | ||
| } | ||
| // Otherwise find the task by ID | ||
| return task.getDescription().equals(FeatureIndexBuilderJob.PERSISTENT_TASK_DESCRIPTION_PREFIX + id); | ||
| } | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| @Override | ||
| public void readFrom(StreamInput in) throws IOException { | ||
| super.readFrom(in); | ||
| id = in.readString(); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| super.writeTo(out); | ||
| out.writeString(id); | ||
| } | ||
|
|
||
| @Override | ||
| public ActionRequestValidationException validate() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.field(FeatureIndexBuilderJob.ID.getPreferredName(), id); | ||
| return builder; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(id); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (obj == null) { | ||
| return false; | ||
| } | ||
| if (getClass() != obj.getClass()) { | ||
| return false; | ||
| } | ||
| Request other = (Request) obj; | ||
| return Objects.equals(id, other.id); | ||
| } | ||
| } | ||
|
|
||
| public static class RequestBuilder extends ActionRequestBuilder<Request, Response> { | ||
|
|
||
| protected RequestBuilder(ElasticsearchClient client, GetDataFrameJobsStatsAction action) { | ||
| super(client, action, new Request()); | ||
| } | ||
| } | ||
|
|
||
| public static class Response extends BaseTasksResponse implements Writeable, ToXContentObject { | ||
| private List<DataFrameJobStateAndStats> jobsStateAndStats; | ||
|
|
||
| public Response(List<DataFrameJobStateAndStats> jobsStateAndStats) { | ||
| super(Collections.emptyList(), Collections.emptyList()); | ||
| this.jobsStateAndStats = jobsStateAndStats; | ||
| } | ||
|
|
||
| public Response(List<DataFrameJobStateAndStats> jobsStateAndStats, List<TaskOperationFailure> taskFailures, | ||
| List<? extends FailedNodeException> nodeFailures) { | ||
| super(taskFailures, nodeFailures); | ||
| this.jobsStateAndStats = jobsStateAndStats; | ||
| } | ||
|
|
||
| public Response() { | ||
| super(Collections.emptyList(), Collections.emptyList()); | ||
|
||
| this.jobsStateAndStats = Collections.emptyList(); | ||
| } | ||
|
|
||
| public Response(StreamInput in) throws IOException { | ||
| super(Collections.emptyList(), Collections.emptyList()); | ||
| readFrom(in); | ||
| } | ||
|
|
||
| public List<DataFrameJobStateAndStats> getJobsStateAndStats() { | ||
| return jobsStateAndStats; | ||
| } | ||
|
|
||
| @Override | ||
| public void readFrom(StreamInput in) throws IOException { | ||
| super.readFrom(in); | ||
| jobsStateAndStats = in.readList(DataFrameJobStateAndStats::new); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| super.writeTo(out); | ||
| out.writeList(jobsStateAndStats); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.field(COUNT.getPreferredName(), jobsStateAndStats.size()); | ||
| builder.field(JOBS.getPreferredName(), jobsStateAndStats); | ||
| builder.endObject(); | ||
| return builder; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(jobsStateAndStats); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object other) { | ||
| if (this == other) { | ||
| return true; | ||
| } | ||
|
|
||
| if (other == null || getClass() != other.getClass()) { | ||
| return false; | ||
| } | ||
|
|
||
| final Response that = (Response) other; | ||
| return Objects.equals(this.jobsStateAndStats, that.jobsStateAndStats); | ||
| } | ||
|
|
||
| @Override | ||
| public final String toString() { | ||
| return Strings.toString(this); | ||
| } | ||
| } | ||
| } | ||
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
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.
For anomaly detection, the equivalent action is called
GetJobStatsActionwhere job is singular. We might want to be consistent but I don't feel strongly about it.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.
Discussed this with @droberts195 on a previous PR and we went all for plural, all the endpoint have changed to
.../jobs/{id}/...GetDataFrameJobchanged toGetDataFrameJobs, etc.Anyway, it's a good point and I suggest to keep it as is for now but have a session about naming where we can go over all endpoints and then do a renaming PR.
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.
The ML actions are inconsistent in this respect: we have
GetJobsStatsActionandGetDatafeedsStatsActionbutGetJobStatsActionRequestandRestGetJobStatsAction. I think plural is correct.