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

Denormalize actionTypeId into alert actions for easier filtering #51628

Merged
merged 13 commits into from
Dec 10, 2019

Conversation

mikecote
Copy link
Contributor

@mikecote mikecote commented Nov 25, 2019

Alerts UI will need a filter on action types (ex: show me alerts that send emails). In order to do this, it's better to denormalize the actionTypeId field within alert actions than it would be to load all the actions that use a certain action type and then filter by those ids.

In this PR, I'm copying the alertTypeId value to each alert.actions[x] object.

Done: Before this merges, we need to make sure saved objects KQL will work with this (#51637). So far encountering an error like This key 'actionTypeId' need to be wrapped by a saved object type like alert:.

@mikecote mikecote self-assigned this Nov 25, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-services (Team:Stack Services)

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mikecote mikecote marked this pull request as ready for review December 4, 2019 19:01
@mikecote mikecote requested review from a team, pmuellr and gmmorris December 4, 2019 19:01
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mikecote
Copy link
Contributor Author

mikecote commented Dec 5, 2019

@elasticmachine merge upstream

actions: Array<{
group: string;
id: string;
actionTypeId: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @pmuellr mentioned, APIs (create / update) shouldn't accept actionTypeId and we should add it ourselves while also validating the action.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pmuellr I made the changes for this here: 005d3d9.

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@gmmorris gmmorris left a comment

Choose a reason for hiding this comment

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

Overall LGTM, assuming the validation issue Patrick pointed out is addressed.
Approving as that's the only blocker I can see.

.expect(200);
objectRemover.add(space.id, createdAlert.id, 'alert');

const response = await supertestWithoutAuth
.get(
`${getUrlPrefix(
space.id
)}/api/alert/_find?filter=alert.attributes.alertTypeId:test.noop`
)}/api/alert/_find?filter=alert.attributes.actions:{ actionTypeId: test.noop }`
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have previous examples of JSON being used on query string like this?
This seems non idiomatic, so just wondering what the reason is. 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No examples I can think of, I added this here as we need a test to make sure we can filter on nested ES objects and this will become more common for the alerts list.

Copy link
Member

Choose a reason for hiding this comment

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

This isn't JSON though, is it? It's KQL AFAIK, which happens to look like JSON for nested queries ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it's KQL and not JSON, looks very similar for nested queries.

@mikecote
Copy link
Contributor Author

mikecote commented Dec 6, 2019

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mikecote
Copy link
Contributor Author

mikecote commented Dec 9, 2019

@elasticmachine merge upstream

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

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

LGTM

I took a quick check and didn't see any tests for an alert with multiple actions, that would go through the new denormalizeActions() call. Suggest we add one, maybe in a subsequent PR (create an issue if so), ... or maybe there is one and I missed it. :-)

): Promise<{ actions: RawAlert['actions']; references: SavedObjectReference[] }> {
// Fetch action objects in bulk
const bulkGetOpts = [
...new Set(alertActions.map(alertAction => ({ id: alertAction.id, type: 'action' }))),
Copy link
Member

Choose a reason for hiding this comment

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

TIL you could use an iterable with ... in an array - makes total sense, but I guess I've always thought it had to be an array (in this context).

.expect(200);
objectRemover.add(space.id, createdAlert.id, 'alert');

const response = await supertestWithoutAuth
.get(
`${getUrlPrefix(
space.id
)}/api/alert/_find?filter=alert.attributes.alertTypeId:test.noop`
)}/api/alert/_find?filter=alert.attributes.actions:{ actionTypeId: test.noop }`
Copy link
Member

Choose a reason for hiding this comment

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

This isn't JSON though, is it? It's KQL AFAIK, which happens to look like JSON for nested queries ...

@mikecote
Copy link
Contributor Author

mikecote commented Dec 9, 2019

@pmuellr I went ahead and added tests for denormalizeActions within this commit: 1211ad1.

@mikecote
Copy link
Contributor Author

mikecote commented Dec 9, 2019

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@mikecote mikecote merged commit ca5f6d7 into elastic:master Dec 10, 2019
mikecote added a commit to mikecote/kibana that referenced this pull request Dec 10, 2019
…stic#51628)

* Denormalize actionTypeId for easier filtering of alerts

* Add tests

* No longer pass actionTypeId for each alert action in APIs

* Add tests to ensure denormalizeActions works on multiple actions

* Fix ESLint errors
mikecote added a commit that referenced this pull request Dec 10, 2019
) (#52588)

* Denormalize actionTypeId for easier filtering of alerts

* Add tests

* No longer pass actionTypeId for each alert action in APIs

* Add tests to ensure denormalizeActions works on multiple actions

* Fix ESLint errors
timductive pushed a commit to timductive/kibana that referenced this pull request Dec 16, 2019
…stic#51628)

* Denormalize actionTypeId for easier filtering of alerts

* Add tests

* No longer pass actionTypeId for each alert action in APIs

* Add tests to ensure denormalizeActions works on multiple actions

* Fix ESLint errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants