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

Create REST API to fire actions #39463

Merged
merged 10 commits into from
Jun 26, 2019
Merged

Conversation

mikecote
Copy link
Contributor

In this PR, we're exposing the fire action function as a REST API.

@mikecote mikecote self-assigned this Jun 21, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-services

@elasticmachine

This comment has been minimized.

@mikecote mikecote marked this pull request as ready for review June 21, 2019 20:07
@mikecote mikecote requested review from a team June 21, 2019 20:07
@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@mikecote

This comment has been minimized.

@elasticmachine

This comment has been minimized.

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 but left some comments

export function fireRoute({ server, actionTypeRegistry, getServices }: FireRouteOptions) {
server.route({
method: 'POST',
path: '/api/action/{id}/_fire',
Copy link
Member

Choose a reason for hiding this comment

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

what does the underscore in _fire mean? Not quite public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a pattern established by Elasticsearch as well as a way to indicate it doesn't correspond to a restful resource.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's used to denote an action on a resource, though ES seems to be trying to move away from this convention. It also disambiguates in some cases, as index names in ES can't start with an underscore.

@@ -64,6 +68,11 @@ export function init(server: Legacy.Server) {
findRoute(server);
updateRoute(server);
listActionTypesRoute(server);
fireRoute({
Copy link
Member

Choose a reason for hiding this comment

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

seems slightly weird that this route takes different params than the others. The others don't need actionTypeRegistry nor getServices? Or was this needed for mocking, perhaps for the "immediate fire" API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah these are functions required by the route (not only for testing). It needs the registry to lookup the action type once loaded from saved objects. And also the getServices to parameterized the execution. This was the only way I was thinking to pass in the singleton instances without exposing anything outside the plugin.

@elasticmachine

This comment has been minimized.

@mikecote

This comment has been minimized.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

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.

LGTM. I had a comment re: changing the name from fire to execute, but if we want to do that it could be done in a separate PR, as it would be a lot of changes.

export function fireRoute({ server, actionTypeRegistry, getServices }: FireRouteOptions) {
server.route({
method: 'POST',
path: '/api/action/{id}/_fire',
Copy link
Contributor

Choose a reason for hiding this comment

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

It's used to denote an action on a resource, though ES seems to be trying to move away from this convention. It also disambiguates in some cases, as index names in ES can't start with an underscore.

@azasypkin azasypkin self-requested a review June 26, 2019 11:37
Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

LGTM, couple of nits.

One general suggestion: the action plugin is a plugin that is or will be a foundational to many other things, is relatively new and will become very complex relatively soon. So it would be awesome if you can use debug logging more frequently, it would be a great help when we debug issues that will happen in production sooner or later (e.g. it was/is super valuable for security plugin) ;)

x-pack/legacy/plugins/actions/server/init.ts Outdated Show resolved Hide resolved
x-pack/legacy/plugins/actions/server/lib/execute.test.ts Outdated Show resolved Hide resolved
@@ -41,8 +43,21 @@ export function createMockServer(config: Record<string, any> = defaultConfig) {
},
});

server.register({
Copy link
Member

Choose a reason for hiding this comment

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

note: you may have a hard time rewriting tests that rely on this mock and Hapi's expose/register when you decide to migrate to new platform. No need to do anything about that in this PR, just saying 🙈 (experienced that recently, and started to abstract away from Hapi where possible)

x-pack/legacy/plugins/actions/server/routes/fire.ts Outdated Show resolved Hide resolved
x-pack/legacy/plugins/actions/server/routes/fire.ts Outdated Show resolved Hide resolved
x-pack/test/api_integration/apis/actions/fire.ts Outdated Show resolved Hide resolved
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mikecote mikecote merged commit e522e75 into elastic:master Jun 26, 2019
mikecote added a commit to mikecote/kibana that referenced this pull request Jun 26, 2019
* Create REST API to fire actions

* Add more tests to the fire API

* Remove dead file reference

* Fix broken tests

* Fix broken test

* Update docs

* Apply PR feedback
mikecote added a commit that referenced this pull request Jun 26, 2019
* Create REST API to fire actions

* Add more tests to the fire API

* Remove dead file reference

* Fix broken tests

* Fix broken test

* Update docs

* Apply PR feedback
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.3.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants