-
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
HLRC: Adding ML Job stats #33183
HLRC: Adding ML Job stats #33183
Changes from 12 commits
e2d0daa
cefe9d3
8a7feb4
f55e01e
cc602fe
de52ab2
54d56a7
c8d3f5a
da0c1bd
5254cc1
55f543d
79dd816
9f2bc9e
a6512a4
2c9e231
b761884
a45fbec
fdf2aa0
401223b
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 |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.client.ml; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.ObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
|
||
/** | ||
* Request object to get {@link org.elasticsearch.client.ml.job.stats.JobStats} objects with the matching `jobId`s | ||
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.
|
||
* | ||
* `_all` explicitly gets all the jobs' statistics in the cluster | ||
* An empty request (no `jobId`s) implicitly gets all the jobs' statistics in the cluster | ||
*/ | ||
public class GetJobsStatsRequest extends ActionRequest implements ToXContentObject { | ||
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 name of this and the |
||
|
||
public static final ParseField JOB_ID = new ParseField("job_id"); | ||
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. reuse |
||
public static final ParseField ALLOW_NO_JOBS = new ParseField("allow_no_jobs"); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<GetJobsStatsRequest, Void> PARSER = new ConstructingObjectParser<>( | ||
"get_jobs_stats_request", | ||
true, a -> new GetJobsStatsRequest((List<String>) a[0])); | ||
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. We shouldn't support unknown fields in the request objects, only the response. You can use the constructor that skips this argument all together. |
||
|
||
static { | ||
PARSER.declareField(ConstructingObjectParser.constructorArg(), | ||
p -> Arrays.asList(Strings.commaDelimitedListToStringArray(p.text())), | ||
JOB_ID, ObjectParser.ValueType.STRING_ARRAY); | ||
PARSER.declareBoolean(GetJobsStatsRequest::setAllowNoJobs, ALLOW_NO_JOBS); | ||
} | ||
|
||
private static final String ALL_JOBS = "_all"; | ||
|
||
private final List<String> jobIds; | ||
private Boolean allowNoJobs; | ||
|
||
/** | ||
* Explicitly gets all jobs statistics | ||
* | ||
* @return a {@link GetJobsStatsRequest} for all existing jobs | ||
*/ | ||
public static GetJobsStatsRequest allJobsStats(){ | ||
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. make consistent with the equivalent in other requests: |
||
return new GetJobsStatsRequest(ALL_JOBS); | ||
} | ||
|
||
GetJobsStatsRequest(List<String> jobIds) { | ||
if (jobIds.stream().anyMatch(Objects::isNull)) { | ||
throw new NullPointerException("jobIds must not contain null values"); | ||
} | ||
this.jobIds = new ArrayList<>(jobIds); | ||
} | ||
|
||
/** | ||
* Get the specified Job's statistics via their unique jobIds | ||
* | ||
* @param jobIds must be non-null and each jobId must be non-null | ||
*/ | ||
public GetJobsStatsRequest(String... jobIds) { | ||
this(Arrays.asList(jobIds)); | ||
} | ||
|
||
/** | ||
* All the jobIds for which to get statistics | ||
*/ | ||
public List<String> getJobIds() { | ||
return jobIds; | ||
} | ||
|
||
public Boolean isAllowNoJobs() { | ||
return this.allowNoJobs; | ||
} | ||
|
||
/** | ||
* Whether to ignore if a wildcard expression matches no jobs. | ||
* | ||
* This includes `_all` string or when no jobs have been specified | ||
* | ||
* @param allowNoJobs When {@code true} ignore if wildcard or `_all` matches no jobs. Defaults to {@code true} | ||
*/ | ||
public void setAllowNoJobs(boolean allowNoJobs) { | ||
this.allowNoJobs = allowNoJobs; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(jobIds, allowNoJobs); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
GetJobsStatsRequest that = (GetJobsStatsRequest) other; | ||
return Objects.equals(jobIds, that.jobIds) && | ||
Objects.equals(allowNoJobs, that.allowNoJobs); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(JOB_ID.getPreferredName(), Strings.collectionToCommaDelimitedString(jobIds)); | ||
if (allowNoJobs != null) { | ||
builder.field(ALLOW_NO_JOBS.getPreferredName(), allowNoJobs); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.client.ml; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.client.ml.job.stats.JobStats; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
||
/** | ||
* Contains a {@link List} of the found {@link JobStats} objects and the total count found | ||
*/ | ||
public class GetJobsStatsResponse extends AbstractResultResponse<JobStats> { | ||
|
||
public static final ParseField RESULTS_FIELD = new ParseField("jobs"); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<GetJobsStatsResponse, Void> PARSER = | ||
new ConstructingObjectParser<>("jobs_stats_response", true, | ||
a -> new GetJobsStatsResponse((List<JobStats>) a[0], (long) a[1])); | ||
|
||
static { | ||
PARSER.declareObjectArray(constructorArg(), JobStats.PARSER, RESULTS_FIELD); | ||
PARSER.declareLong(constructorArg(), COUNT); | ||
} | ||
|
||
GetJobsStatsResponse(List<JobStats> jobStats, long count) { | ||
super(RESULTS_FIELD, jobStats, count); | ||
} | ||
|
||
/** | ||
* The collection of {@link JobStats} objects found in the query | ||
*/ | ||
public List<JobStats> jobs() { | ||
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. rename to |
||
return results; | ||
} | ||
|
||
public static GetJobsStatsResponse fromXContent(XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(results, count); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
|
||
GetJobsStatsResponse other = (GetJobsStatsResponse) obj; | ||
return Objects.equals(results, other.results) && count == other.count; | ||
} | ||
|
||
@Override | ||
public final String toString() { | ||
return Strings.toString(this); | ||
} | ||
} |
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.
Rephrase to
Gets usage information for one or more Machine Learning jobs
?