-
Notifications
You must be signed in to change notification settings - Fork 14k
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: Improve state key generation for dashboards and charts #18576
feat: Improve state key generation for dashboards and charts #18576
Conversation
Codecov Report
@@ Coverage Diff @@
## master #18576 +/- ##
==========================================
- Coverage 66.34% 66.13% -0.22%
==========================================
Files 1619 1620 +1
Lines 62967 63053 +86
Branches 6354 6365 +11
==========================================
- Hits 41778 41700 -78
- Misses 19529 19694 +165
+ Partials 1660 1659 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
/testenv up FEATURE_ENABLE_EXPLORE_DRAG_AND_DROP=true |
@jinghua-qa Ephemeral environment spinning up at http://34.222.115.242:8080. Credentials are |
Question: I tried add a new chart to the dashboard but the form_data_key of the dashboard did not change, is that expected? Screen.Recording.2022-02-07.at.8.40.31.AM.mov |
Yes. It's expected. The |
Hey @michael-s-molina it took a few clicks to reproduce the problem sorry about that, but as you will see in the video after going back and forth a few times the Dashboard Video Game Sales went from using Superset.mp4 |
Thanks for spotting that @geido! I submitted a fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it may be pragmatic to not initialize a new key-value pair every time the resource is reloaded with the same key. However, removing support for having separate state in two tabs on the same context (user + resource) is a problem. I would like to suggest a compromise: when opening the same resource without a key, a new key-value pair is initialized. However, when the same user reloads the same resource with the same key, the key would not change.
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx
Show resolved
Hide resolved
@michael-s-molina Thanks for working on this! there are 2 concerns in this PR.
|
@zhaoyongjie Thanks for bringing the multi-session and key expiration problems to my attention. I addressed both problems here and in #18624 |
Thanks for you tackle this! LGTM |
@michael-s-molina In order to avoid code conflicts, we need to merge PR-18624 first. |
beac1ef
to
1fe5635
Compare
@villebro @zhaoyongjie I rebased the code and worked on supporting multi-tab states for the dashboards. The idea is to add an optional parameter called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really impressive work - logic looks solid and works just as expected. Bravo! 👏
@zhaoyongjie @villebro I added the Explore part. Now the PR is complete. In this part, I only replicated the server-side logic in Explore and extracted the |
f394515
to
a8d648c
Compare
Hi @michael-s-molina, Thanks for providing different tabs cache mechanisms. The current solution causes the same session to have different cache keys due to different tab keys. Imagine if the user created 5 tabs, the cache system has to create 5 cache records. For this high-frequency operation, do we consider using some data structures to solve it? for example:
Second, could we consider using In the future, we can also improve |
I think this could be a further optimization that we can implement in the future 👍🏼
I considered this option but discarded it because of the following in window.sessionStorage docs:
|
bc48950
to
47d13f7
Compare
Ephemeral environment shutdown and build artifacts deleted. |
🏷 2022.7 |
🏷 preset:2022.7 |
SUMMARY
When opening a dashboard or a chart in Explore, the URL will update with a new state key every time the page is reloaded even when the state isn't updated. This may not be scalable in high-traffic Superset deployments where it can quickly fill up disk space or exhaust the number of cache keys too fast, due to memory restrictions, making it more likely that a link you shared with someone a while ago becomes invalid.
To address this problem we should consider the request context such as user ID, resource ID, etc, to generate new keys only when the context changes. This way we can reuse existing keys but at the same time maintain the uniqueness of storage spaces for different users/dashboards/datasets/charts.
We could use HMAC to generate the same key for the same context but that would require key rotation management.
We can’t base key generation on previous keys because we have POST scenarios where the key is not present. One example would be when the user is inside a dashboard and selects “View chart in Explore”.
We can’t change the structure of the cache key to use the user and resource because this information is not present in the GET/DELETE requests and it would also require keeping backward compatibility with previous versions.
To implement the desired behavior we’ll keep a secondary mapping of user and resources with the previously generated keys. We'll store this mapping together with the entry so they’ll share the same expiration time. We’ll also keep it in sync with DELETE events. That way we can reuse the keys and keep the solution backward compatible.
Hat tip to @zhaoyongjie and @ktmud for bringing this concern during the reviews 👏🏼
Follow-up of #18181
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Screen.Recording.2022-02-03.at.2.58.42.PM.mov
TESTING INSTRUCTIONS
1 - Check that
form_data_key
is reused when the same user is accessing the same resource (dashboard, dataset, or chart)2 - Check that
form_data_key
changes when the user, dashboard, dataset, or chart changes.3 - Check that the values associated with a given key are correctly retrieved from the server
ADDITIONAL INFORMATION