-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
Pinging @elastic/kibana-stack-services |
7cec0fe
to
ad6ad69
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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 but left some comments
export function fireRoute({ server, actionTypeRegistry, getServices }: FireRouteOptions) { | ||
server.route({ | ||
method: 'POST', | ||
path: '/api/action/{id}/_fire', |
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.
what does the underscore in _fire
mean? Not quite public?
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.
This is a pattern established by Elasticsearch as well as a way to indicate it doesn't correspond to a restful resource.
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.
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({ |
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.
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?
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.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💚 Build Succeeded |
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. 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', |
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.
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.
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, 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/lib/get_create_task_runner_function.test.ts
Outdated
Show resolved
Hide resolved
x-pack/legacy/plugins/actions/server/lib/get_create_task_runner_function.test.ts
Outdated
Show resolved
Hide resolved
x-pack/legacy/plugins/actions/server/lib/get_create_task_runner_function.test.ts
Outdated
Show resolved
Hide resolved
@@ -41,8 +43,21 @@ export function createMockServer(config: Record<string, any> = defaultConfig) { | |||
}, | |||
}); | |||
|
|||
server.register({ |
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.
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)
💚 Build Succeeded |
* 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
In this PR, we're exposing the fire action function as a REST API.