Skip to content

Add Google Cloud Run worker identity/deployment helper - #1776

Draft
seanbollin wants to merge 1 commit into
mainfrom
cloud-run-worker-id
Draft

Add Google Cloud Run worker identity/deployment helper#1776
seanbollin wants to merge 1 commit into
mainfrom
cloud-run-worker-id

Conversation

@seanbollin

Copy link
Copy Markdown

What & why

The Python SDK already ships an AWS Lambda worker module (temporalio/contrib/aws/lambda_worker) that sets the worker "ID" for Lambda. This adds the equivalent capability for Google Cloud Run, covering both Cloud Run worker pools and services.

Cloud Run runs a long-lived container, so — unlike Lambda's per-invocation handler — there is nothing to wrap. This PR adds a small metadata helper module at temporalio/contrib/gcp/cloud_run. It's marked experimental.

What it does

get_google_cloud_run_metadata(), called once at worker startup:

  • resolves the deployment name from CLOUD_RUN_WORKER_POOL (worker pools) → K_SERVICE (services), and the revision from CLOUD_RUN_REVISIONK_REVISION, and
  • makes a single HTTP GET to the instance metadata server (http://metadata.google.internal/computeMetadata/v1/instance/id, header Metadata-Flavor: Google) for the unique instance id (available on both worker pools and services).

It returns a GoogleCloudRunMetadata exposing ready-to-pass values:

  • .worker_identity<instance_id>@<revision>, for Client.connect(..., identity=...); and
  • .worker_deployment_config → a WorkerDeploymentConfig(version=..., use_worker_versioning=True), for Worker(..., deployment_config=...).

(.worker_deployment_version is also exposed.)

Notes

  • Draft — opening early for design feedback. Naming/idiom (GoogleCloudRun-style, experimental marking) intentionally mirrors the coordinated Google Cloud Run effort already visible in the .NET SDK (Temporalio.Extensions.Gcp.CloudRun.OpenTelemetry).
  • No new runtime dependencies — uses only the standard library (urllib.request) for the HTTP call. worker_deployment_config uses a deferred import so identity-only use doesn't pull in the worker package.
  • No tests / OpenTelemetry companion yet (kept intentionally minimal).
  • Verified locally: ruff check, ruff format --check, pydocstyle, and mypy all clean. (A full import temporalio... needs the compiled Rust bridge, which isn't built in my sandbox; the module's logic was verified directly instead.)

🤖 Generated with Claude Code

Adds an experimental Google Cloud Run helper, mirroring the existing AWS
Lambda module's worker-ID behavior. Because Cloud Run runs a long-lived
container (unlike Lambda's per-invocation model), this is a metadata
helper rather than a worker wrapper: it reads the Cloud Run instance
metadata -- the instance id from the metadata server, plus the worker
pool/service name and revision from CLOUD_RUN_WORKER_POOL / CLOUD_RUN_REVISION
(worker pools) or K_SERVICE / K_REVISION (services) -- and derives a worker
identity and a WorkerDeploymentVersion to apply to a normal long-lived
worker. Covers both Cloud Run worker pools and services.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant