Skip to content

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

Draft
seanbollin wants to merge 5 commits into
mainfrom
cloud-run-worker-id
Draft

Add Google Cloud Run worker identity/deployment helper#3028
seanbollin wants to merge 5 commits into
mainfrom
cloud-run-worker-id

Conversation

@seanbollin

Copy link
Copy Markdown

What & why

The Java SDK already ships an AWS Lambda contrib module (contrib/temporal-aws-lambda) 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 contrib/temporal-gcp-cloud-run (registered in settings.gradle, mirroring the Lambda module). It's marked @Experimental.

What it does

GoogleCloudRunMetadata.fetch(), 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 with fluent applyTo(...) overloads you drop into your normal, long-lived worker:

  • metadata.applyTo(WorkflowClientOptions.newBuilder()) → sets identity to <instanceId>@<revision>; and
  • metadata.applyTo(WorkerOptions.newBuilder()) → enables Worker Deployment Versioning with new WorkerDeploymentVersion(<name>, <revision>).

(workerIdentity() / workerDeploymentVersion() accessors are also exposed.)

Notes

  • Draft — opening early for design feedback. Naming/idiom (GoogleCloudRun-style, "apply defaults to your options", @Experimental) intentionally mirrors the coordinated Google Cloud Run effort already visible in the .NET SDK (Temporalio.Extensions.Gcp.CloudRun.OpenTelemetry).
  • No new runtime dependencies — compileOnly project(':temporal-sdk') plus the JDK's HttpURLConnection (Java 8-compatible).
  • No tests / OpenTelemetry companion yet (kept intentionally minimal).
  • ⚠️ Local-build note: I could not run ./gradlew in my environment — only JDK 25 is installed, and the repo's pinned Gradle 8.10.2 cannot compile build scripts on JDK 25 (no JDK 21/23 available, and I did not install one). The source was verified by compiling standalone with the SDK's exact --release 8 -Werror flags against stubs (clean), by checking every temporal-sdk API symbol used against the real sources, and by manually checking google-java-format compliance. Please run ./gradlew :temporal-gcp-cloud-run:spotlessApply :temporal-gcp-cloud-run:compileJava on a supported JDK before un-drafting.

🤖 Generated with Claude Code

seanbollin and others added 3 commits August 21, 2026 12:22
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 Cloud Run metadata helper: environment-variable precedence
(CLOUD_RUN_WORKER_POOL over K_SERVICE, CLOUD_RUN_REVISION over
K_REVISION), worker identity fallbacks, WorkerDeploymentVersion mapping
and its empty name/revision error, the metadata HTTP request
(Metadata-Flavor: Google header, body trimming, non-200 and unreachable
errors), and the applyTo(...) methods (client identity, and PINNED
worker deployment versioning).

The metadata request is served by an in-process com.sun.net.httpserver
HttpServer and the environment lookup is injected through a new
package-private fetch(String, Duration, Function) test seam, so the
tests touch neither the network nor the real process environment. The
seam is not part of the public API and does not change public behavior.

Add the matching testImplementation dependencies (temporal-sdk, junit)
to the module, mirroring the temporal-aws-lambda module.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
seanbollin and others added 2 commits August 25, 2026 14:19
new URL(String) is deprecated since Java 20 and fails the SDK's -Werror
build on newer JDKs (the Java 23 "Edge" CI job). Use URI.create(...).toURL()
instead, the recommended non-deprecated replacement (MalformedURLException
is still an IOException and stays caught).

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