Skip to content

Commit

Permalink
[ML] adding new flag exclude_generated that removes generated fields …
Browse files Browse the repository at this point in the history
…in GET config APIs (#63899)

When exporting and cloning ml configurations in a cluster it can be
frustrating to remove all the fields that were generated by
the plugin. Especially as the number of these fields change
from version to version.

This flag, exclude_generated, allows the GET config APIs to return
configurations with these generated fields removed.

APIs supporting this flag: 
- GET _ml/anomaly_detection/<job_id>
- GET _ml/datafeeds/<datafeed_id>
- GET _ml/data_frame/analytics/<analytics_id>

The following fields are not returned in the objects:

- any field that is not user settable (e.g. version, create_time)
- any field that is a calculated default value (e.g. datafeed chunking_config)
- any field that is automatically set via another Elastic stack process (e.g. anomaly job custom_settings.created_by)

relates to #63055
  • Loading branch information
benwtrent committed Oct 20, 2020
1 parent 658acdb commit c1de07f
Show file tree
Hide file tree
Showing 30 changed files with 146 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ static Request getJob(GetJobRequest getJobRequest) {
if (getJobRequest.getAllowNoMatch() != null) {
params.putParam(GetJobRequest.ALLOW_NO_MATCH.getPreferredName(), Boolean.toString(getJobRequest.getAllowNoMatch()));
}
if (getJobRequest.getForExport() != null) {
params.putParam(GetJobRequest.FOR_EXPORT, Boolean.toString(getJobRequest.getForExport()));
if (getJobRequest.getExcludeGenerated() != null) {
params.putParam(GetJobRequest.EXCLUDE_GENERATED, Boolean.toString(getJobRequest.getExcludeGenerated()));
}
request.addParameters(params.asMap());
return request;
Expand Down Expand Up @@ -273,8 +273,8 @@ static Request getDatafeed(GetDatafeedRequest getDatafeedRequest) {
params.putParam(GetDatafeedRequest.ALLOW_NO_MATCH.getPreferredName(),
Boolean.toString(getDatafeedRequest.getAllowNoMatch()));
}
if (getDatafeedRequest.getForExport() != null) {
params.putParam(GetDatafeedRequest.FOR_EXPORT, Boolean.toString(getDatafeedRequest.getForExport()));
if (getDatafeedRequest.getExcludeGenerated() != null) {
params.putParam(GetDatafeedRequest.EXCLUDE_GENERATED, Boolean.toString(getDatafeedRequest.getExcludeGenerated()));
}
request.addParameters(params.asMap());
return request;
Expand Down Expand Up @@ -653,8 +653,8 @@ static Request getDataFrameAnalytics(GetDataFrameAnalyticsRequest getRequest) {
if (getRequest.getAllowNoMatch() != null) {
params.putParam(GetDataFrameAnalyticsRequest.ALLOW_NO_MATCH, Boolean.toString(getRequest.getAllowNoMatch()));
}
if (getRequest.getForExport() != null) {
params.putParam(GetDataFrameAnalyticsRequest.FOR_EXPORT, Boolean.toString(getRequest.getForExport()));
if (getRequest.getExcludeGenerated() != null) {
params.putParam(GetDataFrameAnalyticsRequest.EXCLUDE_GENERATED, Boolean.toString(getRequest.getExcludeGenerated()));
}
request.addParameters(params.asMap());
return request;
Expand Down Expand Up @@ -795,8 +795,8 @@ static Request getTrainedModels(GetTrainedModelsRequest getTrainedModelsRequest)
if (getTrainedModelsRequest.getTags() != null) {
params.putParam(GetTrainedModelsRequest.TAGS, Strings.collectionToCommaDelimitedString(getTrainedModelsRequest.getTags()));
}
if (getTrainedModelsRequest.getForExport() != null) {
params.putParam(GetTrainedModelsRequest.FOR_EXPORT, Boolean.toString(getTrainedModelsRequest.getForExport()));
if (getTrainedModelsRequest.getExcludeGenerated() != null) {
params.putParam(GetTrainedModelsRequest.EXCLUDE_GENERATED, Boolean.toString(getTrainedModelsRequest.getExcludeGenerated()));
}
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
request.addParameters(params.asMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
public class GetDataFrameAnalyticsRequest implements Validatable {

public static final String ALLOW_NO_MATCH = "allow_no_match";
public static final String FOR_EXPORT = "for_export";
public static final String EXCLUDE_GENERATED = "exclude_generated";

private final List<String> ids;
private Boolean allowNoMatch;
private PageParams pageParams;
private Boolean forExport;
private Boolean excludeGenerated;

/**
* Helper method to create a request that will get ALL Data Frame Analytics
Expand Down Expand Up @@ -65,14 +65,14 @@ public Boolean getAllowNoMatch() {
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param forExport Boolean value indicating if certain fields should be removed
* @param excludeGenerated Boolean value indicating if certain fields should be removed
*/
public void setForExport(boolean forExport) {
this.forExport = forExport;
public void setExcludeGenerated(boolean excludeGenerated) {
this.excludeGenerated = excludeGenerated;
}

public Boolean getForExport() {
return forExport;
public Boolean getExcludeGenerated() {
return excludeGenerated;
}

/**
Expand Down Expand Up @@ -111,12 +111,12 @@ public boolean equals(Object o) {
GetDataFrameAnalyticsRequest other = (GetDataFrameAnalyticsRequest) o;
return Objects.equals(ids, other.ids)
&& Objects.equals(allowNoMatch, other.allowNoMatch)
&& Objects.equals(forExport, other.forExport)
&& Objects.equals(excludeGenerated, other.excludeGenerated)
&& Objects.equals(pageParams, other.pageParams);
}

@Override
public int hashCode() {
return Objects.hash(ids, allowNoMatch, forExport, pageParams);
return Objects.hash(ids, allowNoMatch, excludeGenerated, pageParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public class GetDatafeedRequest implements Validatable, ToXContentObject {

public static final ParseField DATAFEED_IDS = new ParseField("datafeed_ids");
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");
public static final String FOR_EXPORT = "for_export";
public static final String EXCLUDE_GENERATED = "exclude_generated";

private static final String ALL_DATAFEEDS = "_all";
private final List<String> datafeedIds;
private Boolean allowNoMatch;
private Boolean forExport;
private Boolean excludeGenerated;

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<GetDatafeedRequest, Void> PARSER = new ConstructingObjectParser<>(
Expand Down Expand Up @@ -108,19 +108,19 @@ public Boolean getAllowNoMatch() {
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param forExport Boolean value indicating if certain fields should be removed
* @param excludeGenerated Boolean value indicating if certain fields should be removed
*/
public void setForExport(boolean forExport) {
this.forExport = forExport;
public void setExcludeGenerated(boolean excludeGenerated) {
this.excludeGenerated = excludeGenerated;
}

public Boolean getForExport() {
return forExport;
public Boolean getExcludeGenerated() {
return excludeGenerated;
}

@Override
public int hashCode() {
return Objects.hash(datafeedIds, forExport, allowNoMatch);
return Objects.hash(datafeedIds, excludeGenerated, allowNoMatch);
}

@Override
Expand All @@ -136,7 +136,7 @@ public boolean equals(Object other) {
GetDatafeedRequest that = (GetDatafeedRequest) other;
return Objects.equals(datafeedIds, that.datafeedIds) &&
Objects.equals(allowNoMatch, that.allowNoMatch) &&
Objects.equals(forExport, that.forExport);
Objects.equals(excludeGenerated, that.excludeGenerated);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public class GetJobRequest implements Validatable, ToXContentObject {

public static final ParseField JOB_IDS = new ParseField("job_ids");
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");
public static final String FOR_EXPORT = "for_export";
public static final String EXCLUDE_GENERATED = "exclude_generated";

private static final String ALL_JOBS = "_all";
private final List<String> jobIds;
private Boolean allowNoMatch;
private Boolean forExport;
private Boolean excludeGenerated;

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<GetJobRequest, Void> PARSER = new ConstructingObjectParser<>(
Expand Down Expand Up @@ -108,19 +108,19 @@ public Boolean getAllowNoMatch() {
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param forExport Boolean value indicating if certain fields should be removed
* @param excludeGenerated Boolean value indicating if certain fields should be removed
*/
public void setForExport(boolean forExport) {
this.forExport = forExport;
public void setExcludeGenerated(boolean excludeGenerated) {
this.excludeGenerated = excludeGenerated;
}

public Boolean getForExport() {
return forExport;
public Boolean getExcludeGenerated() {
return excludeGenerated;
}

@Override
public int hashCode() {
return Objects.hash(jobIds, forExport, allowNoMatch);
return Objects.hash(jobIds, excludeGenerated, allowNoMatch);
}

@Override
Expand All @@ -135,7 +135,7 @@ public boolean equals(Object other) {

GetJobRequest that = (GetJobRequest) other;
return Objects.equals(jobIds, that.jobIds) &&
Objects.equals(forExport, that.forExport) &&
Objects.equals(excludeGenerated, that.excludeGenerated) &&
Objects.equals(allowNoMatch, that.allowNoMatch);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class GetTrainedModelsRequest implements Validatable {
private static final String TOTAL_FEATURE_IMPORTANCE = "total_feature_importance";
private static final String FEATURE_IMPORTANCE_BASELINE = "feature_importance_baseline";
public static final String ALLOW_NO_MATCH = "allow_no_match";
public static final String FOR_EXPORT = "for_export";
public static final String EXCLUDE_GENERATED = "exclude_generated";
public static final String DECOMPRESS_DEFINITION = "decompress_definition";
public static final String TAGS = "tags";
public static final String INCLUDE = "include";
Expand All @@ -48,7 +48,7 @@ public class GetTrainedModelsRequest implements Validatable {
private Boolean allowNoMatch;
private Set<String> includes = new HashSet<>();
private Boolean decompressDefinition;
private Boolean forExport;
private Boolean excludeGenerated;
private PageParams pageParams;
private List<String> tags;

Expand Down Expand Up @@ -163,8 +163,8 @@ public GetTrainedModelsRequest setTags(String... tags) {
return setTags(Arrays.asList(tags));
}

public Boolean getForExport() {
return forExport;
public Boolean getExcludeGenerated() {
return excludeGenerated;
}

/**
Expand All @@ -173,10 +173,10 @@ public Boolean getForExport() {
* This is useful when getting the model and wanting to put it in another cluster.
*
* Default value is false.
* @param forExport Boolean value indicating if certain fields should be removed from the mode on GET
* @param excludeGenerated Boolean value indicating if certain fields should be removed from the mode on GET
*/
public GetTrainedModelsRequest setForExport(Boolean forExport) {
this.forExport = forExport;
public GetTrainedModelsRequest setExcludeGenerated(Boolean excludeGenerated) {
this.excludeGenerated = excludeGenerated;
return this;
}

Expand All @@ -198,12 +198,12 @@ public boolean equals(Object o) {
&& Objects.equals(allowNoMatch, other.allowNoMatch)
&& Objects.equals(decompressDefinition, other.decompressDefinition)
&& Objects.equals(includes, other.includes)
&& Objects.equals(forExport, other.forExport)
&& Objects.equals(excludeGenerated, other.excludeGenerated)
&& Objects.equals(pageParams, other.pageParams);
}

@Override
public int hashCode() {
return Objects.hash(ids, allowNoMatch, pageParams, decompressDefinition, includes, forExport);
return Objects.hash(ids, allowNoMatch, pageParams, decompressDefinition, includes, excludeGenerated);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public void testGetJob() throws Exception {
// tag::get-job-request
GetJobRequest request = new GetJobRequest("get-machine-learning-job1", "get-machine-learning-job*"); // <1>
request.setAllowNoMatch(true); // <2>
request.setForExport(false); // <3>
request.setExcludeGenerated(false); // <3>
// end::get-job-request

// tag::get-job-execute
Expand Down Expand Up @@ -840,7 +840,7 @@ public void testGetDatafeed() throws Exception {
// tag::get-datafeed-request
GetDatafeedRequest request = new GetDatafeedRequest(datafeedId); // <1>
request.setAllowNoMatch(true); // <2>
request.setForExport(false); // <3>
request.setExcludeGenerated(false); // <3>
// end::get-datafeed-request

// tag::get-datafeed-execute
Expand Down Expand Up @@ -2866,7 +2866,7 @@ public void testGetDataFrameAnalytics() throws Exception {
{
// tag::get-data-frame-analytics-request
GetDataFrameAnalyticsRequest request = new GetDataFrameAnalyticsRequest("my-analytics-config"); // <1>
request.setForExport(false); // <2>
request.setExcludeGenerated(false); // <2>
// end::get-data-frame-analytics-request

// tag::get-data-frame-analytics-execute
Expand Down Expand Up @@ -3728,7 +3728,7 @@ public void testGetTrainedModels() throws Exception {
.setDecompressDefinition(false) // <6>
.setAllowNoMatch(true) // <7>
.setTags("regression") // <8>
.setForExport(false); // <9>
.setExcludeGenerated(false); // <9>
// end::get-trained-models-request
request.setTags((List<String>)null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Retrieves configuration information for {dfeeds}.

`GET _ml/datafeeds/` +

`GET _ml/datafeeds/_all`
`GET _ml/datafeeds/_all`

[[ml-get-datafeed-prereqs]]
== {api-prereq-title}
Expand All @@ -36,7 +36,7 @@ comma-separated list of {dfeeds} or a wildcard expression. You can get
information for all {dfeeds} by using `_all`, by specifying `*` as the
`<feed_id>`, or by omitting the `<feed_id>`.

IMPORTANT: This API returns a maximum of 10,000 {dfeeds}.
IMPORTANT: This API returns a maximum of 10,000 {dfeeds}.

[[ml-get-datafeed-path-parms]]
== {api-path-parms-title}
Expand All @@ -57,9 +57,9 @@ all {dfeeds}.
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=allow-no-datafeeds]

`for_export`::
`exclude_generated`::
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=for-export]
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=exclude-generated]

[[ml-get-datafeed-results]]
== {api-response-body-title}
Expand Down
10 changes: 5 additions & 5 deletions docs/reference/ml/anomaly-detection/apis/get-job.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ using a group name, a comma-separated list of jobs, or a wildcard expression.
You can get information for all {anomaly-jobs} by using `_all`, by specifying
`*` as the `<job_id>`, or by omitting the `<job_id>`.

IMPORTANT: This API returns a maximum of 10,000 jobs.
IMPORTANT: This API returns a maximum of 10,000 jobs.

[[ml-get-job-path-parms]]
== {api-path-parms-title}
Expand All @@ -50,9 +50,9 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection-defaul
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=allow-no-jobs]

`for_export`::
`exclude_generated`::
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=for-export]
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=exclude-generated]

[[ml-get-job-results]]
== {api-response-body-title}
Expand All @@ -63,7 +63,7 @@ properties, see <<ml-put-job-request-body,create {anomaly-jobs} API>>.
`create_time`::
(string) The time the job was created. For example, `1491007356077`. This
property is informational; you cannot change its value.

`finished_time`::
(string) If the job closed or failed, this is the time the job finished,
otherwise it is `null`. This property is informational; you cannot change its
Expand All @@ -83,7 +83,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-snapshot-id]
== {api-response-codes-title}

`404` (Missing resources)::
If `allow_no_match` is `false`, this code indicates that there are no
If `allow_no_match` is `false`, this code indicates that there are no
resources that match the request or only partial matches for the request.

[[ml-get-job-example]]
Expand Down

0 comments on commit c1de07f

Please sign in to comment.