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: add ability to disable cache #23439

Merged
merged 1 commit into from
Mar 31, 2023

Conversation

villebro
Copy link
Member

@villebro villebro commented Mar 21, 2023

SUMMARY

Currently it's only possible to bypass the chart data cache by adding the force=true query param if a chart cache has been defined. This can be problematic if one wants to either

  1. disable caching globally by default, but make it possible to enable caching per database, dataset or chart
  2. disable caching by default for a specific database, dataset or chart without disabling chart data caching globally

This PR adds support for a -1 chart data timeout which is interpreted similarly to force=true, and is implemented both in the V1 chart data endpoint and viz.py. A test is also added to the chart data test suite. Note that the timeout value 0 is already reserved and ambiguous, and its behavior is different depending on the cache backend: sometimes is means "never expire", and other times "expire instantly" (I was not able to find a documentation reference to this, but I remember seeing it in the Flask-Caching source code while working on something else).

AFTER

By setting the cache timeout to -1 the cache is bypassed similar to what happens if making the request with force=true:

cache_disabled.mp4

Note, that the value is still persisted in the cache if a cache is defined. This is to ensure that Global Async Queries will still work, and that other chart data requests that don't want to bypass the cache are able to retrieve the cached data (if available).

BEFORE

Previously it was not possible to disable the cache if CHART_DATA_CACHE was defined (at a minimum, it was possible to set it to 1 second, which almost did the same):

cache_enabled.mp4

In addition, if the "cache timeout" value was removed in the dataset modal, it would get saved as an empty string, which caused a 500 in the backend when trying to reopen the modal (it expects either anull or a number). To make sure that doesn't happen, we change the value to null if the value is an empty string when the dataset is saved.

image

TESTING INSTRUCTIONS

  1. Set the chart, dataset, database or global cache config timeout to -1
  2. Go to a chart and click "Update" repeatedly
  3. Notice that the cache is always bypassed

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Merging #23439 (9d95529) into master (b0d83e8) will increase coverage by 0.00%.
The diff coverage is 90.32%.

❗ Current head 9d95529 differs from pull request most recent head 8a43a2f. Consider uploading reports for the commit 8a43a2f to get more accurate results

@@           Coverage Diff           @@
##           master   #23439   +/-   ##
=======================================
  Coverage   67.63%   67.63%           
=======================================
  Files        1908     1908           
  Lines       73716    73731   +15     
  Branches     7989     7990    +1     
=======================================
+ Hits        49856    49871   +15     
+ Misses      21812    21811    -1     
- Partials     2048     2049    +1     
Flag Coverage Δ
hive 52.73% <46.66%> (-0.01%) ⬇️
javascript 53.81% <81.25%> (-0.06%) ⬇️
mysql 78.45% <66.66%> (-0.01%) ⬇️
postgres 78.51% <66.66%> (-0.01%) ⬇️
presto 52.66% <46.66%> (-0.01%) ⬇️
python 82.37% <100.00%> (+0.06%) ⬆️
sqlite 77.02% <66.66%> (?)
unit 52.58% <60.00%> (+0.06%) ⬆️

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

Impacted Files Coverage Δ
...ackages/superset-ui-core/src/utils/featureFlags.ts 100.00% <ø> (ø)
...c/components/Chart/DrillDetail/DrillDetailPane.tsx 75.00% <ø> (ø)
...end/src/components/Datasource/DatasourceEditor.jsx 65.35% <ø> (ø)
...tend/src/components/Datasource/DatasourceModal.tsx 68.18% <0.00%> (-1.59%) ⬇️
...tersConfigModal/FiltersConfigForm/ColumnSelect.tsx 77.14% <ø> (ø)
...onfigModal/FiltersConfigForm/FiltersConfigForm.tsx 55.17% <ø> (-4.49%) ⬇️
...d/src/explore/components/PropertiesModal/index.tsx 50.53% <ø> (ø)
.../CRUD/data/database/DatabaseModal/ExtraOptions.tsx 70.37% <ø> (ø)
.../dataset/AddDataset/EditDataset/UsageTab/index.tsx 90.47% <ø> (ø)
superset/config.py 91.78% <ø> (ø)
... and 10 more

... and 10 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@villebro villebro requested a review from dpgaspar March 21, 2023 10:59
@@ -101,6 +101,10 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
postPayload: {
data: {
...currentDatasource,
cache_timeout:
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add this logic to the server-side endpoint to make sure this treatment is applied when invoking the API directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently the Datasource modal is unfortunately using the legacy endpoint, which is why this check isn't happening in the API. If it were in fact using the V1 API, the old request would produce an error, as it does not satisfy the Marshmallow schema.

Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

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

Makes sense, but it's possible on redis to set expiry to -1, so that a key never expires. Probably a rare case but these special cases will colide

@villebro
Copy link
Member Author

Makes sense, but it's possible on redis to set expiry to -1, so that a key never expires. Probably a rare case but these special cases will colide

@dpgaspar Oh, I thought 0 expiry on Redis made it never expire (that's what we're also claiming in one of the modals). Let me read up on docs + do testing and come back with a revised approach.

@dpgaspar
Copy link
Member

your right, sorry, got confused because of: https://redis.io/commands/ttl/ TTL = -1 when a key has no associated TTL.

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

LGTM

@villebro villebro merged commit 500d900 into apache:master Mar 31, 2023
@villebro villebro deleted the villebro/bypass-cache branch March 31, 2023 08:42
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.0.0 labels Mar 13, 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/M 🚢 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants