Skip to content

Add Cloud Run worker-ID sample - #531

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

Add Cloud Run worker-ID sample#531
seanbollin wants to merge 3 commits into
mainfrom
cloud-run-worker-id

Conversation

@seanbollin

Copy link
Copy Markdown

What

Adds a Cloud Run worker-ID sample (cloud-run-worker-id/) that mirrors the existing
lambda-worker/ sample. It runs a long-running Temporal worker on Google Cloud Run and uses the new
go.temporal.io/sdk/contrib/gcp/cloudrun helper to
derive, from the Cloud Run instance metadata at startup:

  • a client identity of <instanceID>@<revision> (with @<name> / bare-<instanceID> fallbacks), and
  • a Worker Deployment Version of (deploymentName=name, buildID=revision), with a PINNED
    default versioning behavior.

It reads TEMPORAL_ADDRESS / TEMPORAL_NAMESPACE / TEMPORAL_TASK_QUEUE (plaintext connection),
registers a small greeting workflow + activity, and shuts down gracefully on SIGTERM. The README
explains Cloud Run worker pools and deployment via gcloud run worker-pools deploy.

Files

  • cloud-run-worker-id/worker/main.go — the worker (FetchMetadata → ApplyToClientOptions / ApplyToWorkerOptions)
  • cloud-run-worker-id/starter/main.go — starts a workflow against it
  • cloud-run-worker-id/greeting/{workflow,activity}.go — sample workflow + activity
  • cloud-run-worker-id/{Dockerfile,README.md}

Draft: temporary dependency wiring

The cloudrun contrib module is unreleased (see sdk-go #2599), so go.mod carries a temporary
local replace:

replace go.temporal.io/sdk/contrib/gcp/cloudrun => ../sdk-go-2/contrib/gcp/cloudrun
  • The helper compiles against the released go.temporal.io/sdk (v1.48.0), so no go.temporal.io/sdk
    replace is needed and go.sum is unchanged. Adding the dependency does raise the module's go
    directive to 1.26 (the contrib module targets Go 1.26).
  • A container/--source build cannot reach the sibling ../sdk-go-2, so the Dockerfile / deploy build
    only work once the module is published and the replace is removed.

This PR must stay a draft until the cloudrun module is released, at which point the replace is
dropped and the require switched to the released version.

Verified locally: go build, go vet, and gofmt -l are clean for ./cloud-run-worker-id/....

Note for reviewers: overlap with the OpenTelemetry Cloud Run sample

There is a separate, parallel effort on branch gcp-cloud-run-otel that adds a cloud-run-worker/
sample demonstrating the cloudrun OpenTelemetry plugin. This PR is a different sample
(worker identity + deployment versioning) and deliberately uses a distinct directory name
(cloud-run-worker-id/) to avoid collision. If both land, we may want to reconcile naming or fold the
two into one Cloud Run sample directory.

🤖 Generated with Claude Code

seanbollin and others added 3 commits August 25, 2026 13:43
Mirror the lambda-worker sample for Google Cloud Run: a long-running worker that
uses the go.temporal.io/sdk/contrib/gcp/cloudrun helper to derive its identity
(<instanceID>@<revision>) and Worker Deployment Version (name + revision) from
the Cloud Run instance metadata at startup, pinning workflows to that version by
default. It reads TEMPORAL_ADDRESS/TEMPORAL_NAMESPACE/TEMPORAL_TASK_QUEUE
(plaintext), registers a greeting workflow + activity, and stops gracefully on
SIGTERM. The README explains Cloud Run worker pools and deployment via
`gcloud run worker-pools deploy`.

The cloudrun contrib module is unreleased, so go.mod carries a TEMPORARY local
replace to ../sdk-go-2/contrib/gcp/cloudrun (the helper compiles against the
released SDK, so no SDK replace is needed; the new dependency does raise the
module go directive to 1.26). The replace must be dropped once the module is
released, hence this PR is a draft.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Update the Cloud Run worker sample to register cloudrun.Plugin on the client
instead of calling the removed Metadata.ApplyToClientOptions/ApplyToWorkerOptions
methods. The plugin fetches the instance metadata at connect time, sets the
worker identity, and pins the worker's deployment version; the sample reads the
resolved metadata back via plugin.Metadata() for logging.

Bump go.temporal.io/api to v1.63.5 (go mod tidy) as required by the updated
contrib/gcp/cloudrun module.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The Cloud Run worker-ID plugin moved from module
go.temporal.io/sdk/contrib/gcp/cloudrun to
go.temporal.io/sdk/contrib/gcp/cloudrun/workerid (Go package cloudrun ->
workerid) so the cloudrun directory can also host the OpenTelemetry
plugin without a package collision. Follow that here:

- import go.temporal.io/sdk/contrib/gcp/cloudrun/workerid and use
  workerid.NewPlugin / workerid.PluginOptions in worker/main.go
- point the go.mod require and local replace at the new module path
- update the README and Dockerfile references

go build and go vet pass against the in-repo module.

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