Skip to content

feat: front Cloud Run with the Cloudflare edge and request-based billing - #6

Merged
davidgamez merged 8 commits into
mainfrom
feat/edge-protection
Nov 26, 2026
Merged

davidgamez merged 8 commits into
mainfrom
feat/edge-protection

Conversation

@davidgamez

@davidgamez davidgamez commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Cuts GBFS validator costs and bot exposure: Cloud Run switches to request-based billing, sized from load tests (4 vCPU, 4 GiB, JVM heap 75%, 5 validations per instance, 90 s timeout; 20 instances in prod, 1 in dev/qa), adds the gbfs-edge-{env} invoker service account for the Cloudflare Worker, and turns off the built-in Swagger UI. The legacy load balancer stays behind legacy_load_balancer_enabled (default true) until the cutover; a follow-up change removes it. Limits and runbook: docs/edge-cutover.md.

Related: MobilityData/org-cloudflare-workers#19, MobilityData/gbfs-validator-java#211 (loader fix, needed before the cutover), MobilityData/gbfs-validator-java#210

🤖 Generated with Claude Code

davidgamez and others added 4 commits November 26, 2026 13:03
Replace the proxied DNS steps with the Custom Domain cutover, keep the
legacy load balancer IPs and certificate in the setup script until the
follow-up change, and note the run.app URL stays public until then.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run 5 validations per 2 GiB instance (4 in prod, 1 in dev/qa) with the
JVM heap at 75%, document limits and the load test, and switch prod to
the Worker after dev and qa.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidgamez
davidgamez marked this pull request as ready for review November 26, 2026 18:57
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fredericsimard

fredericsimard commented Nov 26, 2026 •

Copy link
Copy Markdown

@davidgamez Audit of this PR.

Audit

Nothing blocking. The dev apply (run 45873907791) planned 2 to add, 1 to change, 0 to destroy: the moved blocks kept the existing load balancer and invoker without recreating them. Findings below are for follow-up; nothing is being fixed in this PR yet.

Worth fixing

  1. The run.app URL is public during the cutover. Before this PR, ingress was INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER. Now ingress is INGRESS_TRAFFIC_ALL (infra/cloud-run-service/cloud-run-main.tf:57) and the allUsers invoker stays (infra/cloud-run-service/cloud-run-main.tf:108), so anyone can call run.app directly and skip both Cloud Armor and the Worker's checks until the follow-up change. The README acknowledges this and the 10-instance cap bounds the cost, but:
  2. The 60 s timeout is untested at 5 validations per instance. The timeout drops from 540 s to 60 s while one instance now runs 5 validations on 1 vCPU. The load test only measured memory (docs/edge-cutover.md:26), not latency. Five large feeds (8-12 MB) sharing one CPU could exceed 60 s and return 504s. Needs latency numbers at concurrency 5, or 2 vCPU, or a lower concurrency. Cheap extra: startup_cpu_boost = true shortens Spring Boot cold starts when scaling from 0.
  3. The runbook has no rollback. Step 3 (docs/edge-cutover.md:47) deletes the A/AAAA records, then merges the Worker PR. If the Worker deploy fails, the hostname stays down. The README no longer lists the load balancer IPs, so add a rollback step: recreate DNS-only (grey cloud) A/AAAA records pointing at {env}-lb-ipv4 / {env}-lb-ipv6.

Nits

  • Service account key: no rotation or expiry is documented. If wrangler fails in step 2 (docs/edge-cutover.md:43), the key is still created and left behind (check with gcloud iam service-accounts keys list). The key also lives in the shared mobilitydata-sites Worker, so every site's code there can read it; low risk, since it only grants roles/run.invoker on this one service.
  • Cleanup commands (docs/edge-cutover.md:63) only show dev; the qa and prod resource names are missing. Running scripts/setup-environment.sh again before the follow-up change recreates the billed IPs and certificate.
  • "Hard cost ceiling" comment (infra/cloud-run-service/cloud-run-main.tf:33) is overstated: the cap limits instances, not egress or logging, and Cloud Run can briefly exceed max instances during a rollout.
  • Rate limit in the limits table: "5/min" is per IP and per Cloudflare location (as MobilityData/org-cloudflare-workers#19 says), not a global per-IP limit.

Checked, no change needed

  • cpu_idle = true is required: once CPU and memory limits are set, Cloud Run defaults to instance-based billing.
  • SPRINGDOC_SWAGGERUI_ENABLED and SPRINGDOC_APIDOCS_ENABLED match Spring's relaxed binding, and the jar does ship springdoc 2.8.13.
  • MobilityData/org-cloudflare-workers#19 uses the same secret names (GBFS_VALIDATOR_<ENV>_URL, GBFS_VALIDATOR_<ENV>_SA_KEY) and the run.app URL as the ID token audience.
  • Provider 4.85.0 supports the new Cloud Run fields (dev applied them).

Run 10 validations per 4 vCPU / 4 GiB instance (5 in prod, 1 in
dev/qa) with a 90 s timeout and startup CPU boost. Runbook: budget
alerts before the cutover, rollback step, key cleanup and rotation,
cleanup for all environments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@fredericsimard fredericsimard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!

10 large feeds at once on 4 vCPU took up to 82 s against the 90 s
timeout on dev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidgamez
davidgamez merged commit abeba22 into main Nov 26, 2026
5 checks passed
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.

2 participants