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

feat: Refactor asyncEvent middleware and add websocket support #13696

Merged
merged 5 commits into from
Mar 23, 2021

Conversation

robdiciuccio
Copy link
Member

SUMMARY

Migrate asyncEvent module from Redux middleware to a Promise-based event listener approach (with @suddjian) and add Websocket event transport support (extracted from #11498).

Resolves an incompatibility between async queries and dashboard native filters.

TEST PLAN

Verify async queries function properly with polling with and without dashboard native filters enabled.

ADDITIONAL INFORMATION

  • 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

@codecov
Copy link

codecov bot commented Mar 19, 2021

Codecov Report

Merging #13696 (d72c86e) into master (aa92c1e) will decrease coverage by 4.19%.
The diff coverage is 77.03%.

❗ Current head d72c86e differs from pull request most recent head d3afcc6. Consider uploading reports for the commit d3afcc6 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #13696      +/-   ##
==========================================
- Coverage   77.43%   73.24%   -4.20%     
==========================================
  Files         933      620     -313     
  Lines       47093    21985   -25108     
  Branches     5818     5731      -87     
==========================================
- Hits        36465    16102   -20363     
+ Misses      10485     5741    -4744     
+ Partials      143      142       -1     
Flag Coverage Δ
cypress 56.40% <19.04%> (-0.10%) ⬇️
hive ?
javascript 63.44% <77.03%> (+0.04%) ⬆️
mysql ?
postgres ?
presto ?
python ?
sqlite ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset-frontend/src/chart/chartReducer.ts 66.19% <ø> (+1.81%) ⬆️
superset-frontend/src/dashboard/index.jsx 100.00% <ø> (+36.36%) ⬆️
superset-frontend/src/explore/index.jsx 100.00% <ø> (+36.36%) ⬆️
superset-frontend/src/chart/chartAction.js 78.60% <60.00%> (+0.60%) ⬆️
superset-frontend/src/middleware/asyncEvent.ts 78.03% <77.69%> (-9.32%) ⬇️
superset/utils/cache.py
superset/commands/importers/v1/__init__.py
superset/reports/notifications/exceptions.py
superset/databases/decorators.py
superset/translations/utils.py
... and 309 more

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 aa92c1e...d3afcc6. Read the comment docs.

@robdiciuccio robdiciuccio marked this pull request as ready for review March 19, 2021 21:51
@villebro
Copy link
Member

Awesome @robdiciuccio! Testing/reviewing this weekend. Quick observation: you need to upgrade to npm@7, as the lock file will otherwise be downgraded from version 2 to 1.

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

I think this is a great improvement and makes the the async query framework much more approachable. I was able to make native filters work with this feature with just a few small changes (although a proper cleanup is probably in order there, too). I'm happy to implement this in native filters once this is merged. I left a few non-blocking comments, but LGTM (although please do update the lockfile to v2!).

Comment on lines 50 to 51
const chartData = {
some: 'data',
Copy link
Member

Choose a reason for hiding this comment

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

nit: This comes down to personal preference, but for me it's always easier to digest tests/mocks if they resemble real requests/responses as much as possible. In this case I believe chartData should be of type ChartDataResponseResult[]: https://github.com/apache-superset/superset-ui/blob/a3ec94f7a72a3dbb6cb6563e7ea7d3582661ea43/packages/superset-ui-core/src/query/types/QueryResponse.ts#L46-L72

switch (asyncEvent.status) {
case JOB_STATUS.DONE: {
let { data, status } = await fetchCachedData(asyncEvent); // eslint-disable-line prefer-const
data = Array.isArray(data) ? data : [data];
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines -50 to +42
componentId: number;
status: string;
data: any;
};
type AppConfig = Record<string, any>;
type ListenerFn = (asyncEvent: AsyncEvent) => Promise<any>;
Copy link
Member

Choose a reason for hiding this comment

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

Bycatch: I believe the correct type for data should be LegacyQueryData | ChartDataResponseResult[]

Copy link
Member Author

Choose a reason for hiding this comment

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

This could be a response payload for SQL Lab as well (in the future), which is the reason why it's generic. Well, that and laziness.

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, that makes total sense 👍

"jsdom": "^16.4.0",
"less": "^3.12.2",
"less-loader": "^5.0.0",
"mini-css-extract-plugin": "^0.4.0",
"mock-socket": "^9.0.3",
Copy link
Member

Choose a reason for hiding this comment

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

Is this used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently it's a peer dependency of jest-websocket-mock.

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM, let's get this in so we can fix native filter support

@robdiciuccio robdiciuccio merged commit 452b530 into master Mar 23, 2021
@robdiciuccio robdiciuccio deleted the rd/async-event-refactor branch March 23, 2021 14:23
allanco91 pushed a commit to allanco91/superset that referenced this pull request May 21, 2021
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 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 preset-io size/XL 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants