Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ to include examples, links to docs, or any other relevant information.

### Added

- Added the `temporalio.contrib.gcp.cloud_run.id` module plugin to help set the worker identity on Cloud Run.
- Added the `temporalio.contrib.gcp.cloud_run.id` module with the `CloudRunIdPlugin` client plugin to set the worker identity on Cloud Run.
### Changed

### Deprecated
Expand Down
12 changes: 6 additions & 6 deletions temporalio/contrib/gcp/cloud_run/id/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> ⚠️ **This package is currently at an experimental release stage.** ⚠️

A plugin for running [Temporal](https://temporal.io) workers on Google Cloud Run. `CloudRunIDPlugin`
A plugin for running [Temporal](https://temporal.io) workers on Google Cloud Run. `CloudRunIdPlugin`
reads Cloud Run instance metadata and sets the client identity. Both Cloud Run **worker pools** and
**services** are supported.

Expand All @@ -15,7 +15,7 @@ derived from the Cloud Run instance (unless you already passed an `identity`).
import asyncio

from temporalio.client import Client
from temporalio.contrib.gcp.cloud_run.id import CloudRunIDPlugin
from temporalio.contrib.gcp.cloud_run.id import CloudRunIdPlugin
from temporalio.worker import Worker

from my_workflows import MyWorkflow
Expand All @@ -26,7 +26,7 @@ async def main() -> None:
# Install the plugin on the client; it propagates to workers automatically.
client = await Client.connect(
"localhost:7233",
plugins=[CloudRunIDPlugin()],
plugins=[CloudRunIdPlugin()],
)

worker = Worker(
Expand Down Expand Up @@ -55,7 +55,7 @@ the
at `http://metadata.google.internal/computeMetadata/v1/instance/id`, which requires the
`Metadata-Flavor: Google` request header.

When the client connects, `CloudRunIDPlugin` resolves the worker pool name from
When the client connects, `CloudRunIdPlugin` resolves the worker pool name from
`CLOUD_RUN_WORKER_POOL` (falling back to the service name `K_SERVICE`) and the revision from
`CLOUD_RUN_REVISION` (falling back to
`K_REVISION`), then performs a single synchronous HTTP GET to the metadata server for the instance
Expand All @@ -74,10 +74,10 @@ For advanced scenarios or unit tests you can bypass the metadata server by passi
metadata object, or steer the fetch with `getenv` / `metadata_url` / `timeout`:

```python
from temporalio.contrib.gcp.cloud_run.id import CloudRunIDPlugin, get_google_cloud_run_metadata
from temporalio.contrib.gcp.cloud_run.id import CloudRunIdPlugin, get_google_cloud_run_metadata

metadata = get_google_cloud_run_metadata()
plugin = CloudRunIDPlugin(metadata=metadata)
plugin = CloudRunIdPlugin(metadata=metadata)

# metadata.identity exposes the same value the plugin applies, for use
# without the plugin if needed.
Expand Down
10 changes: 5 additions & 5 deletions temporalio/contrib/gcp/cloud_run/id/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"""Run Temporal workers on Google Cloud Run.

:py:class:`CloudRunIDPlugin` reads Cloud Run instance metadata (from a worker pool or a service) and
:py:class:`CloudRunIdPlugin` reads Cloud Run instance metadata (from a worker pool or a service) and
sets the client identity from the Cloud Run instance.

Quick start::

import asyncio

from temporalio.client import Client
from temporalio.contrib.gcp.cloud_run.id import CloudRunIDPlugin
from temporalio.contrib.gcp.cloud_run.id import CloudRunIdPlugin
from temporalio.worker import Worker

async def main() -> None:
# Install the plugin on the client; it propagates to workers automatically.
client = await Client.connect(
"localhost:7233",
plugins=[CloudRunIDPlugin()],
plugins=[CloudRunIdPlugin()],
)

worker = Worker(
Expand All @@ -29,7 +29,7 @@ async def main() -> None:
asyncio.run(main())
"""

from temporalio.contrib.gcp.cloud_run.id._cloud_run_id_plugin import CloudRunIDPlugin
from temporalio.contrib.gcp.cloud_run.id._cloud_run_id_plugin import CloudRunIdPlugin
from temporalio.contrib.gcp.cloud_run.id._metadata import (
CLOUD_RUN_METADATA_URL,
GoogleCloudRunMetadata,
Expand All @@ -39,6 +39,6 @@ async def main() -> None:
__all__ = [
"CLOUD_RUN_METADATA_URL",
"GoogleCloudRunMetadata",
"CloudRunIDPlugin",
"CloudRunIdPlugin",
"get_google_cloud_run_metadata",
]
4 changes: 2 additions & 2 deletions temporalio/contrib/gcp/cloud_run/id/_cloud_run_id_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from temporalio.service import ConnectConfig, ServiceClient


class CloudRunIDPlugin(temporalio.plugin.SimplePlugin):
class CloudRunIdPlugin(temporalio.plugin.SimplePlugin):
"""Set a Temporal client's identity from Google Cloud Run instance metadata.

Install this plugin once when connecting the client; the identity it sets
Expand Down Expand Up @@ -58,7 +58,7 @@ def __init__(
``os.environ.get`` and exists primarily for testing. Ignored when
``metadata`` is supplied.
"""
super().__init__("CloudRunIDPlugin")
super().__init__("CloudRunIdPlugin")
self._metadata = metadata
self._timeout = timeout
self._metadata_url = metadata_url
Expand Down
12 changes: 6 additions & 6 deletions tests/contrib/gcp/cloud_run/id/test_cloud_run_id_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pytest

from temporalio.contrib.gcp.cloud_run.id import (
CloudRunIDPlugin,
CloudRunIdPlugin,
GoogleCloudRunMetadata,
)
from temporalio.service import ConnectConfig, ServiceClient
Expand Down Expand Up @@ -48,7 +48,7 @@ def _service_client() -> ServiceClient:
class TestClientIdentity:
@pytest.mark.asyncio
async def test_sets_identity_when_unset(self) -> None:
plugin = CloudRunIDPlugin(
plugin = CloudRunIdPlugin(
metadata=_metadata(instance_id="abc", revision="rev-1")
)
# ConnectConfig auto-fills identity with <pid>@<hostname> when none is given.
Expand All @@ -65,7 +65,7 @@ async def connect(input: ConnectConfig) -> ServiceClient:

@pytest.mark.asyncio
async def test_preserves_caller_identity(self) -> None:
plugin = CloudRunIDPlugin(
plugin = CloudRunIdPlugin(
metadata=_metadata(instance_id="abc", revision="rev-1")
)
config = ConnectConfig(target_host="localhost:7233", identity="my-identity")
Expand All @@ -85,14 +85,14 @@ async def connect(input: ConnectConfig) -> ServiceClient:
class TestMetadataFetch:
def test_construction_does_not_fetch(self) -> None:
# A bad metadata URL must not raise at construction -- the fetch is lazy.
CloudRunIDPlugin(
CloudRunIdPlugin(
metadata_url=f"http://127.0.0.1:{_closed_port()}/instance/id",
getenv={}.get, # type: ignore[arg-type]
)

@pytest.mark.asyncio
async def test_connect_fails_fast_off_platform(self) -> None:
plugin = CloudRunIDPlugin(
plugin = CloudRunIdPlugin(
timeout=1.0,
metadata_url=f"http://127.0.0.1:{_closed_port()}/instance/id",
getenv={}.get, # type: ignore[arg-type]
Expand All @@ -114,7 +114,7 @@ async def test_metadata_fetched_from_server_at_connect(
"temporalio.contrib.gcp.cloud_run.id._cloud_run_id_plugin.get_google_cloud_run_metadata",
fetch,
)
plugin = CloudRunIDPlugin()
plugin = CloudRunIdPlugin()
config = ConnectConfig(target_host="localhost:7233")

async def connect(_input: ConnectConfig) -> ServiceClient:
Expand Down
Loading