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

[Tines connector] SubActions framework changes #142475

Merged
merged 18 commits into from
Oct 5, 2022

Conversation

semd
Copy link
Contributor

@semd semd commented Oct 3, 2022

Summary

Issue: #140066

This PR is part of the Tines connector implementation, which is being implemented using the SubActions framework.
It needed some changes in the SubAction framework in order to meet the requirements, these changes have been extracted into this PR to be reviewed independently, the connector implementation itself is not included.

The SubActions framework changes are:

Backend:

  • Some Type generics were created and exported.
  • The subAction connector config now accepts renderParameterTemplates to allow custom body rendering.

Frontend:

  • useSubAction hook was improved to prevent an infinite request loop.
  • Abort control added.
  • Action execution response types improved.

@semd semd added release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting Security Solution Threat Hunting Team Team:Threat Hunting:Explore v8.6.0 labels Oct 3, 2022
@semd semd self-assigned this Oct 3, 2022
@semd semd requested a review from a team as a code owner October 3, 2022 14:05
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting (Team:Threat Hunting)

@semd semd requested a review from a team as a code owner October 4, 2022 10:39
Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

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

Thank you for the fixes!

@semd
Copy link
Contributor Author

semd commented Oct 4, 2022

@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, but added a note about a missing test for the newly supported renderParameterTemplates parameter

@@ -54,5 +54,6 @@ export const register = <Config extends ActionTypeConfig, Secrets extends Action
supportedFeatureIds: connector.supportedFeatureIds,
validate: validators,
executor,
renderParameterTemplates: connector.renderParameterTemplates,
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we should have a test for this new parameter being copied in, in register.test.ts.

@@ -55,6 +56,7 @@ describe('Registration', () => {
supportedFeatureIds: connector.supportedFeatureIds,
validate: expect.anything(),
executor: expect.anything(),
renderParameterTemplates: expect.anything(),
Copy link
Member

@cnasikas cnasikas Oct 5, 2022

Choose a reason for hiding this comment

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

nit: This check does not assert that the correct function is passed. What about

const renderParameterTemplates = jest.fn()

const connector = {
    id: '.test',
    name: 'Test',
    minimumLicenseRequired: 'basic' as const,
    supportedFeatureIds: ['alerting'],
    schema: {
      config: TestConfigSchema,
      secrets: TestSecretsSchema,
    },
    Service: TestSubActionConnector,
   renderParameterTemplates,
  };

// code omitted for brevity

 expect(actionTypeRegistry.register).toHaveBeenCalledWith({
      id: connector.id,
      name: connector.name,
      minimumLicenseRequired: connector.minimumLicenseRequired,
      supportedFeatureIds: connector.supportedFeatureIds,
      validate: expect.anything(),
      executor: expect.anything(),
      renderParameterTemplates,
    }); 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I was following the same criteria as in the validate and executor properties.
However, strictly speaking, it does not need to be the same function, the important thing is the function is properly wired.
Instead of testing the function reference (it could change and still be correct), I updated the test by adding a test case that checks the renderParameterTemplates is called with the correct parameters and it returns the correct value.

Copy link
Member

Choose a reason for hiding this comment

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

You are right @semd! We should improve that. Thanks for the additional test. Much better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cnasikas 👍 thanks for the review!

@cnasikas cnasikas added Feature:Actions Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) labels Oct 5, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@semd semd enabled auto-merge (squash) October 5, 2022 13:57
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
actions 211 208 -3

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
actions 21 23 +2

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
triggersActionsUi 99.1KB 99.1KB +18.0B
Unknown metric groups

API count

id before after diff
actions 216 213 -3

History

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

cc @semd

@semd semd merged commit 5e44010 into elastic:main Oct 5, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Oct 5, 2022
WafaaNasr pushed a commit to WafaaNasr/kibana that referenced this pull request Oct 11, 2022
* validators and template render

* frontend use_sub_action changes

* rollback custom validations in favor of 142376

* types fix

* rollback test

* extract render template function type

* fix type

* use abort controller in useSubAction hook

* renderTemplate in register test

* [CI] Auto-commit changed files from 'node scripts/build_plugin_list_docs'

* improve test

* register test improved

* test the renderedTemrenderedTemplate return value

Co-authored-by: Kibana Machine <[email protected]>
WafaaNasr pushed a commit to WafaaNasr/kibana that referenced this pull request Oct 14, 2022
* validators and template render

* frontend use_sub_action changes

* rollback custom validations in favor of 142376

* types fix

* rollback test

* extract render template function type

* fix type

* use abort controller in useSubAction hook

* renderTemplate in register test

* [CI] Auto-commit changed files from 'node scripts/build_plugin_list_docs'

* improve test

* register test improved

* test the renderedTemrenderedTemplate return value

Co-authored-by: Kibana Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Actions release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Team:Threat Hunting:Explore Team:Threat Hunting Security Solution Threat Hunting Team v8.6.0
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

7 participants