-
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
[ResponseOps] add pre-create, pre-update, and post-delete hooks for connectors #194081
Conversation
Here are some things to consider looking at the original commit:
|
I was mistaken about the executor only getting passed a request. Here's the full signature for the executor: kibana/x-pack/plugins/actions/server/types.ts Lines 75 to 92 in bc576fe
I think we want most of these, but we could add them later as needed. Critically, we want Here's kibana/x-pack/plugins/actions/server/types.ts Lines 48 to 58 in bc576fe
|
Thought it would be interesting to think about extending this in the future. Not in this PR :-) Currently, the hooks really just allow the hook to allow or deny the operation - they don't return anything useful. What else could they do?
Modifying config/secrets seems dicey - in fact, we may want to provide deep copies of these to prevent modification. But could be useful to supply additional computed values in those objects. There are noconnector type provided functions invoked iduring create/update/delete, so this may make it easier to deal with non-trivial or expensive data before it hits the executor. The concept of "connector state" feels like something we talked about a long time ago, but there are no issues open. The idea would be to add the capability for a The I don't think there's anything in the current "shape" of these hooks that would make it harder to implement these, if we want to go there. |
In b0ec428c5be6717eb2076d6ff00086870506a372 I added a minimal |
@@ -255,6 +256,33 @@ export class ActionsClient { | |||
} | |||
this.context.actionTypeRegistry.ensureActionTypeEnabled(actionTypeId); | |||
|
|||
const hookServices: HookServices = { | |||
scopedClusterClient: this.context.scopedClusterClient.asCurrentUser, |
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.
For my specific use case I need scopedClusterClient.asInternalUser
, so can we just return scopedClusterClient
to have a choice or expose two client?
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.
I plan on sending this.context.scopedClusterClient
, so both will be available. Easy to imagine both might be needed.
Using post/preSave hooks in the commit 6f9504f |
6ab5755
to
4599d00
Compare
…onnectors Extracted from elastic#189027, commit c97afeb Allows connector types to add functions to be called when connectors are created, updated, and deleted.
4599d00
to
c182b1b
Compare
⏳ Build in-progress, with failuresFailed CI StepsTest Failures
History
To update your PR or re-run it, just comment with: |
- re-added the update code to the new update module (update body removed from actionsClient) - propertly set `scopedClusterClient` instead of the `asCurrentUser` flavor - moved `tryCatch()` to `lib`
Pinging @elastic/response-ops (Team:ResponseOps) |
// functional version of try/catch, allows you to not have to use | ||
// `let` vars initialied to `undefined` to capture the result value | ||
|
||
export async function tryCatch<T>(fn: () => Promise<T>): Promise<T | Error> { |
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.
Handy little function to avoid having to let
define a variable that would need to be set within a try
/ catch
.
Happy to use some alternative, didn't find anything simple.
const label = `connectorId: "${id}"; type: ${actionTypeId}`; | ||
const tags = ['post-save-hook', id]; | ||
|
||
if (actionType.postSaveHook) { |
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.
is the idea here that by passing in wasSuccessful
the postSave hook could potentially undo whatever it did in the preSave hook if the create failed? Might be useful to be explicit about this in the README
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.
That is the exact reason, and you're right, I'll add it to the doc. Yuliia will need to make use of it, as she is calling the ES /inference
endpoint in the pre hook, but if the connector create/update fails, she'll need to "undo" it ...
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
async executor({ config, secrets, params, services, actionId }) { | ||
return { status: 'ok', actionId }; | ||
}, | ||
async preSaveHook({ connectorId, config, secrets, services, isUpdate, logger }) { |
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.
nit: could add a flag to the config to force the hook to throw an error to test the error condition
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.
ah, thanks for reminding me. I do think we should have some FT that test the error conditions, but didn't think they were absolutely required, since we do test in the jest tests. And given the time frame. Also not sure how to test for the SO create/update failing in FT, but could likely do it in a jest integration test.
So was planning on opening an issue to add those later.
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.
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.
Looks great! Thank you @pmuellr for shaping it and making through the line! Docs are awesome 💅
I thought it wouldn't do a full re-build if just an I'll plan on merging this after THAT build completes ... |
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Public APIs missing exports
History
|
Starting backport for target branches: 8.x https://github.com/elastic/kibana/actions/runs/11263635266 |
…onnectors (elastic#194081) Allows connector types to add functions to be called when connectors are created, updated, and deleted. Extracted from elastic#189027, commit c97afeb Co-authored-by: Yuliia Naumenko <[email protected]> (cherry picked from commit 57096d1)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
… for connectors (#194081) (#195686) # Backport This will backport the following commits from `main` to `8.x`: - [[ResponseOps] add pre-create, pre-update, and post-delete hooks for connectors (#194081)](#194081) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Patrick Mueller","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-09T21:52:09Z","message":"[ResponseOps] add pre-create, pre-update, and post-delete hooks for connectors (#194081)\n\nAllows connector types to add functions to be called when connectors are created, updated, and deleted.\r\n\r\nExtracted from #189027, commit c97afeb\r\n\r\nCo-authored-by: Yuliia Naumenko <[email protected]>","sha":"57096d1f4fbcb4fc0135505b6c6100566ff08cc9","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Feature:Actions","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.16.0"],"title":"[ResponseOps] add pre-create, pre-update, and post-delete hooks for connectors","number":194081,"url":"https://github.com/elastic/kibana/pull/194081","mergeCommit":{"message":"[ResponseOps] add pre-create, pre-update, and post-delete hooks for connectors (#194081)\n\nAllows connector types to add functions to be called when connectors are created, updated, and deleted.\r\n\r\nExtracted from #189027, commit c97afeb\r\n\r\nCo-authored-by: Yuliia Naumenko <[email protected]>","sha":"57096d1f4fbcb4fc0135505b6c6100566ff08cc9"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/194081","number":194081,"mergeCommit":{"message":"[ResponseOps] add pre-create, pre-update, and post-delete hooks for connectors (#194081)\n\nAllows connector types to add functions to be called when connectors are created, updated, and deleted.\r\n\r\nExtracted from #189027, commit c97afeb\r\n\r\nCo-authored-by: Yuliia Naumenko <[email protected]>","sha":"57096d1f4fbcb4fc0135505b6c6100566ff08cc9"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Patrick Mueller <[email protected]>
Extracted from #189027, commit c97afeb
Summary
Allows connector types to add functions to be called when connectors are created, updated, and deleted.
Checklist