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] Add indices_options to datafeed config and update #52793

Merged

Conversation

benwtrent
Copy link
Member

This adds a new configurable field called indices_options. This allows users to create or update the indices_options used when a datafeed reads from an index.

This is necessary for the following use cases:

  • Reading from frozen indices
  • Allowing certain indices in multiple index patterns to not exist yet

These index options are available on datafeed creation and update. Users may specify them as URL parameters or within the configuration object.

closes #48056

@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core (:ml)

Copy link
Contributor

@dimitris-athanasiou dimitris-athanasiou left a comment

Choose a reason for hiding this comment

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

Looks good! My only confusion has to do with handling default options when it is not set. In particular, it seems we used to have 2 different defaults in different places: IndicesOptions.lenientExpandOpen() and SearchRequest.DEFAULT_INDICES_OPTIONS, which is IndicesOptions.strictExpandOpenAndForbidClosedIgnoreThrottled().

With this change defaults will remain the same when there are no options set. But if a user sets options explicitly, we use SearchRequest.DEFAULT_INDICES_OPTIONS as the default options. This is the part that confuses me.

@@ -44,8 +46,15 @@ public String getName() {
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
String datafeedId = restRequest.param(DatafeedConfig.ID.getPreferredName());
IndicesOptions indicesOptions = null;
if (restRequest.hasParam("expand_wildcards")
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we avoid checking if restRequest has those params? I think it'd work to do IndicesOptions indicesOptions = IndicesOptions.fromRequest(restRequest, SearchRequest.DEFAULT_INDICES_OPTIONS)

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. DatafeedConfig can make the options non-null and default to SearchRequestt.DEFAULT_INDICES_OPTIONS

@@ -44,8 +46,15 @@ public String getName() {
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
String datafeedId = restRequest.param(DatafeedConfig.ID.getPreferredName());
IndicesOptions indicesOptions = null;
if (restRequest.hasParam("expand_wildcards")
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't agree. If none are provided, then that means the user doesn't want to update them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yes. That's the update. My bad!

@droberts195
Copy link
Contributor

it seems we used to have 2 different defaults in different places: IndicesOptions.lenientExpandOpen() and SearchRequest.DEFAULT_INDICES_OPTIONS, which is IndicesOptions.strictExpandOpenAndForbidClosedIgnoreThrottled().

It seems that this was a bug before, and it didn't really matter in the days before frozen indices but frozen indices mean it could cause weird behaviour.

We discussed this a bit in a different channel and the outcome was:

  1. We should use the same default in both places, and that default should be SearchRequest.DEFAULT_INDICES_OPTIONS
  2. As a result of this, the indicesOptions member of DatafeedConfig can be made @NotNull and defaulted to SearchRequest.DEFAULT_INDICES_OPTIONS at an earlier stage - this will reduce the number of null checks required downstream
  3. We have an extra check for no concrete indices in addition to the indices options check:
    if (concreteIndices.length == 0) {
    return new AssignmentFailure(reason, true);
    }

Currently that sets the same assignment failure reason as an exception from the indices options check sets, and this could lead to confusion if indices options include allow_no_indices. So the reason returned on line 126 of current master/line 128 of commit 1 on this PR should be made different to the reason returned on line 130 of current master/line 132 of commit 1 on this PR. The current reason is most suited to the if (concreteIndices.length == 0) check and the new reason for the resolver throwing should include the toString() representation of the caught exception so that it reflects the problem given the configured indices options.

Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@dimitris-athanasiou dimitris-athanasiou left a comment

Choose a reason for hiding this comment

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

LGTM2

@benwtrent benwtrent merged commit d7a6333 into elastic:master Feb 27, 2020
@benwtrent benwtrent deleted the feature/ml-datafeed-add-indices_options branch February 27, 2020 17:22
benwtrent added a commit to benwtrent/elasticsearch that referenced this pull request Feb 27, 2020
This adds a new configurable field called `indices_options`. This allows users to create or update the indices_options used when a datafeed reads from an index.

This is necessary for the following use cases:
 - Reading from frozen indices
 - Allowing certain indices in multiple index patterns to not exist yet

These index options are available on datafeed creation and update. Users may specify them as URL parameters or within the configuration object.

closes elastic#48056
benwtrent added a commit that referenced this pull request Feb 27, 2020
This adds a new configurable field called `indices_options`. This allows users to create or update the indices_options used when a datafeed reads from an index.

This is necessary for the following use cases:
 - Reading from frozen indices
 - Allowing certain indices in multiple index patterns to not exist yet

These index options are available on datafeed creation and update. Users may specify them as URL parameters or within the configuration object.

closes #48056
benwtrent added a commit that referenced this pull request Feb 28, 2020
Re-enables bwc tests and fixes up code after backport of #52793
@jakelandis jakelandis removed the v8.0.0 label Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ML] Allow indices_options parameter for datafeed configuration
5 participants