-
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
Data plugin: Suggested enhance pattern #74505
Conversation
Pinging @elastic/kibana-app-arch (Team:AppArch) |
@elasticmachine merge upstream |
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.
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)
src/plugins/data/public/types.ts
Outdated
@@ -47,6 +51,7 @@ export interface DataPublicPluginSetup { | |||
search: ISearchSetup; | |||
fieldFormats: FieldFormatsSetup; | |||
query: QuerySetup; | |||
enhance: (enhancements: DataPublicPluginEnhancements) => void; |
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.
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)
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.
also, lets mark this as internal, i would prefer if we keep it under separate key to make it very clear
data.__internal.enhance()
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.
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)?
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 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.
- I agree about making it internal. I think calling the function
data._enhance
should be enough. - 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.
@elasticmachine merge upstream |
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.
code LGTM
💚 Build SucceededBuild metricspage load bundle size
History
To update your PR or re-run it, just comment with: |
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.
Code LGTM. Pulled down and tested OSS/trial license and things were functioning as expected.
* 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]>
* 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) ...
…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) ...
* 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]>
* 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) ...
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: is supposed to be what the current enhancements does. We should support multiple "enhancers", and you could do something like: 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. |
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?
enhance
function on thesetup
contract.enhance
function enriches the plugin by using passed inenhancements
or passes them down to sub-plugins, by calling theirenhance
function.x-pack
plugin should callenhance
function from it'ssetup
contract. (This is important because enhancements should be done, before consuming those services).start
contract, it should usecore.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