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

Remove core->cli dependency #95145

Merged
merged 45 commits into from
Mar 30, 2021

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Mar 23, 2021

Summary

Fix #76935

Remove the core->cli circular dependency by having the src/cli/serve script starting the CliDevMode instead of delegating that job to a 'stub' core's Server instance. See #76935 (comment) for more details on the issue and the chosen approach.

Unwiring and moving all the required parts to achieve that was a little tricky, but to summarize, I had to:

  • Create the @kbn/http-tools package

The BasePathProxyServer was using some utility functions from core (createServer, getServerOptions, getListenerOptions and so on), that are also used by core's HttpServer. As we do want to keep that code factorized, in case we change our underlying http lib at some point, I created this package instead of just duplicating the code we wanted (which is just the correct practice, overall)

  • Create the @kbn/crypto package

This package contains what was previously in src/core/server/utils/crypto, as it was used by the code we extracted to @kbn/http-tools. I could have just put the crypto utils in http-tools, but as these utils were not exclusively used by http-related stuff, I thought it made more sense to have our own package. Note that I initially wanted to put that in @kbn/utils, but some tests of the crypto extracted code relies on @kbn/dev-utils, so that would have created a circular dev-utils->utils->dev-utils dependency. I still think having our own crypto dedicated package make sense anyway.

  • Create the @kbn/dev-cli-mode package

This package contains what was previously under src/dev/cli_dev_mode. All this code is now self-contained into a package, making sure we'll not be adding unwanted dependencies to core later.

Checklist

@kibanamachine
Copy link
Contributor

⏳ Build in-progress, with failures

Failed CI Steps

History

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

@kibanamachine
Copy link
Contributor

⏳ Build in-progress, with failures

Failed CI Steps

History

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

@pgayvallet pgayvallet added chore release_note:skip Skip the PR/issue when compiling release notes v7.13.0 labels Mar 24, 2021
packages/kbn-crypto/tsconfig.json Outdated Show resolved Hide resolved
packages/kbn-crypto/package.json Show resolved Hide resolved
packages/kbn-http-tools/src/get_server_options.ts Outdated Show resolved Hide resolved
packages/kbn-http-tools/src/get_server_options.ts Outdated Show resolved Hide resolved
packages/kbn-http-tools/src/get_request_id.ts Outdated Show resolved Hide resolved
Comment on lines 1842 to 1849
describe('Timeouts', () => {
let httpServer: HttpServer;
let router: Router;

beforeEach(() => {
httpServer = new HttpServer(logger, 'foo');
const enhanceWithContext = (fn: (...args: any[]) => any) => fn.bind(null, {});
router = new Router('', logger.get(), enhanceWithContext);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be placed in src/core/server/http/http_server.test.ts? We can move the whole file into integration_tests later

src/cli/serve/serve.js Outdated Show resolved Hide resolved
public basePathProxyTargetPort: number;

constructor(rawConfig: DevConfigType) {
this.basePathProxyTargetPort = rawConfig.basePathProxyTarget;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need a wrapper for a boolean flag?

Comment on lines +144 to +145
pluginPaths: config.plugins.additionalPluginPaths,
pluginScanDirs: config.plugins.pluginSearchPaths,
Copy link
Contributor

Choose a reason for hiding this comment

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

we can remove getPluginSearchPaths usage in @kbn/optimizer then?

src/cli/serve/serve.js Show resolved Hide resolved
};
const bootstrapScript = getBootstrapScript(cliArgs.dev);

await bootstrapScript({
Copy link
Contributor

@mshustov mshustov Mar 26, 2021

Choose a reason for hiding this comment

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

@spalger What is the main reason we want dev_cli controlling the Kibana server creation? It always confuses me when debugging the Kibana server with Chrome

...(ACTIVE_INSPECT_FLAG ? [`${ACTIVE_INSPECT_FLAG}=${process.debugPort + 1}`] : []),

Copy link
Contributor

Choose a reason for hiding this comment

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

The main reason is because the dev cli implements auto restart on changes and ensuring that we don't see failed requests while it's restarting, and so that there's a single command to run that sets that and the optimizer up.

Copy link
Contributor

@spalger spalger Mar 27, 2021

Choose a reason for hiding this comment

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

If you instead run node scripts/kibana without --dev, or instead of using yarn start, you can run the server without the dev cli wrapper that makes dev a lot easier in most cases.

packages/kbn-cli-dev-mode/package.json Outdated Show resolved Hide resolved
packages/kbn-cli-dev-mode/package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

@pgayvallet pgayvallet merged commit 265cc76 into elastic:master Mar 30, 2021
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Mar 30, 2021
* extract http_tools to package

* fix readme

* start moving stuff

* cleaning up `isDevCliParent`

* choose bootstrap script

* fix bootstrap script logic

* fix watch paths logic

* import REPO_ROOT from correct package

* create the @kbn/crypto package

* update core's `dev` config

* only export bootstrap function

* extract sslConfig to http-tools package

* fix core types

* fix optimizer tests

* fix cli_dev_mode tests

* fix basePath proxy tests

* update generated doc

* fix unit tests

* create @kbn/dev-cli-mode package

* remove useless comment

* self-review NITS

* update CODEOWNERS file

* add devOnly flag

* use variable for DEV_MODE_PATH

* review comments

* fix logger/log adapter

* fix log calls in base path proxy server

* address some review comments

* rename @kbn/http-tools to @kbn/server-http-tools

* more review comments

* move test to correct file

* add comment on getBootstrapScript

* fix lint

* lint

* add cli-dev-mode to eslint dev packages

* review comments

* update yarn.lock

* Revert "[ci] skip building ts refs when not necessary (elastic#95739)"

This reverts commit e46a74f
# Conflicts:
#	.github/CODEOWNERS
pgayvallet added a commit that referenced this pull request Mar 30, 2021
* extract http_tools to package

* fix readme

* start moving stuff

* cleaning up `isDevCliParent`

* choose bootstrap script

* fix bootstrap script logic

* fix watch paths logic

* import REPO_ROOT from correct package

* create the @kbn/crypto package

* update core's `dev` config

* only export bootstrap function

* extract sslConfig to http-tools package

* fix core types

* fix optimizer tests

* fix cli_dev_mode tests

* fix basePath proxy tests

* update generated doc

* fix unit tests

* create @kbn/dev-cli-mode package

* remove useless comment

* self-review NITS

* update CODEOWNERS file

* add devOnly flag

* use variable for DEV_MODE_PATH

* review comments

* fix logger/log adapter

* fix log calls in base path proxy server

* address some review comments

* rename @kbn/http-tools to @kbn/server-http-tools

* more review comments

* move test to correct file

* add comment on getBootstrapScript

* fix lint

* lint

* add cli-dev-mode to eslint dev packages

* review comments

* update yarn.lock

* Revert "[ci] skip building ts refs when not necessary (#95739)"

This reverts commit e46a74f
# Conflicts:
#	.github/CODEOWNERS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore release_note:skip Skip the PR/issue when compiling release notes v7.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove circular dependencies between CLI & core
5 participants