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

implement "plugin" package type #149370

Merged
merged 11 commits into from
Jan 30, 2023

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Jan 24, 2023

This PR updates the core discovery logic to support loading plugins from packages. This logic is additive, so that the existing plugins in the repo and third-party plugins can continue to be loaded via the existing mechanism, but with #148130 we will be automatically migrating all plugins in the repo to packages, which will use this logic.

The logic is already in-use in that PR, and was developed there, but extracted here for easier review.

The logic is relatively simple, where a list of packages in the repo are attached to the core Env and then filtered by core before converting all plugin packages to PluginWrapper. The PluginWrapper still exposes the plugin manifest to the rest of the code, and it is used in many places, so rather than making changes to the PluginWrapper I'm faking a legacy plugin manifest with the plugin package manifest.

@elastic/kibana-core: I'm going to need some help identifying what we need to get test coverage for. This is a pretty simple addition to the core IMO, and if it didn't work then nothing would work, so I'm pretty confident in it, but would still appreciate your feedback.

@spalger spalger added Team:Operations Team label for Operations Team release_note:skip Skip the PR/issue when compiling release notes labels Jan 24, 2023
@spalger spalger marked this pull request as ready for review January 24, 2023 14:55
@spalger spalger requested review from a team as code owners January 24, 2023 14:55
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

@TinaHeiligers
Copy link
Contributor

TinaHeiligers commented Jan 24, 2023

I'm going to need some help identifying what we need to get test coverage for.

@lukeelmers your input here would help a lot!
I can take a guess but don't have all the historical knowledge that other folks on the @elastic/kibana-core might have.

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

I left a few questions and recommend getting input from other team members on test coverage but it seems to be good. I'll give it a tentative LGTM. There are still a few days to follow up with changes if needed.

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

Tentative LGTM pending questions and test-coverage input from other team members.

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

To be perfectly honest, I'm still not sure to understand why exactly we want to change the plugin scanning system to be based on our generated plugin list instead of just filesystem scan as it's done today.

I get the fact that it's more performant, given that packages can be 'anywhere' and that therefore the plugin discovery system would take more time if it was only based on FS scan, but still, having the implementation diverging between 3rd parties (and test?) plugins and our internal ones feels somewhat wrong to me.

Now, this is just my gut feeling, I don't have any strong argument against this PR's changes.

A few questions and remarks that I'd like covered before the merge though:

import { PluginType } from '@kbn/core-base-common';
import { pluginManifestFromPluginPackage } from './plugin_manifest_from_plugin_package';

const kibanaVersion = `1.${Math.round(10 * Math.random())}.1`;
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: rand in tests is bad, m'kay?

Copy link
Contributor Author

@spalger spalger Jan 25, 2023

Choose a reason for hiding this comment

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

lol, fine, want me to just hard-code a version here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, given we had surprises in the past when using the current version, having an hardcoded one seems the best compromise to me

id: manifest.plugin.id,
version: '1.0.0',
enabledOnAnonymousPages: manifest.plugin.enabledOnAnonymousPages,
serviceFolders: manifest.serviceFolders,
Copy link
Contributor

@pgayvallet pgayvallet Jan 25, 2023

Choose a reason for hiding this comment

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

What are serviceFolders exactly? I saw the documentation on this property later in the PR, but still not sure to get it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty sure they were added to the documentation system for core specifically so that core/server and core/public were separate documentation sections. I'm not totally clear what it actually does, but I'm just maintaining support for it.

Comment on lines +72 to +80
const pluginPkgDiscovery$ = from(coreContext.env.repoPackages ?? EMPTY).pipe(
filter(
getPluginPackagesFilter({
oss: coreContext.env.cliArgs.oss,
examples: coreContext.env.cliArgs.runExamples,
paths: config.additionalPluginPaths,
parentDirs: config.pluginSearchPaths,
})
),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a fundamental change. The associated test file will have to be adapted accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +83 to +86
const manifest = pluginManifestFromPluginPackage(
coreContext.env.packageInfo.version,
pkg.manifest
);
Copy link
Contributor

@pgayvallet pgayvallet Jan 25, 2023

Choose a reason for hiding this comment

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

It's still unclear to me how to define multi-zone (browser+server) plugins with this package approach? Is it as simple as creating a package with a server and client sub folders? I assume so, given the PR remove the distinction with a single plugin package type, but I wanted to confirm it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's based on the plugin.server and plugin.browser properties in kibana.jsonc. They're both required properties in the manifest.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if my question was unclear, let me rephrase: can we still define plugins having both server and client parts with the new system?

})
);

const discoveryResults$ = merge(fsDiscovery$, pluginPkgDiscovery$).pipe(shareReplay());
Copy link
Contributor

