-
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
Watcher: Allow to execute actions for each element in array #41997
Watcher: Allow to execute actions for each element in array #41997
Conversation
This adds the ability to execute an action for each element that occurs in an array, for example you could sent a dedicated slack action for each search hit returned from a search. Relates elastic#34546
Pinging @elastic/es-core-features |
@spinscale - i am trying to test this and am running into the following error
A slightly modified version of the doc example I am using to test:
|
the documentation stated something different than the implementation by using |
@elasticmachine run test elasticsearch-ci/1 |
I pulled the latest and the error is now gone and executes the action for each hit. However, (using the example above), It is not reading the template field correctly. e.g. results in :
|
indeed. this slipped through the tests as it requires mustache for testing. I'll investigate that one and ping you once I found the issue |
I fixed the notation in the docs how to access fields. You still need to specify
the reason for this, as each action creates the |
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.
Looking good... a couple small points
if (o instanceof Map) { | ||
results.add(action.execute(id, ctx, new Payload.Simple((Map<String, Object>) o))); | ||
} else { | ||
throw new ElasticsearchException("item in foreach [{}] object was not a map", path); |
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.
How difficult is it to remove the requirement of only an array of maps ? I think an array of arrays, or an array of values would be useful.
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.
changed to also be able to pass any object, which then is available in ctx.payload._value
List<Action.Result> results = new ArrayList<>(); | ||
Object object = ObjectPath.eval(path, toMap(ctx)); | ||
if (object instanceof Collection) { | ||
Collection collection = Collection.class.cast(object); |
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.
Can you add an upper limit here ? I am fine with a hard coded 100
size (or something like that) just so that we don't allow this to be a DOS vector.
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.
set it hundred, also included the number of executed actions in the JSON that gets written to watch history
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.
100 seems quite arbitrary from my perspective. Any chance to make this an option?
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.
please open a new issue to make this configurable plus the rationale. The main goal here was to not let the watch run extremely long and block other watch executions, as well as its own executions.
Thank you!
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.
Filed as #45169
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.
LGTM (assuming CI agrees)
Thanks for putting this together, i suspect this will get quite a bit usage. May want to consider adding this a highlight feature for the minor release this lands ?
This adds the ability to execute an action for each element that occurs in an array, for example you could sent a dedicated slack action for each search hit returned from a search. There is also a limit for the number of actions executed, which is hardcoded to 100 right now, to prevent having watches run forever. The watch history logs each action result and the total number of actions the were executed. Relates #34546
This adds the ability to execute an action for each element that occurs
in an array, for example you could sent a dedicated slack action for
each search hit returned from a search.
Relates #34546
Reviewers notes: My intention is to get this into master and 7.x branches, please veto if you disagree. Also, please take a special look at the watch history and that no additional fields are created unintentionally in the history mapping.