Skip to content

[ML] fix empty body on post issue for datafeed _preview #73205

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
merged 2 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
Expand Down Expand Up @@ -53,8 +54,13 @@ public static class Request extends ActionRequest implements ToXContentObject {
PARSER.declareObject(Builder::setJobBuilder, Job.STRICT_PARSER, JOB_CONFIG);
}

public static Request fromXContent(XContentParser parser) {
return PARSER.apply(parser, null).build();
public static Request fromXContent(XContentParser parser, @Nullable String datafeedId) {
Builder builder = PARSER.apply(parser, null);
// We don't need to check for "inconsistent ids" as we don't parse an ID from the body
if (datafeedId != null) {
builder.setDatafeedId(datafeedId);
}
return builder.build();
}

private final String datafeedId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public String getName() {
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
PreviewDatafeedAction.Request request = restRequest.hasContentOrSourceParam() ?
PreviewDatafeedAction.Request.fromXContent(restRequest.contentOrSourceParamParser()) :
PreviewDatafeedAction.Request.fromXContent(
restRequest.contentOrSourceParamParser(),
restRequest.param(DatafeedConfig.ID.getPreferredName(), null)
) :
new PreviewDatafeedAction.Request(restRequest.param(DatafeedConfig.ID.getPreferredName()));
return channel -> client.execute(PreviewDatafeedAction.INSTANCE, request, new RestToXContentListener<>(channel));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ setup:
- match: { 3.airline: foo }
- match: { 3.responsetime: 42.0 }

- do:
ml.preview_datafeed:
datafeed_id: preview-datafeed-feed
body: >
{}
- length: { $body: 4 }
- match: { 0.time: 1487376000000 }
- match: { 0.airline: foo }
- match: { 0.responsetime: 1.0 }
- match: { 1.time: 1487377800000 }
- match: { 1.airline: foo }
- match: { 1.responsetime: 1.0 }
- match: { 2.time: 1487379600000 }
- match: { 2.airline: bar }
- match: { 2.responsetime: 42.0 }
- match: { 3.time: 1487379660000 }
- match: { 3.airline: foo }
- match: { 3.responsetime: 42.0 }

- do:
ml.preview_datafeed:
body: >
Expand Down