Skip to content
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

[ML] Allow datafeed and job configs for datafeed preview API #70836

Conversation

benwtrent
Copy link
Member

@benwtrent benwtrent commented Mar 24, 2021

Previously, a datafeed and job must already exist for the _preview API to work.

With this change, users can get an accurate preview of the data that will be sent to the anomaly detection job
without creating either of them.

Example:

POST _ml/datafeeds/_preview
{
            "datafeed_config": {
              "indexes":"airline-data"
            },
            "job_config": {
              "analysis_config" : {
                "bucket_span": "1h",
                "detectors" :[{"function":"sum","field_name":"responsetime","by_field_name":"airline"}]
              },
              "data_description" : {
                "time_field":"time"
              }
            }
          }

closes #70264

@elasticmachine elasticmachine added the Team:ML Meta label for the ML team label Mar 24, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

Copy link
Member

@davidkyle davidkyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Nice, I thought this would be a lot more complicated

@@ -27,6 +30,6 @@ protected PreviewDatafeedRequest doParseInstance(XContentParser parser) throws I

@Override
protected boolean supportsUnknownFields() {
return true;
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ requests parsering shouldn't be lenient. Can you also change the parser in PreviewDatafeedRequest to have ignoreUnknownFields = false

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100%

datafeedBuilder.setJobId("preview_job_id");
}
}
if (jobBuilder != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it valid to have a jobBuilder but no datafeedBuilder a null datafeedId? i.e. just the job config

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it valid to have a jobBuilder but no datafeedBuilder a null datafeedId?

no, it isn't. The API MUST have either a datafeedBuilder or a datafeedId. The restrictive ctors ensure this (with null checks).

listener::onFailure
);
if (request.getDatafeedConfig() != null) {
datafeedConfigActionListener.onResponse(request.getDatafeedConfig());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if I'd known it was that simple...

@@ -35,8 +39,10 @@ public String getName() {

@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
String datafeedId = restRequest.param(DatafeedConfig.ID.getPreferredName());
PreviewDatafeedAction.Request request = new PreviewDatafeedAction.Request(datafeedId);
String datafeedId = restRequest.param(DatafeedConfig.ID.getPreferredName(), null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defaultValue of null is unnecessary but I prefer this usage it makes the intent more explicit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, I will only grab this param if hasContent is false. Also, I won't provide a default value that way it blows up expecting it.

@benwtrent
Copy link
Member Author

run elasticsearch-ci/bwc

@benwtrent
Copy link
Member Author

run elasticsearch-ci/2

@benwtrent
Copy link
Member Author

@elasticmachine update branch

@benwtrent benwtrent merged commit b796632 into elastic:master Mar 26, 2021
@benwtrent benwtrent deleted the feature/ml-allow-configs-in-datafeed-preview branch March 26, 2021 16:52
benwtrent added a commit to benwtrent/elasticsearch that referenced this pull request Mar 26, 2021
…#70836)

Previously, a datafeed and job must already exist for the `_preview` API to work.

With this change, users can get an accurate preview of the data that will be sent to the anomaly detection job
without creating either of them.

closes elastic#70264
benwtrent added a commit that referenced this pull request Mar 26, 2021
…#70927)

Previously, a datafeed and job must already exist for the `_preview` API to work.

With this change, users can get an accurate preview of the data that will be sent to the anomaly detection job
without creating either of them.

closes #70264
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :ml Machine learning Team:ML Meta label for the ML team v7.13.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ML] Datafeed _preview should work with configs
5 participants