Choose a reason for hiding this comment

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

merge(fsDiscovery$, pluginPkgDiscovery$)

I feel like we should be checking for duplicated from the two sources somehow here, unless we're adamant there's no risk of plugins being scanned by both (fs+package), wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The filesystem scanning only finds legacy plugins with kibana.json files, and the package scanning only finds packages with kibana.jsonc files. fsDiscovery$ won't ever produce duplicate values, though I'm find adding a distinct operator here.

Copy link
Contributor

Choose a reason for hiding this comment

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

My naive question was: what about a folder with both kibana.json and kibana.jsonc for the same plugin?

@@ -64,6 +66,8 @@ export class Env {
public readonly logDir: string;
/** @internal */
public readonly pluginSearchPaths: readonly string[];
/** @internal */
public readonly repoPackages?: readonly Package[];
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: update unit tests accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@spalger
Copy link
Contributor Author

spalger commented Jan 25, 2023

I get the fact that it's more performant, given that packages can be 'anywhere' and that therefore the plugin discovery system would take more time if it was only based on FS scan, but still, having the implementation diverging between 3rd parties (and test?) plugins and our internal ones feels somewhat wrong to me.

Yeah, the locations of packages is flexible, and the manifest approach to package discovery (listing dirs to search somewhere) is limiting and annoying for normal devs. Being able to put packages anywhere is a really good DX and worth it IMO, but we can't just scan every file in the repo to find all the kibana.jsonc files. We do this in bootstrap because we know we're in a git repo and can list all the files very efficiently, and we do it in the build process because we have the list of packages we are adding to the build. Either way, this approach brings a lot of consistency to many other operations, which is why this feels so good to me. Third-party plugins might also get a similar treatment, but we just haven't solved that problem yet. It should be really simple to add third-party packages to the standard package list, we just have to figure out the semantics around that, and then we can deprecate the old file-scanning code and remove it at some point.

@spalger spalger requested a review from pgayvallet January 25, 2023 16:23
@spalger spalger enabled auto-merge (squash) January 30, 2023 16:35
@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
@kbn/kibana-manifest-schema 85 107 +22
Unknown metric groups

API count

id before after diff
@kbn/kibana-manifest-schema 86 108 +22

History

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

@spalger spalger merged commit 376bed5 into elastic:main Jan 30, 2023
@spalger spalger deleted the implement/plugin-package-type branch January 30, 2023 17:47
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jan 30, 2023
kqualters-elastic pushed a commit to kqualters-elastic/kibana that referenced this pull request Feb 6, 2023
This PR updates the core discovery logic to support loading plugins from
packages. This logic is additive, so that the existing plugins in the
repo and third-party plugins can continue to be loaded via the existing
mechanism, but with elastic#148130 we
will be automatically migrating all plugins in the repo to packages,
which will use this logic.

The logic is already in-use in that PR, and was developed there, but
extracted here for easier review.

The logic is relatively simple, where a list of packages in the repo are
attached to the core `Env` and then filtered by core before converting
all plugin packages to `PluginWrapper`. The `PluginWrapper` still
exposes the plugin manifest to the rest of the code, and it is used in
many places, so rather than making changes to the `PluginWrapper` I'm
faking a legacy plugin manifest with the plugin package manifest.

@elastic/kibana-core: I'm going to need some help identifying what we
need to get test coverage for. This is a pretty simple addition to the
core IMO, and if it didn't work then nothing would work, so I'm pretty
confident in it, but would still appreciate your feedback.
spalger pushed a commit that referenced this pull request Feb 9, 2023
Fixes #149344

This PR migrates all plugins to packages automatically. It does this
using `node scripts/lint_packages` to automatically migrate
`kibana.json` files to `kibana.jsonc` files. By doing this automatically
we can simplify many build and testing procedures to only support
packages, and not both "packages" and "synthetic packages" (basically
pointers to plugins).

The majority of changes are in operations related code, so we'll be
having operations review this before marking it ready for review. The
vast majority of the code owners are simply pinged because we deleted
all `kibana.json` files and replaced them with `kibana.jsonc` files, so
we plan on leaving the PR ready-for-review for about 24 hours before
merging (after feature freeze), assuming we don't have any blockers
(especially from @elastic/kibana-core since there are a few core
specific changes, though the majority were handled in #149370).

---------

Co-authored-by: kibanamachine <[email protected]>
mistic pushed a commit to mistic/kibana that referenced this pull request May 10, 2023
Fixes elastic#149344

This PR migrates all plugins to packages automatically. It does this
using `node scripts/lint_packages` to automatically migrate
`kibana.json` files to `kibana.jsonc` files. By doing this automatically
we can simplify many build and testing procedures to only support
packages, and not both "packages" and "synthetic packages" (basically
pointers to plugins).

The majority of changes are in operations related code, so we'll be
having operations review this before marking it ready for review. The
vast majority of the code owners are simply pinged because we deleted
all `kibana.json` files and replaced them with `kibana.jsonc` files, so
we plan on leaving the PR ready-for-review for about 24 hours before
merging (after feature freeze), assuming we don't have any blockers
(especially from @elastic/kibana-core since there are a few core
specific changes, though the majority were handled in elastic#149370).

---------

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit 1b85815)

# Conflicts:
#	.github/CODEOWNERS
#	src/dev/build/tasks/bundle_fleet_packages.ts
#	src/dev/tsconfig.json
#	yarn.lock
mistic added a commit that referenced this pull request May 11, 2023
# Backport

This will backport the following commits from `main` to `8.7`:
- [[packages] migrate all plugins to packages
(#148130)](#148130)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Spencer","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-02-09T03:06:50Z","message":"[packages]
migrate all plugins to packages (#148130)\n\nFixes
https://github.com/elastic/kibana/issues/149344\r\n\r\nThis PR migrates
all plugins to packages automatically. It does this\r\nusing `node
scripts/lint_packages` to automatically migrate\r\n`kibana.json` files
to `kibana.jsonc` files. By doing this automatically\r\nwe can simplify
many build and testing procedures to only support\r\npackages, and not
both \"packages\" and \"synthetic packages\" (basically\r\npointers to
plugins).\r\n\r\nThe majority of changes are in operations related code,
so we'll be\r\nhaving operations review this before marking it ready for
review. The\r\nvast majority of the code owners are simply pinged
because we deleted\r\nall `kibana.json` files and replaced them with
`kibana.jsonc` files, so\r\nwe plan on leaving the PR ready-for-review
for about 24 hours before\r\nmerging (after feature freeze), assuming we
don't have any blockers\r\n(especially from @elastic/kibana-core since
there are a few core\r\nspecific changes, though the majority were
handled in #149370).\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"1b8581540295fde746dae6b4a09d74fb5821bfef","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Operations","release_note:skip","backport:skip","v8.8.0"],"number":148130,"url":"https://github.com/elastic/kibana/pull/148130","mergeCommit":{"message":"[packages]
migrate all plugins to packages (#148130)\n\nFixes
https://github.com/elastic/kibana/issues/149344\r\n\r\nThis PR migrates
all plugins to packages automatically. It does this\r\nusing `node
scripts/lint_packages` to automatically migrate\r\n`kibana.json` files
to `kibana.jsonc` files. By doing this automatically\r\nwe can simplify
many build and testing procedures to only support\r\npackages, and not
both \"packages\" and \"synthetic packages\" (basically\r\npointers to
plugins).\r\n\r\nThe majority of changes are in operations related code,
so we'll be\r\nhaving operations review this before marking it ready for
review. The\r\nvast majority of the code owners are simply pinged
because we deleted\r\nall `kibana.json` files and replaced them with
`kibana.jsonc` files, so\r\nwe plan on leaving the PR ready-for-review
for about 24 hours before\r\nmerging (after feature freeze), assuming we
don't have any blockers\r\n(especially from @elastic/kibana-core since
there are a few core\r\nspecific changes, though the majority were
handled in #149370).\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"1b8581540295fde746dae6b4a09d74fb5821bfef"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/148130","number":148130,"mergeCommit":{"message":"[packages]
migrate all plugins to packages (#148130)\n\nFixes
https://github.com/elastic/kibana/issues/149344\r\n\r\nThis PR migrates
all plugins to packages automatically. It does this\r\nusing `node
scripts/lint_packages` to automatically migrate\r\n`kibana.json` files
to `kibana.jsonc` files. By doing this automatically\r\nwe can simplify
many build and testing procedures to only support\r\npackages, and not
both \"packages\" and \"synthetic packages\" (basically\r\npointers to
plugins).\r\n\r\nThe majority of changes are in operations related code,
so we'll be\r\nhaving operations review this before marking it ready for
review. The\r\nvast majority of the code owners are simply pinged
because we deleted\r\nall `kibana.json` files and replaced them with
`kibana.jsonc` files, so\r\nwe plan on leaving the PR ready-for-review
for about 24 hours before\r\nmerging (after feature freeze), assuming we
don't have any blockers\r\n(especially from @elastic/kibana-core since
there are a few core\r\nspecific changes, though the majority were
handled in #149370).\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"1b8581540295fde746dae6b4a09d74fb5821bfef"}}]}]
BACKPORT-->

---------

Co-authored-by: Spencer <[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 release_note:skip Skip the PR/issue when compiling release notes Team:Operations Team label for Operations Team v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants