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

Data plugin: Suggested enhance pattern #74505

Merged
merged 22 commits into from
Aug 13, 2020

Conversation

lizozom
Copy link
Contributor

@lizozom lizozom commented Aug 6, 2020

Summary

This PR is a suggestion for a simple pattern to enhance an OSS plugin from x-pack.

Related to #62998

The term "enhance" refers to cases where the x-pack plugin changes the functionality or expands the API of an OSS plugin. It does not refer to cases where an OSS plugin has a registry that multiple plugins can register to (i.e. search strategy registry).

How does it work?

  • The OSS plugin exposes an enhance function on the setup contract.
  • The enhance function enriches the plugin by using passed in enhancements or passes them down to sub-plugins, by calling their enhance function.
  • The corresponding x-pack plugin should call enhance function from it's setup contract. (This is important because enhancements should be done, before consuming those services).
  • If any enhancement requires a dependency from the start contract, it should use core.getStartServices internally.

Empty APIs

Another part of the suggested pattern (but is not demoed here), is explained in detail by @streamich in this comment.

To allow OSS plugins easily consume those enhanced APIs, an OSS plugin may expose empty functions that do nothing in OSS (return undefined \ null \ false \ throw an exception, depending on the usecase). The enhance function will provide the implementation for those functions, hence enabling those features.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@lizozom lizozom requested a review from a team as a code owner August 6, 2020 12:10
@lizozom lizozom added the release_note:skip Skip the PR/issue when compiling release notes label Aug 6, 2020
@lizozom
Copy link
Contributor Author

lizozom commented Aug 10, 2020

@elasticmachine merge upstream

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

not sure how different this is from what we are currently doing, except that if we want many overrides we can do them all in one method. (so its easier to add more overrides)

