Add Google Cloud Run worker-identity sample - #356
Draft
seanbollin wants to merge 6 commits into
Draft
Conversation
Add a runnable sample that runs a long-lived Temporal Worker in a Google Cloud Run worker pool and uses temporalio.contrib.gcp.cloud_run to derive the worker identity and a PINNED Worker Deployment version from Cloud Run instance metadata. The sample registers a small greeting Workflow and Activity, reads TEMPORAL_ADDRESS / TEMPORAL_NAMESPACE / TEMPORAL_TASK_QUEUE (plaintext or, with TEMPORAL_API_KEY, Temporal Cloud over TLS), and runs until Cloud Run sends SIGTERM. The sample is standalone and excluded from the root project's build/lint/type tooling, mirroring the lambda_worker sample. The Cloud Run metadata helper is not released yet, so pyproject.toml pins temporalio to the local SDK checkout (../../sdk-python-2) on the cloud-run-worker-id branch; the README and Dockerfile note this must be dropped for a released (or git-pinned) temporalio once the helper ships. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Register temporalio.contrib.gcp.cloud_run.CloudRunPlugin on the client via Client.connect(plugins=[...]) instead of manually fetching metadata and passing identity= and deployment_config=. The plugin sets the client identity and the PINNED worker deployment config from Cloud Run instance metadata and propagates to the worker automatically. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The SDK renamed the generic CloudRunPlugin to WorkerIDPlugin (Cloud Run can host multiple plugins). Update the sample's worker, README, and the pyproject comment to match the new class name. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The plugin moved from temporalio.contrib.gcp.cloud_run into the
temporalio.contrib.gcp.cloud_run.worker_id sub-package (to avoid a
collision with the OTel Cloud Run plugin). Update the sample's import,
docstring, README doc link, and pyproject comment to the new path:
from temporalio.contrib.gcp.cloud_run.worker_id import WorkerIDPlugin
The public name WorkerIDPlugin is unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ub versioning Move gcp_cloud_run_worker_id/* into gcp/cloud_run/worker_id/ to mirror the sibling OpenTelemetry Cloud Run sample layout, add the gcp / gcp.cloud_run / gcp.cloud_run.worker_id namespace packages (the two parents byte-identical to the OTel sample's), and mirror the tests/gcp/cloud_run/worker_id/ structure. WorkerIDPlugin is now identity-only, so remove every Worker Deployment Versioning reference (deployment name/config, build id, PINNED, versioning behavior) from the sample. It now registers WorkerIDPlugin() and shows the worker identity via get_google_cloud_run_metadata().worker_identity. Switch the sample to package-qualified imports and run the worker/starter as modules (python -m ...), matching the OTel sample's Dockerfile, and stop excluding the sample from ruff/mypy/setuptools now that it lives in the gcp package tree. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Runnable Google Cloud Run worker-identity sample, laid out under
gcp/cloud_run/worker_id/to match the sibling OpenTelemetry Cloud Run sample (gcp/cloud_run/opentelemetry/). It registersWorkerIDPlugin()on the client so the worker identity ({instanceId}@{revision}) is set from Cloud Run instance metadata; a greeting Workflow/Activity and a starter demonstrate a normal long-lived Worker on a Cloud Run worker pool. No Worker Deployment Versioning — identity only.worker.py— registersWorkerIDPlugin(), runs a long-lived Worker until Cloud Run sendsSIGTERM, and logs the identity viaget_google_cloud_run_metadata().worker_identity.workflows.py/activities.py— a small greeting Workflow + Activity.settings.py— readsTEMPORAL_ADDRESS/TEMPORAL_NAMESPACE/TEMPORAL_TASK_QUEUE(plaintext), with optionalTEMPORAL_API_KEYfor Temporal Cloud (TLS).starter.py— starts the Workflow from a local machine.Dockerfile/.dockerignore— container build forgcloud run worker-pools deploy.README.md— explains Cloud Run worker pools and the deploy flow.The
gcp/__init__.pyandgcp/cloud_run/__init__.pynamespace packages are byte-identical to the OpenTelemetry sample's so the two samples merge cleanly, andtests/gcp/cloud_run/worker_id/mirrors the OTel test layout.Run
See
gcp/cloud_run/worker_id/README.mdfor the fullgcloud run worker-pools deployflow; start a Workflow locally from the repo root withuv run python -m gcp.cloud_run.worker_id.starter.Draft — depends on an unreleased helper
The Cloud Run metadata helper is not released yet (SDK PR: temporalio/sdk-python#1776). To keep this sample runnable,
pyproject.tomlpinstemporalioto a local path source (../../../../sdk-python-2) on thecloud-run-worker-idbranch. This[tool.uv.sources]override must be dropped (in favor of a releasedtemporalio) once the helper ships; the README and Dockerfile call this out. The local path is not available inside a Docker build context, so the container build must use a released or git-referencedtemporalio(documented in theDockerfile).Verification
ruff checkandruff format --checkpass on the sample;mypyis clean.WorkerIDPlugin,get_google_cloud_run_metadata).python -m py_compilepasses, andtests/gcp/cloud_run/worker_id/workflow_test.pyis collected by pytest.🤖 Generated with Claude Code