Add Google Cloud Run worker identity plugin - #1776
Open
seanbollin wants to merge 13 commits into
Open
Conversation
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>
The worker-side apply helper enabled versioning and set the deployment version but left the default versioning behavior unset, so a versioned worker with a plain (un-annotated) workflow failed to register. Default it to PINNED; a per-workflow versioning behavior still takes precedence. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Cover the temporalio.contrib.gcp.cloud_run helper: - Environment precedence for the deployment name (CLOUD_RUN_WORKER_POOL over K_SERVICE) and revision (CLOUD_RUN_REVISION over K_REVISION). - Worker identity formatting and its revision -> name -> instance-id fallbacks. - WorkerDeploymentVersion derivation and its ValueError when name/revision empty. - WorkerDeploymentConfig enabling worker versioning with PINNED default behavior. - The metadata HTTP fetch via a local in-process server: asserts the Metadata-Flavor: Google header is sent, the body is trimmed, and a clear RuntimeError is raised on non-200 and unreachable responses. Uses the helper's dependency-injection seams (getenv and metadata_url) so no real environment or network access is required. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
seanbollin
marked this pull request as ready for review
August 26, 2026 19:37
Re-architect the Cloud Run worker-ID helper into a plugin mirroring the SDK's OpenTelemetry Cloud Run plugin. CloudRunPlugin subclasses temporalio.plugin.SimplePlugin and is registered once on the client via Client.connect(plugins=[...]); it propagates to workers automatically. The plugin fetches Cloud Run instance metadata lazily at client connect and caches it, then sets the client identity (only when the caller did not provide one) and configures the worker with a PINNED WorkerDeploymentConfig derived from the Cloud Run revision. Connecting off Cloud Run fails fast with a clear error. The GoogleCloudRunMetadata dataclass and its worker_identity / worker_deployment_version / worker_deployment_config properties are kept for advanced and non-plugin use. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Cloud Run can host multiple plugins (a worker-ID plugin and an
OpenTelemetry plugin both live in the same cloud_run area), so the
worker-ID plugin needs a specific name rather than the generic
CloudRunPlugin.
- Rename class CloudRunPlugin -> WorkerIDPlugin and move
_plugin.py -> _worker_id_plugin.py (cloud_run package and
GoogleCloudRunMetadata unchanged).
- Update the package __init__ export/__all__, quick-start, and README.
- Rename test_plugin.py -> test_worker_id_plugin.py and fix the
basedpyright reportInvalidCast errors by constructing WorkerConfig()
instead of cast(WorkerConfig, {}); silence reportUnusedParameter on
the unused connect() callbacks.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Relocate the Google Cloud Run worker-ID plugin from directly inside
temporalio/contrib/gcp/cloud_run/ into a new worker_id/ sub-package so it
owns its own __init__.py and README.md. This avoids a hard collision with
the separate OTel Cloud Run plugin, which also owns cloud_run/README.md and
cloud_run/__init__.py; after the move the two plugins share only the
minimal cloud_run/ and gcp/ namespace-marker __init__.py files.
The public names are unchanged; only the import path gains .worker_id:
from temporalio.contrib.gcp.cloud_run.worker_id import WorkerIDPlugin
cloud_run/__init__.py is reduced to a minimal namespace-marker docstring
with no worker-ID exports. Mirrors the Go (contrib/gcp/cloudrun/workerid)
and .NET (CloudRun.WorkerId) layouts.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Satisfies the changelog checkpoint, which requires a user-facing change to add an entry under Unreleased in a CHANGELOG.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Reduce temporalio/contrib/gcp/__init__.py and temporalio/contrib/gcp/cloud_run/__init__.py to the same generic namespace markers used by the Cloud Run OpenTelemetry PR, so both PRs add byte-identical files and merge into main without an add/add conflict. The worker_id plugin imports from cloud_run.worker_id, so this docstring-only change to the cloud_run root is safe. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Drop all Worker Deployment Versioning from the Cloud Run WorkerID plugin so it only sets the worker identity from Cloud Run instance metadata. - Remove the worker_deployment_version and worker_deployment_config (PINNED) properties from GoogleCloudRunMetadata, plus the now-unused WorkerDeploymentVersion, WorkerDeploymentConfig, and VersioningBehavior imports. - Remove WorkerIDPlugin.configure_worker (which set deployment_config); the plugin no longer overrides the worker configurator. The client hook still sets the identity when unset or equal to the SDK pid@host default, and the worker inherits it. - Update tests, docstrings, README, and the CHANGELOG entry to identity-only wording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Bring the branch up to date with main (clean merge; only CHANGELOG.md auto-merged). Clears a stale GitHub mergeability flag. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The plugin sets only the worker identity, so describe the Cloud Run metadata as the worker pool/service name and revision rather than a Temporal deployment name and build ID. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Bring the branch up to date with main and clear the stale mergeability state blocking CI. Clean merge (CHANGELOG.md auto-merged); worker_id module unchanged. 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
Adds an experimental Google Cloud Run worker-identity plugin — the Cloud Run counterpart to the SDK's AWS Lambda worker support — for both Cloud Run worker pools and services. Cloud Run runs a long-lived container, so this is a small client plugin rather than a worker wrapper.
What it does
Register
WorkerIDPluginon your client:When the client connects, the plugin reads the current Cloud Run instance's metadata — the revision (
CLOUD_RUN_REVISION/K_REVISION), the worker pool or service name (CLOUD_RUN_WORKER_POOL/K_SERVICE), and the unique instance id from the metadata server (http://metadata.google.internal/computeMetadata/v1/instance/id) — and sets the client identity to<instance_id>@<revision>when one isn't already configured. Workers created from that client inherit it.get_google_cloud_run_metadata()/GoogleCloudRunMetadataare exposed for reading the values directly. Experimental.🤖 Generated with Claude Code