@@ -47,6 +51,7 @@ export interface DataPublicPluginSetup {
search: ISearchSetup;
fieldFormats: FieldFormatsSetup;
query: QuerySetup;
enhance: (enhancements: DataPublicPluginEnhancements) => void;
Copy link
Member

Choose a reason for hiding this comment

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

should it take in Partial ? will we be providing enhancements from different plugins ? (one plugin providing search enhancement and another one providing index pattern enhancement) or do we want to limit it to single plugin ?

if so, lets add a check to make sure we are not calling this twice (and throw)

Copy link
Member

Choose a reason for hiding this comment

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

also, lets mark this as internal, i would prefer if we keep it under separate key to make it very clear
data.__internal.enhance()

Copy link
Member

Choose a reason for hiding this comment

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

another taught: should we rather provide this functions on per service basis ? (data.search.enhance()) or even on per item basis: data.search.setSearchInterceptor() (which is what we are currently doing)?

Copy link
Contributor Author

@lizozom lizozom Aug 10, 2020

Choose a reason for hiding this comment

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

  1. I don't think we want to take in a partial because this is a pattern for a plugin enhancing it's own matching OSS plugin. Not for a registry or so.
  2. I agree about making it internal. I think calling the function data._enhance should be enough.
  3. We do have it in a per service basis (to propagate the enhancements). However, I think that one of the benefits of having an enhance method rather than a setInterceptor method, is the explicitness of it.

An additional change here, is that enhancements are managed during the setup phase, while before we enhanced during the start phase (which was giving me trouble in the Background Sessions PR. IN the same PR I also have multiple enhancements, getting actual value from the pattern suggested here.

@lizozom
Copy link
Contributor Author

lizozom commented Aug 11, 2020

@elasticmachine merge upstream

@lizozom lizozom requested a review from ppisljar August 12, 2020 13:46
Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

code LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

page load bundle size

id value diff baseline
data 1.4MB +1.2KB 1.4MB
dataEnhanced 178.0KB +34.0B 178.0KB
total +1.2KB

History

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

Copy link
Member

@lukasolson lukasolson left a comment

Choose a reason for hiding this comment

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

Code LGTM. Pulled down and tested OSS/trial license and things were functioning as expected.

@lizozom lizozom merged commit 290f9bf into elastic:master Aug 13, 2020
lizozom added a commit to lizozom/kibana that referenced this pull request Aug 13, 2020
* improve test stability

* Enhance pattern

* fix tests

* fix test

* Rename enhance to __enhance

* Deleted unnecessary attribute

* ISearchInterceptor interface

* docs

* Clean up internal docs

* jest

Co-authored-by: Elastic Machine <[email protected]>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 13, 2020
* master: (28 commits)
  [Task manager] Prevents edge case where already running tasks are reschedule every polling interval (elastic#74606)
  [Security Solution] Fix the status of timelines' bulk actions (elastic#74560)
  Data plugin: Suggested enhance pattern (elastic#74505)
  Use jest.useFakeTimers instead of hard coded timeout for tooltip tests. (elastic#74642)
  [Security Solution][lists] Adds tests for exception lists and items part 2 (elastic#74815)
  [Security Solution][Resolver] fix presentation role on edgeline (elastic#74869)
  [Security Solution][Detections] Refactor ML calls for newest ML permissions (elastic#74582)
  [bin/kibana-plugin] support KP plugins instead (elastic#74604)
  Reduce number of indexed fields in index pattern saved object (elastic#74817)
  [reporting] Pass along generic parameters in high-order route handler (elastic#74892)
  Migrated last pieces of legacy fixture code (elastic#74470)
  Empty index patterns page re-design  (elastic#68819)
  [babel] coalese some versions to prevent breaking yarn install (elastic#74864)
  [Dashboard First] Decouple Attribute Service and By Value Embeddables (elastic#74302)
  Revert "[reporting] Pass along generic parameters in high-order route handler" (elastic#74891)
  [reporting] Pass along generic parameters in high-order route handler (elastic#74879)
  [src/dev/build] implement a getBuildNumber() mock (elastic#74881)
  [Enterprise Search] Add solution-level side navigation (elastic#74705)
  [DOCS] Canvas docs 7.9 refresh (elastic#74000)
  [Security Solution][Resolver]Enzyme test related events closing (elastic#74811)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 13, 2020
…le-buffer-with-update-of-same-id

* upstream/master: (37 commits)
  [Task manager] Prevents edge case where already running tasks are reschedule every polling interval (elastic#74606)
  [Security Solution] Fix the status of timelines' bulk actions (elastic#74560)
  Data plugin: Suggested enhance pattern (elastic#74505)
  Use jest.useFakeTimers instead of hard coded timeout for tooltip tests. (elastic#74642)
  [Security Solution][lists] Adds tests for exception lists and items part 2 (elastic#74815)
  [Security Solution][Resolver] fix presentation role on edgeline (elastic#74869)
  [Security Solution][Detections] Refactor ML calls for newest ML permissions (elastic#74582)
  [bin/kibana-plugin] support KP plugins instead (elastic#74604)
  Reduce number of indexed fields in index pattern saved object (elastic#74817)
  [reporting] Pass along generic parameters in high-order route handler (elastic#74892)
  Migrated last pieces of legacy fixture code (elastic#74470)
  Empty index patterns page re-design  (elastic#68819)
  [babel] coalese some versions to prevent breaking yarn install (elastic#74864)
  [Dashboard First] Decouple Attribute Service and By Value Embeddables (elastic#74302)
  Revert "[reporting] Pass along generic parameters in high-order route handler" (elastic#74891)
  [reporting] Pass along generic parameters in high-order route handler (elastic#74879)
  [src/dev/build] implement a getBuildNumber() mock (elastic#74881)
  [Enterprise Search] Add solution-level side navigation (elastic#74705)
  [DOCS] Canvas docs 7.9 refresh (elastic#74000)
  [Security Solution][Resolver]Enzyme test related events closing (elastic#74811)
  ...
lizozom added a commit that referenced this pull request Aug 13, 2020
* improve test stability

* Enhance pattern

* fix tests

* fix test

* Rename enhance to __enhance

* Deleted unnecessary attribute

* ISearchInterceptor interface

* docs

* Clean up internal docs

* jest

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 13, 2020
* upstream/master: (45 commits)
  [Metrics UI] Fix inventory footer misalignment (elastic#74707)
  Remove legacy optimizer (elastic#73154)
  Update design-specific GH code-owners (elastic#74877)
  skip test Reporting paginates content elastic#74922
  [Metrics UI] Add Jest tests for alert previews (elastic#74890)
  Fixed tooltip (elastic#74074)
  [Ingest Pipelines] Processor forms for processors A-D (elastic#72849)
  [Observability] change ingest manager link (elastic#74928)
  [Task manager] Prevents edge case where already running tasks are reschedule every polling interval (elastic#74606)
  [Security Solution] Fix the status of timelines' bulk actions (elastic#74560)
  Data plugin: Suggested enhance pattern (elastic#74505)
  Use jest.useFakeTimers instead of hard coded timeout for tooltip tests. (elastic#74642)
  [Security Solution][lists] Adds tests for exception lists and items part 2 (elastic#74815)
  [Security Solution][Resolver] fix presentation role on edgeline (elastic#74869)
  [Security Solution][Detections] Refactor ML calls for newest ML permissions (elastic#74582)
  [bin/kibana-plugin] support KP plugins instead (elastic#74604)
  Reduce number of indexed fields in index pattern saved object (elastic#74817)
  [reporting] Pass along generic parameters in high-order route handler (elastic#74892)
  Migrated last pieces of legacy fixture code (elastic#74470)
  Empty index patterns page re-design  (elastic#68819)
  ...
@stacey-gammon
Copy link
Contributor

As far as a generic pattern goes, this is a bit hard to follow, since the types are specific to the plugin, but here are my initial thoughts:

I don't think we'll be able to come up with a generic solution that fits every use case - many of the use cases are very situationally dependent. For example - the embeddable enhancement is an enhancement to a registry item, and can add state, so needs to provide a migration function. This kind of enhancement pattern I tried to capture here. It's somewhat generic but I don't think it extends to the use case here because you aren't extending instances that belong to a registry. You are intercepting a function call (if I'm following correctly), so no possibility of manipulating state, so no migration concerns.

@streamich - I think your diagram here:

Screen Shot 2020-08-17 at 4 51 26 PM

is supposed to be what the current enhancements does. We should support multiple "enhancers", and you could do something like:

Screen Shot 2020-08-17 at 4 59 22 PM

Which is what you are getting at too, with your diagrams? If so, I think we are on the same page. The problem now is that only one enhancer is supported, which I agree should probably change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Meta release_note:skip Skip the PR/issue when compiling release notes v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants