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

🔨 change CF thumbnail function to use chart configs from R2 #3867

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

danyx23
Copy link
Contributor

@danyx23 danyx23 commented Aug 13, 2024

This PR changes how the CF thumnail worker gets the config for a chart. It used to be the case that it would fetch the HTML file of the grapher page at the given slug and extract the config from that HTML. Now it looks up the grapher config json file in an R2 bucket.

This PR only changes this for published charts accessed by slug. A later PR will enable this also by UUID.

Cloudflare is a bit weird with the intersection of support of various features between CF workers/pages functions, R2 and local/remote dev support:

  • Initially I wanted to use bindings in CF functions. For local development, wrangler dev does not support using a remote R2 bucket which is annoying
  • I then thought I'd switch to fetching data from R2 buckets via HTTPS instead of bindings, similar to what we do with our variable data/metadata.json files. I realized then though that this only works if the bucket itself is accessible publicly via HTTPS. I'd like to keep the R2 bucket internal and not expose it directly.
  • My next approach was to try to use the S3 API in the CF pages function. This didn't work because the default AWS library doesn't work in CF functions and the simpler replacement libraries that I could find were very barebones and made you deal with XML manually
  • I then decided to go back to bindings and accepting the somewhat annoying dev story
  • But then I realized that once we get MDims, our data managers will want to make changes to charts and also to make changes to MDims and see their changes. If we fetch chart configs for MDims from CF functions in the future then on staging servers this would have been a painful story
  • So in the end I decided to make the R2 buckets accessible via the public internet and use fetch instead of R2 bindings.

To test this PR, the main change to your local setup is to add an entry to your .dev.vars example to specify the path within the staging R2 bucket to use for thumbnail rendering:

GRAPHER_CONFIG_R2_BUCKET_PATH=devs/YOURNAME

Before you can test the thumnail rendering locally for a particular chart, you will either have to edit one chart in the admin to make sure it gets uploaded to R2, or run the sync script in devTolls/syncGraphersToR2

This PR adds a few new env vars for CF functions:

  • GRAPHER_CONFIG_R2_BUCKET_URL - the primary bucket to read from
  • GRAPHER_CONFIG_R2_BUCKET_FALLBACK_URL - the fallback bucket to read from (this should be the prod bucket; on prod it should be empty)
  • GRAPHER_CONFIG_R2_BUCKET_FALLBACK_PATH - the path in the fallback bucket to read from (the path inside the prod bucket; on prod it should be empty)
  • GRAPHER_CONFIG_R2_BUCKET_PATH - in wrangler.toml we set this only for prod as it's constant there. For local dev setups it should be used from the .dev.vars as per above. Staging servers fall back to the branch name.

Copy link
Contributor Author

danyx23 commented Aug 13, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @danyx23 and the rest of your teammates on Graphite Graphite

@owidbot
Copy link
Contributor

owidbot commented Aug 13, 2024

Quick links (staging server):

Site Admin Wizard

Login: ssh owid@staging-site-use-r2-in-cf-functions

SVG tester:

Number of differences (default views): 0 ✅
Number of differences (all views): 0 ✅

Edited: 2024-09-09 14:51:24 UTC
Execution time: 1.37 seconds

@danyx23 danyx23 force-pushed the grapher-configs-in-r2 branch from 19cc89e to 3436339 Compare August 13, 2024 14:49
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from 87f0855 to 1eb1643 Compare August 13, 2024 14:49
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from 1eb1643 to 9ceb138 Compare August 13, 2024 16:36
@danyx23 danyx23 force-pushed the grapher-configs-in-r2 branch 2 times, most recently from 30197c7 to 1821c66 Compare August 13, 2024 16:55
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from 9ceb138 to e002f95 Compare August 13, 2024 16:55
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from e002f95 to 72aa0f2 Compare August 13, 2024 20:21
@danyx23 danyx23 force-pushed the grapher-configs-in-r2 branch from f683d47 to ca8b0ab Compare August 13, 2024 20:50
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from 72aa0f2 to da94610 Compare August 13, 2024 20:50
@danyx23 danyx23 marked this pull request as ready for review August 13, 2024 21:00
@danyx23 danyx23 force-pushed the grapher-configs-in-r2 branch from ca8b0ab to 5652f95 Compare August 15, 2024 15:00
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from da94610 to ff6fe4c Compare August 15, 2024 15:00
@danyx23 danyx23 changed the title 🔨 configure r2 bindings 🔨 change CF thumbnail function to use chart configs from R2 Aug 15, 2024
@danyx23 danyx23 force-pushed the grapher-configs-in-r2 branch from 5652f95 to 4ed3f88 Compare August 15, 2024 17:01
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch 3 times, most recently from b0d0d92 to 6474c78 Compare August 15, 2024 19:23
@danyx23 danyx23 requested a review from marcelgerber August 15, 2024 20:43
@danyx23 danyx23 force-pushed the grapher-configs-in-r2 branch from 691b7ea to 47ccc78 Compare September 5, 2024 12:13
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch 2 times, most recently from 4e65248 to 2a858eb Compare September 5, 2024 12:31
@danyx23 danyx23 force-pushed the grapher-configs-in-r2 branch from 47ccc78 to b6ffcc0 Compare September 5, 2024 18:36
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from 2a858eb to 1889cde Compare September 5, 2024 18:36
@danyx23 danyx23 force-pushed the grapher-configs-in-r2 branch from b6ffcc0 to c32a418 Compare September 9, 2024 09:33
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from 1889cde to fcfa4b2 Compare September 9, 2024 09:33
@danyx23 danyx23 force-pushed the grapher-configs-in-r2 branch from c32a418 to 64bf832 Compare September 9, 2024 11:53
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from fcfa4b2 to 38778bf Compare September 9, 2024 11:53
@danyx23 danyx23 changed the base branch from grapher-configs-in-r2 to graphite-base/3867 September 9, 2024 14:35
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from 38778bf to 6179fc0 Compare September 9, 2024 14:42
@danyx23 danyx23 changed the base branch from graphite-base/3867 to master September 9, 2024 14:43
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from 6179fc0 to 9565e1a Compare September 10, 2024 07:59
@danyx23 danyx23 changed the base branch from master to unify-r2-config-paths September 10, 2024 07:59
@danyx23 danyx23 force-pushed the unify-r2-config-paths branch from ca16a84 to 5f1f72a Compare September 10, 2024 08:05
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from 9565e1a to 51fd4ca Compare September 10, 2024 08:05
@danyx23 danyx23 force-pushed the unify-r2-config-paths branch from 5f1f72a to 7fe2699 Compare September 10, 2024 09:55
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from 51fd4ca to 8da3b43 Compare September 10, 2024 09:55
Base automatically changed from unify-r2-config-paths to master September 10, 2024 10:00
@danyx23 danyx23 force-pushed the use-r2-in-cf-functions branch from 8da3b43 to 884ec4c Compare September 10, 2024 10:23
Copy link
Contributor Author

danyx23 commented Sep 10, 2024

Merge activity

  • Sep 10, 6:33 AM EDT: @danyx23 started a stack merge that includes this pull request via Graphite.
  • Sep 10, 6:34 AM EDT: @danyx23 merged this pull request with Graphite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants