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

[interpreter/loadPlugins] avoid deleting globals added by plugins #27171

Merged
merged 8 commits into from
Dec 28, 2018

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Dec 13, 2018

Plugins loaded by the @kbn/interpreter can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup the canvas global after loading the canvas plugins.

resolves #27162

@spalger spalger force-pushed the fix/canvas-regenerator-runtime-global branch from bb9022b to c071bb9 Compare December 13, 2018 22:27
@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@spalger spalger requested a review from a team as a code owner December 14, 2018 20:42
@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@spalger spalger added review v7.0.0 Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v6.6.0 labels Dec 15, 2018
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-canvas

@spalger spalger added WIP Work in progress and removed review labels Dec 17, 2018
@spalger
Copy link
Contributor Author

spalger commented Dec 17, 2018

I decided I should write tests for the requireWithGlobals() function and it turns out it's not working the way I had intended. Will take a look today and implementing it correctly and including tests to verify that.

@spalger spalger force-pushed the fix/canvas-regenerator-runtime-global branch from eba776d to a34b276 Compare December 17, 2018 17:46
rashidkpc
rashidkpc previously approved these changes Dec 17, 2018
Copy link
Contributor

@rashidkpc rashidkpc left a comment

Choose a reason for hiding this comment

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

I'm good with this conceptually, we just need to make sure nothing break.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

// `a` is `functions` and `b` is `server`
/\/canvas\/canvas_plugin\/(?!functions\/server)([^\/]+\/[^\/]+)/,
// ignore paths matching `/canvas/canvas_plugin/`
/\/canvas\/canvas_plugin\//,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By sharing the server_code_transformer with @kbn/interpreter I was able to pre-transpile the server code in the canvas_plugin_src and remove this customization.

@elasticmachine

This comment has been minimized.

@spalger spalger dismissed rashidkpc’s stale review December 20, 2018 23:02

Thanks for the review, but we've changed the approach pretty dramatically due to issues/complexity caused by mocking out the module system

@elasticmachine

This comment has been minimized.

@spalger spalger force-pushed the fix/canvas-regenerator-runtime-global branch from e58dc9a to 5853717 Compare December 20, 2018 23:32
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@spalger spalger added review and removed WIP Work in progress labels Dec 21, 2018
delete global[key];
}
});
delete global.canvas;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some documentation to this logic, to make it clear why we're adding, registering and then deleting the global?

Are there any other globals we should consider deleting? Forgive the terminology, but perhaps a registry of globals to delete would help, even if it's a bit derivative...?

Copy link
Contributor

Choose a reason for hiding this comment

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

We add the global for plugins to use. They all use canvas.register, so the global needs to exist when the code is run (ie. when require(path) is run).

My understanding is that it's removed to avoid complaints from our test runners, which check for added globals in the node runtime and fail if any are unexpectedly added.

Copy link
Contributor

@w33ble w33ble left a comment

Choose a reason for hiding this comment

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

Couple of questions, nothing worth blocking the PR over though.

@@ -6,6 +6,9 @@

const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const {
createServerCodeTransformer,
} = require('@kbn/interpreter/tasks/build/server_code_transformer');
Copy link
Contributor

Choose a reason for hiding this comment

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

The interpreter seems like a weird place to import build configuration from. It's also weird that it's importing something that wouldn't be part of the published package.

Do you think putting this in another package (currently existing or not) would make more sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We really don't want to have hundreds of packages in two years, so no to another package. I think this is fine, we don't publish these packages and if we want to we can figure something out then.

@@ -42,6 +42,8 @@ export function runMochaCli() {

// check that we aren't leaking any globals
process.argv.push('--check-leaks');
// prevent globals injected from canvas plugins from triggering leak check
process.argv.push('--globals', 'core,regeneratorRuntime,_');
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of fragile, but at least future globals will break the CI.

I do wonder, is there a way to remove that lodash global?

@w33ble
Copy link
Contributor

w33ble commented Dec 26, 2018

Confirmed fix for #27162 in dev mode.

Currently creating a build to check #27162 and #27729 in production.

@w33ble
Copy link
Contributor

w33ble commented Dec 26, 2018

Confirmed this does fix #27162 in the build as well.

Unfortunately, this does not fix #27729.

Copy link
Contributor

@w33ble w33ble left a comment

Choose a reason for hiding this comment

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

Whoops, thought I approved this already. LGTM.

@w33ble w33ble merged commit 3d96469 into elastic:master Dec 28, 2018
@w33ble w33ble added the v6.7.0 label Dec 28, 2018
w33ble pushed a commit to w33ble/kibana that referenced this pull request Dec 28, 2018
…astic#27171)

Plugins loaded by the `@kbn/interpreter` can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup the `canvas` global after loading the canvas plugins.

resolves elastic#27162
w33ble pushed a commit to w33ble/kibana that referenced this pull request Dec 28, 2018
…astic#27171)

Plugins loaded by the `@kbn/interpreter` can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup the `canvas` global after loading the canvas plugins.

resolves elastic#27162
w33ble added a commit that referenced this pull request Dec 28, 2018
…7171) (#27852)

Plugins loaded by the `@kbn/interpreter` can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup the `canvas` global after loading the canvas plugins.

resolves #27162
w33ble added a commit that referenced this pull request Dec 28, 2018
…7171) (#27851)

Plugins loaded by the `@kbn/interpreter` can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup the `canvas` global after loading the canvas plugins.

resolves #27162
@w33ble
Copy link
Contributor

w33ble commented Dec 28, 2018

6.6 ffe58f4
6.x f07987e

clintandrewhall pushed a commit to clintandrewhall/kibana that referenced this pull request Jan 2, 2019
…astic#27171)

Plugins loaded by the `@kbn/interpreter` can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup the `canvas` global after loading the canvas plugins.

resolves elastic#27162
@spalger spalger deleted the fix/canvas-regenerator-runtime-global branch August 18, 2020 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v6.6.0 v6.7.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Canvas] eCommerce Sample Workpad not loading
5 participants