Skip to content

Use R2 bindings for grapher config CF functions (follow-up to #6132) - #6133

Merged
danyx23 merged 2 commits into
masterfrom
cf-use-r2-bindings
Mar 6, 2026
Merged

Use R2 bindings for grapher config CF functions (follow-up to #6132)#6133
danyx23 merged 2 commits into
masterfrom
cf-use-r2-bindings

Conversation

@danyx23

@danyx23 danyx23 commented Feb 20, 2026

Copy link
Copy Markdown
Member

Context

Follow-up to #6132.

PR #6132 (already merged) attempted to mitigate the issue by disabling HTTP caching on the R2 URL fetch path.
This PR is a separate follow-up branch created from master and switches grapher config reads in CF functions from HTTP requests to R2 bindings.

Description

This PR updates Cloudflare Functions grapher config loading to use R2 bucket bindings instead of fetching from https://grapher-configs*.owid.io/....

What changed:

  • functions/_common/grapherTools.ts
    • Replace URL-based fetch() reads with R2Bucket.get() reads.
    • Preserve conditional fetch behavior using If-None-Match (onlyIf) so 304 can still be returned.
    • Keep primary + fallback lookup behavior, now via primary/fallback R2 bindings.
    • Preserve key construction with configured path prefixes (GRAPHER_CONFIG_R2_BUCKET_PATH, GRAPHER_CONFIG_R2_BUCKET_FALLBACK_PATH).
  • functions/_common/env.ts
    • Add R2 binding env types for grapher configs.
    • Keep URL env vars present for possible rollback/experimentation.
  • wrangler.jsonc
    • Add GRAPHER_CONFIG_R2_BUCKET and GRAPHER_CONFIG_R2_BUCKET_FALLBACK bindings for default/preview/production.
    • Set grapher-config bindings to "remote": true for local dev so Wrangler reads from real buckets instead of empty local emulation.
    • Keep existing URL vars in config.

Expected effect:

  • Avoid Cloudflare internal HTTP cache behavior on the R2 URL fetch path.
  • Read config objects directly through R2 bindings while preserving status semantics (200/304/404).

Screenshots / Videos / Diagrams

None (no UI changes).

Testing guidance

  1. Start local CF functions (yarn startLocalCloudflareFunctions).
  2. Request a known config endpoint, e.g. /grapher/life-expectancy.config.json.
  3. Verify config is served from binding-backed lookup and returns expected status codes.
  4. Optionally test with If-None-Match to verify 304 behavior.

Automated checks run:

  • yarn fixPrettierChanged > /dev/null 2>&1 && yarn typecheck

  • yarn testLintChanged

  • yarn testPrettierChanged

  • Does the change work in the archive?

  • Does the staging experience have sign-off from product stakeholders?

Checklist

Before merging

  • Google Analytics events were adapted to fit the changes in this PR
  • Changes to CSS/HTML were checked on Desktop and Mobile Safari at all three breakpoints
  • Changes to HTML were checked for accessibility concerns

@owidbot

owidbot commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Quick links (staging server):

Site Dev Site Preview Admin Wizard Docs

Login: ssh owid@staging-site-cf-use-r2-bindings

Archive:
SVG tester:

Number of differences (graphers): 0 ✅
Number of differences (grapher views): skipped
Number of differences (mdims): skipped
Number of differences (explorers): skipped

Edited: 2026-02-20 20:56:41 UTC
Execution time: 1.22 seconds

@ikesau ikesau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm! etag and no etag paths both work locally :)

Comment thread functions/_common/grapherTools.ts Outdated
key: string,
etag: string | undefined,
fallbackUrl?: URL,
_shouldCache: boolean = true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

_shouldCache should be completely removed now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call — removed _shouldCache and all related plumbing from fetchFromR2/fetchUnparsedGrapherConfig so no dead cache arg remains.

Comment thread functions/_common/env.ts Outdated
@@ -3,8 +3,10 @@ export interface Env {
url: URL
GRAPHER_CONFIG_R2_BUCKET_URL: string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These 2 vars can be removed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, removed both URL vars from Env and from wrangler.jsonc (vars, preview.vars, and production.vars) since config fetch now uses R2 bindings directly.

@danyx23
danyx23 force-pushed the cf-use-r2-bindings branch from 48c5da7 to db84509 Compare March 6, 2026 06:22

danyx23 commented Mar 6, 2026

Copy link
Copy Markdown
Member Author

danyx23 commented Mar 6, 2026

Copy link
Copy Markdown
Member Author

Merge activity

  • Mar 6, 1:07 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Mar 6, 1:08 PM UTC: Graphite rebased this pull request as part of a merge.
  • Mar 6, 1:09 PM UTC: @danyx23 merged this pull request with Graphite.

@danyx23
danyx23 force-pushed the cf-use-r2-bindings branch from 17144b3 to 4f89742 Compare March 6, 2026 13:08
@danyx23
danyx23 merged commit 1481fd4 into master Mar 6, 2026
22 of 24 checks passed
@danyx23
danyx23 deleted the cf-use-r2-bindings branch March 6, 2026 13:09
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