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

Adds index action as built-in action #41592

Merged
merged 3 commits into from
Jul 24, 2019

Conversation

pmuellr
Copy link
Member

@pmuellr pmuellr commented Jul 19, 2019

Intended to be functionally equivalent to the watcher index action.

@pmuellr
Copy link
Member Author

pmuellr commented Jul 19, 2019

Currently there is no config for this action, and the params look like this:

const ParamsSchema = schema.object({
  index: schema.string(),
  doc_id: schema.maybe(schema.string()),
  execution_time_field: schema.maybe(schema.string()),
  refresh: schema.maybe(schema.boolean()),
  body: IndexBodySchema,
});

body can be a single object or an array of objects. I think the ultimate "result" from the action would be an array of results for each doc indexed; so if you pass a single doc, you'd get an array of length one as part of the result.

It seems like having index be a config parm would be nice. That way you could create an action and either have it default or force the index value, preventing various sorts of errors when executing the action where the index isn't what you're expecting (eg, typo). OTOH, perhaps this would be a pain-in-the-rear for folks creating actions programmatically, writing to multiple indices, as they would need to create an action per index. And ... guessing this particular action is going to be more of a programmatic use case, compared to user-facing actions like slack and email.

So, thinking we could make index an optional config property; if set to a value, that value would be used by all executions of the action. If not set, the index would have to be set in the params. If both are used, the params value would be ignored - perhaps logging this would be appropriate?

This would be the first case of having an execution property being set by config | params, which is something we will likely see again.

@spalger
Copy link
Contributor

spalger commented Jul 19, 2019

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@pmuellr pmuellr force-pushed the actions/add-index-action branch from aca712d to 685bc6b Compare July 20, 2019 00:56
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@pmuellr pmuellr force-pushed the actions/add-index-action branch from e47a543 to c34650b Compare July 22, 2019 20:54
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-services

@pmuellr pmuellr requested a review from mikecote July 22, 2019 20:55
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@pmuellr pmuellr marked this pull request as ready for review July 23, 2019 03:01
@pmuellr pmuellr requested a review from a team July 23, 2019 03:01
@pmuellr
Copy link
Member Author

pmuellr commented Jul 23, 2019

fixes #40027

Copy link
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

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

Just one small comment but everything else looks good.

x-pack/legacy/plugins/actions/README.md Show resolved Hide resolved
Copy link
Contributor

@bmcconaghy bmcconaghy left a comment

Choose a reason for hiding this comment

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

Looking good, just a couple of things need to get addressed (localization most importantly).

x-pack/legacy/plugins/actions/README.md Show resolved Hide resolved
type IndexArrayBodySchemaType = TypeOf<typeof IndexArrayBodySchema>;

// see: https://www.elastic.co/guide/en/elastic-stack-overview/current/actions-index.html
// - timeout not added here, as this seems to be a generic thing we want to do
Copy link
Contributor

Choose a reason for hiding this comment

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

wondering if we do want to add timeout here, as you might want to have that value be different from whatever would be set globally.

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 have a card open for this - https://github.com/elastic/kibana/projects/26#card-24087404

Yeah, I think we will probably want a global timeout, and then allow an action type to override. Then the next question is, how can a user change these? env var or kibana yaml config or ...

We could get more elaborate, allow timeout per action, but I don't think we need to go there just yet ...

doc_id: schema.maybe(schema.string()),
execution_time_field: schema.maybe(schema.string()),
refresh: schema.maybe(schema.boolean()),
body: IndexBodySchema,
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like we are also missing refresh and transform from the options that watcher index action supports. Thinking that body isn't the best name for this param, maybe document instead? Also thinking that we should make this always an array, to make it more obvious that you can pass multiples here.

Copy link
Member Author

Choose a reason for hiding this comment

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

documents sounds good, as does always making it an array; that means doc_id would go away, as that was only applicable to the single document case.

refresh is already there. transform isn't, because I figured transform was a general watcher thing, perhaps not appropriate for Kibana. Guessing that if we want it here, we want it as a general capability for all actions. And to some extent, this may intersect with the thought of using templates to generate action parameters. And maybe what we want in the end is to use "expressions" to handle all this jazz. Expressions being the kind of "painless" of Kibana (in terms of a general transformer thing, and it's ubiquity) ...

Copy link
Member Author

Choose a reason for hiding this comment

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

@bmcconaghy so ... whatcha thinking on transform? Even though I think it's possible it could be a general thing for actions, perhaps it's really most appropriate for the index action, since that one deal in fairly arbitrary JSON-able objects, vs the other actions which have less arbitrary params and are more "notification"-y vs "update the db"-y.

Perhaps some research is required to see how people are using it today with watcher, come up with a use case for using it today?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah don't really know how it is used today. I suppose that the alert that was going to trigger this action could do its own transformation, so maybe it's not necessary. Just was looking to see if we were at watcher parity and noticed this.

@@ -49,7 +50,7 @@ async function executor(execOptions: ActionTypeExecutorOptions): Promise<ActionT
} catch (err) {
return {
status: 'error',
message: `error logging message: ${err.message}`,
message: `error in action ${id} logging message: ${err.message}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

This and all strings returned from API calls should be localized.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably localization should be a separate PR - created a card for that - https://github.com/elastic/kibana/projects/26#card-24316443

- moved `nullableType` to a module so it can be reused across action types
- changed index action param `body` to `documents`, and it's no longer an
  object or array, it's only an array
- rename index action param `execution_time_field` to `executionTimeField`
- remove index action param `doc_id` as it's no longer relevant (only useful
  in the single document story previously)
Copy link
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

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

LGTM for my comments 👍

Copy link
Contributor

@bmcconaghy bmcconaghy left a comment

Choose a reason for hiding this comment

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

Code LGTM.

@mikecote
Copy link
Contributor

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@pmuellr
Copy link
Member Author

pmuellr commented Jul 24, 2019

The X-Pack firefox smoke test failure is fixed in master (from some other PR, not this one), so will merge master ...

@elasticmachine
Copy link
Contributor

💔 Build Failed

@pmuellr
Copy link
Member Author

pmuellr commented Jul 24, 2019

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@pmuellr pmuellr merged commit ab6aca2 into elastic:master Jul 24, 2019
pmuellr added a commit to pmuellr/kibana that referenced this pull request Jul 24, 2019
* Adds index action as built-in action

* resolve PR comments

- moved `nullableType` to a module so it can be reused across action types
- changed index action param `body` to `documents`, and it's no longer an
  object or array, it's only an array
- rename index action param `execution_time_field` to `executionTimeField`
- remove index action param `doc_id` as it's no longer relevant (only useful
  in the single document story previously)
pmuellr added a commit that referenced this pull request Jul 24, 2019
* Adds index action as built-in action

* resolve PR comments

- moved `nullableType` to a module so it can be reused across action types
- changed index action param `body` to `documents`, and it's no longer an
  object or array, it's only an array
- rename index action param `execution_time_field` to `executionTimeField`
- remove index action param `doc_id` as it's no longer relevant (only useful
  in the single document story previously)
@pmuellr pmuellr deleted the actions/add-index-action branch July 30, 2019 18:38
@njd5475 njd5475 mentioned this pull request Sep 13, 2019
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants