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

[SIEM] NP Plugin dependency cleanup #64842

Merged
merged 7 commits into from
Apr 30, 2020

Conversation

rylnd
Copy link
Contributor

@rylnd rylnd commented Apr 29, 2020

Summary

Addresses #59250.

  • Removes dependencies from which we only import static code (esUiShared, kibanaUtils)
    • We can do this independent of the plugin being enabled/declared; the files will always be imported and included in siem's bundle
  • Makes usageCollection optional
    • If the user disables this, we simply swap their tracking function with a no-op
  • Removes unused plugin contracts

The following is an audit of our remaining required dependencies:

  • alerting
    • Critical to Detection rules
  • actions
    • transitive dependency through alerting.
    • while we don't currently use the plugin contract, we have code referencing its request handler context (although that too is unused), which means we should (at least) declare it as optional
    • I'm leaving this as required for now, and I've got an issue for followup: ([SIEM] Remove unused references to actions #64855)
  • data
    • critical to global search/filtering
  • embeddable
    • critical to maps embeddable
  • features
    • critical to privileges registration
  • home
    • could be made optional, however:
    • cannot currently be disabled, and is a transient dependency of management besides
  • inspector
    • critical to EmbeddablePanel
  • licensing
    • critical to license-based authorization
  • maps
    • critical to maps embeddable
  • triggers_actions_ui
    • critical to Rule Actions
    • critical to case/connector functionality (needs verification: @stephmilovic @cnasikas)
  • uiActions
    • critical to EmbeddablePanel

Checklist

For maintainers

We are only importing static code from these plugins, and not consuming
their plugin contracts. For this reason, we can safely remove them from
kibana.json as that imported code will always be included in our own
bundle.
If it's not enabled, we simply use a noop for our tracker call.
These are only needed when we're actually using them in our codebase.
For request handler contexts, we only need our kibana.json declaration.
@rylnd rylnd added Team:SIEM v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.8.0 labels Apr 29, 2020
@rylnd rylnd self-assigned this Apr 29, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@rylnd rylnd marked this pull request as ready for review April 30, 2020 00:15
@rylnd rylnd requested review from a team as code owners April 30, 2020 00:15
} catch (error) {
// ignore failed setup here, as we'll just have an inert tracker
_track = noop;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this part of the exception be hit anymore? It doesn't seem like it with the way you changed it above. Just a question I have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a similar thought! Probably not, unless reportUiStats wasn't a function? I debated between the safety of the try/catch vs the cleanliness of not having it.

alerting: AlertingStart;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface StartPlugins {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface PluginSetup {}
Copy link
Contributor

Choose a reason for hiding this comment

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

You can optionally remove these two empty interfaces if you want and just do this below:

export class Plugin implements IPlugin<void, void, SetupPlugins, StartPlugins> {

And then remove the return {} you have in the start and setup to not return anything unless I'm missing something and we are returning empty objects for a purpose. But it looks like the contracts allow void for return types and we don't have anything useful to return at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@FrankHassanabad we return {} instead of undefined to allow consumers to distinguish between a disabled plugin and an enabled plugin with no contract. We first encountered this with our newsfeed integration, which resulted in #56236.

Copy link
Contributor

@FrankHassanabad FrankHassanabad left a comment

Choose a reason for hiding this comment

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

LGTM and thanks for the interesting and detailed read in the conversation notes as that helps a lot to understand what is going on server side. 👍

With the addition of the null coalescing, the only chance for an error
is in usageCollection. However, if the usageCollection contract changes,
we should get a type error long before we see a runtime error.
* passes missing generic arguments to public plugin interface
* passes missing generic arguments to both plugins' CoreSetup types
Instead, import them from core as needed.
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@rylnd rylnd merged commit b8e0730 into elastic:master Apr 30, 2020
@rylnd rylnd deleted the siem_dependency_trimming branch April 30, 2020 19:48
rylnd added a commit to rylnd/kibana that referenced this pull request Apr 30, 2020
* Remove static src dependencies from kibana.json

We are only importing static code from these plugins, and not consuming
their plugin contracts. For this reason, we can safely remove them from
kibana.json as that imported code will always be included in our own
bundle.

* Make usageCollection an optional dependency

If it's not enabled, we simply use a noop for our tracker call.

* Remove unused plugin contracts

These are only needed when we're actually using them in our codebase.
For request handler contexts, we only need our kibana.json declaration.

* Remove unnecessary try/catch

With the addition of the null coalescing, the only chance for an error
is in usageCollection. However, if the usageCollection contract changes,
we should get a type error long before we see a runtime error.

* Improve typings of our Plugin classes

* passes missing generic arguments to public plugin interface
* passes missing generic arguments to both plugins' CoreSetup types

* Don't re-export core types

Instead, import them from core as needed.
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine kibanamachine added backport missing Added to PRs automatically when the are determined to be missing a backport. and removed backport missing Added to PRs automatically when the are determined to be missing a backport. labels May 4, 2020
rylnd added a commit that referenced this pull request May 4, 2020
* Remove static src dependencies from kibana.json

We are only importing static code from these plugins, and not consuming
their plugin contracts. For this reason, we can safely remove them from
kibana.json as that imported code will always be included in our own
bundle.

* Make usageCollection an optional dependency

If it's not enabled, we simply use a noop for our tracker call.

* Remove unused plugin contracts

These are only needed when we're actually using them in our codebase.
For request handler contexts, we only need our kibana.json declaration.

* Remove unnecessary try/catch

With the addition of the null coalescing, the only chance for an error
is in usageCollection. However, if the usageCollection contract changes,
we should get a type error long before we see a runtime error.

* Improve typings of our Plugin classes

* passes missing generic arguments to public plugin interface
* passes missing generic arguments to both plugins' CoreSetup types

* Don't re-export core types

Instead, import them from core as needed.

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
@MindyRS MindyRS added the Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. label Sep 23, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:SIEM v7.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants