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

[DEV] Allow webpack-dev-server proxy to any destination #9296

Merged
merged 1 commit into from
Mar 17, 2020

Conversation

ktmud
Copy link
Member

@ktmud ktmud commented Mar 12, 2020

CATEGORY

  • Build / Development Environment

SUMMARY

One of the main pain points in developing Superset frontend features is the lack of testing data. Local installations often do not have enough examples conveniently set up to test different edge cases. Because of the multi-repo workflow with chart plugins, it also get complicated to set up an editable frontend building environment on remote servers.

This PR allows webpack-dev-server to proxy to any remote Superset web service, but at the same time replaces CSS/JS asset references in the response HTML with locally built chunk files that have source map and hot reload support. The remote Superset service must be running on a version later than this PR.

This allows developers to start the frontend server locally, but test with production/staging data served by a remote server. This setup makes it easier to debug edge cases all while maintaining the productivity of writing code in a local IDE.

The only caveat is that this solution may not work for some complex user authentication configurations that require OAuth callbacks or cross-domain redirects.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TEST PLAN

Using following command to proxy dev-server to a remote Superset service:

npm run dev-server --superset=http://superset.dev.example.com

Or use a local reverse proxy or SSH port forwarding to forward remote service tohttp://localhost:8088.

The page should load normally with locally built assets and JS hot reloading should work.

ADDITIONAL INFORMATION

N/A

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

cc @kristw @etr2460 @rusackas @john-bodley

// make sure the manifest file exists
fs.mkdirSync(path.dirname(MANIFEST_FILE), { recursive: true });
fs.closeSync(fs.openSync(MANIFEST_FILE, 'as+'));
fs.watch(MANIFEST_FILE, loadManifest);
Copy link
Member Author

Choose a reason for hiding this comment

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

Reload manifest every time there is a new build.

superset-frontend/webpack.proxy-config.js Outdated Show resolved Hide resolved
superset/__init__.py Show resolved Hide resolved
{% macro js_bundle(filename) %}
{# HTML comment is needed for webpack-dev-server to replace assets
with development version #}
<!-- Bundle js {{ filename }} START -->
Copy link
Member Author

Choose a reason for hiding this comment

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

The downside is this adds such HTML comments even to the production mode. Can probably create a config flag DISABLE_ASSET_BUNDLE_WATERMARK to turn this off.

@ktmud ktmud force-pushed the dev-server-proxy branch 2 times, most recently from 2a299d8 to c993eac Compare March 13, 2020 21:45
@ktmud ktmud changed the title Allow webpack-dev-server proxy to any destination [DEV] Allow webpack-dev-server proxy to any destination Mar 13, 2020
@@ -236,7 +236,8 @@
"webpack-bundle-analyzer": "^3.4.1",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.14",
"webpack-sources": "^1.1.0"
"webpack-sources": "^1.1.0",
"yargs": "12 - 15"
Copy link
Member Author

Choose a reason for hiding this comment

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

Replace minimist with yargs as the latter has better API and is included by other packages anyway. Choose this wide range (12 -15) also because it is tested working with the latest version but other packages still depend on v12.

Copy link
Contributor

Choose a reason for hiding this comment

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

What other packages are depending on it? Do we have any script that depends on it?
Could we try to get this to 15?

Copy link
Member Author

Choose a reason for hiding this comment

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

jest-cli and webpack-dev-server uses 12, vega-lite uses 15. 15 is the latest version, the latest webpack-dev-server hasn't upgraded it yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, just found out there is a bot that automatically upgrade the packages for you, plus migrating all the code. Maybe we can use it to replace dependabot in superset-ui and superset-ui-plugins.

Copy link
Contributor

Choose a reason for hiding this comment

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

jest-cli and webpack-dev-server uses 12, vega-lite uses 15. 15 is the latest version, the latest webpack-dev-server hasn't upgraded it yet.

Do those list yargs as peerDependencies or dependencies? npm allow nested dependencies so it may install multiple versions of yargs, which is inefficient to have multiple copies, but not too bad. IMO, it might be good to be specific for the script stability.

Copy link
Contributor

Choose a reason for hiding this comment

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

Renovate looks interesting.

Copy link
Member Author

Choose a reason for hiding this comment

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

They list it as dependencies. The range is specifically to avoid multiple copies. I think it's OK to keep this range for now as we didn't use it too extensively and we already know both v12 and v15 works for our code.

() => {
return proxyConfig;
},
],
Copy link
Member Author

@ktmud ktmud Mar 13, 2020

Choose a reason for hiding this comment

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

Hot reload borrowed from here.

@ktmud ktmud force-pushed the dev-server-proxy branch from 501585f to 8c6c02e Compare March 13, 2020 23:37
Copy link
Contributor

@kristw kristw left a comment

Choose a reason for hiding this comment

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

Overall, awesome work! This should make testing with production data much easier!

Will be good to have another python-eye to check the python code.

superset-frontend/webpack.proxy-config.js Outdated Show resolved Hide resolved
superset-frontend/webpack.proxy-config.js Outdated Show resolved Hide resolved
superset/__init__.py Show resolved Hide resolved
@@ -236,7 +236,8 @@
"webpack-bundle-analyzer": "^3.4.1",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.14",
"webpack-sources": "^1.1.0"
"webpack-sources": "^1.1.0",
"yargs": "12 - 15"
Copy link
Contributor

Choose a reason for hiding this comment

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

What other packages are depending on it? Do we have any script that depends on it?
Could we try to get this to 15?

superset-frontend/webpack.proxy-config.js Outdated Show resolved Hide resolved
}

function toDevHTML(origHtml) {
let html = origHtml.replace(
Copy link
Contributor

Choose a reason for hiding this comment

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

  • could move this block of code below the loadManifest() block.
  • can use full word for clarity origHtml => originalHtml

Copy link
Member Author

Choose a reason for hiding this comment

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

I think origHtml is more in line with origRes used elsewhere in this file, otherwise should I rename origRes to originalResponse, henceforth res to response, and req to request as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the variable names!

@ktmud ktmud force-pushed the dev-server-proxy branch from 8c6c02e to 4b7a62e Compare March 14, 2020 22:56
@codecov-io
Copy link

codecov-io commented Mar 14, 2020

Codecov Report

Merging #9296 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #9296   +/-   ##
=======================================
  Coverage   59.08%   59.08%           
=======================================
  Files         374      374           
  Lines       12202    12202           
  Branches     2986     2986           
=======================================
  Hits         7209     7209           
  Misses       4814     4814           
  Partials      179      179

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1916a1...bc1d07c. Read the comment docs.

@ktmud ktmud force-pushed the dev-server-proxy branch from 19c3422 to 53ed851 Compare March 15, 2020 00:24
Copy link
Contributor

@kristw kristw left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments. Just a few minor

@@ -236,7 +236,8 @@
"webpack-bundle-analyzer": "^3.4.1",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.14",
"webpack-sources": "^1.1.0"
"webpack-sources": "^1.1.0",
"yargs": "12 - 15"
Copy link
Contributor

Choose a reason for hiding this comment

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

jest-cli and webpack-dev-server uses 12, vega-lite uses 15. 15 is the latest version, the latest webpack-dev-server hasn't upgraded it yet.

Do those list yargs as peerDependencies or dependencies? npm allow nested dependencies so it may install multiple versions of yargs, which is inefficient to have multiple copies, but not too bad. IMO, it might be good to be specific for the script stability.

}

function toDevHTML(origHtml) {
let html = origHtml.replace(
Copy link
Contributor

Choose a reason for hiding this comment

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

That would be nice.

@@ -236,7 +236,8 @@
"webpack-bundle-analyzer": "^3.4.1",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.14",
"webpack-sources": "^1.1.0"
"webpack-sources": "^1.1.0",
"yargs": "12 - 15"
Copy link
Contributor

Choose a reason for hiding this comment

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

Renovate looks interesting.

One of the pain points in developing Superset frontend code is the lack
of testing data. Local installation often do not have enough examples
setup to test all edge cases.

This change allows `webpack-dev-server` to proxy to any remote Superset
service, but the same time replaces frontend asset references in HTML
with links to local development version. This allows developers to test
with production data locally, tackling edge cases all while maintaining
the productivity of editing the code locally.
@ktmud ktmud force-pushed the dev-server-proxy branch from bd95e43 to 4b11eba Compare March 17, 2020 20:42
@ktmud
Copy link
Member Author

ktmud commented Mar 17, 2020

Tested again with a fresh installation. Didn't see any issues. I think this is ready to merge.

@kristw kristw merged commit c36a7e3 into apache:master Mar 17, 2020
@ktmud ktmud deleted the dev-server-proxy branch April 12, 2020 06:49
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.36.0 labels Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 0.36.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants