Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'bianca-worker-guide' of https://github.com/biancaines/p…
Browse files Browse the repository at this point in the history
…refect-gcp into bianca-worker-guide
  • Loading branch information
biancaines committed Oct 3, 2023
2 parents 0ac25f6 + fdb0509 commit a3c5ea7
Show file tree
Hide file tree
Showing 27 changed files with 982 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/add-to-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Add issue to project
runs-on: ubuntu-latest
steps:
- uses: tibdex/github-app-token@v1
- uses: tibdex/github-app-token@v2
id: generate-token
name: Generate GitHub token
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-dev-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- "3.10"
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Build Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
persist-credentials: false

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/template-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: Submit update PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
Expand All @@ -22,7 +22,7 @@ jobs:
- name: Perform updates
run: cruft update -y

- uses: tibdex/github-app-token@v1
- uses: tibdex/github-app-token@v2
id: generate-token
name: Generate GitHub token
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- "3.10"
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_extras.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- "aiplatform"
fail-fast: true
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- "3.9"
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix `list_folders` and `list_blobs` now logging bucket name and bucket path - [#184](https://github.com/PrefectHQ/prefect-gcp/pull/214)

### Security

## 0.4.7

Released September 22nd, 2023.

### Added

- Vertex AI `CustomJob` worker - [#211](https://github.com/PrefectHQ/prefect-gcp/pull/211)
- Add `kill_infrastructure` method to Vertex AI worker - [#213](https://github.com/PrefectHQ/prefect-gcp/pull/213)

### Changed

- Use flow run name for name of created custom jobs - [#208](https://github.com/PrefectHQ/prefect-gcp/pull/208)

## 0.4.6

Not yet released
Released September 5th, 2023.

### Changed

- Vertex AI CustomJob sets labels specified by Prefect Agent when Deployment triggered on infrastructure.
- Persist Labels to Vertex AI Custom Job - [#198](https://github.com/PrefectHQ/prefect-gcp/pull/208)

## 0.4.5

Expand Down
1 change: 1 addition & 0 deletions docs/cloud_run_worker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: prefect_gcp.workers.cloud_run
1 change: 1 addition & 0 deletions docs/vertex_worker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: prefect_gcp.workers.vertex
1 change: 0 additions & 1 deletion docs/worker.md

This file was deleted.

4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ nav:
- Cloud Run: cloud_run.md
- AI Platform: aiplatform.md
- Deployment Steps: deployments/steps.md
- Worker: worker.md
- Workers:
- Cloud Run: cloud_run_worker.md
- Vertex AI: vertex_worker.md

extra:
social:
Expand Down
20 changes: 12 additions & 8 deletions prefect_gcp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
from . import _version
from prefect._internal.compatibility.deprecated import (
register_renamed_module,
)

from .bigquery import BigQueryWarehouse # noqa
from . import _version
from .aiplatform import VertexAICustomTrainingJob # noqa
from .cloud_storage import GcsBucket # noqa
from .bigquery import BigQueryWarehouse # noqa
from .cloud_run import CloudRunJob # noqa
from .secret_manager import GcpSecret # noqa
from .cloud_storage import GcsBucket # noqa
from .credentials import GcpCredentials # noqa
from .worker import CloudRunWorker # noqa
from prefect._internal.compatibility.deprecated import (
register_renamed_module,
)
from .secret_manager import GcpSecret # noqa
from .workers.vertex import VertexAIWorker # noqa
from .workers.cloud_run import CloudRunWorker # noqa

register_renamed_module(
"prefect_gcp.projects", "prefect_gcp.deployments", start_date="Jun 2023"
)
register_renamed_module(
"prefect_gcp.worker", "prefect_gcp.workers", start_date="Sep 2023"
)


__version__ = _version.get_versions()["version"]
11 changes: 4 additions & 7 deletions prefect_gcp/aiplatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class VertexAICustomTrainingJob(Infrastructure):

_block_type_name = "Vertex AI Custom Training Job"
_block_type_slug = "vertex-ai-custom-training-job"
_logo_url = "https://images.ctfassets.net/gm98wzqotmnx/4CD4wwbiIKPkZDt4U3TEuW/c112fe85653da054b6d5334ef662bec4/gcp.png?h=250" # noqa
_logo_url = "https://cdn.sanity.io/images/3ugk85nk/production/10424e311932e31c477ac2b9ef3d53cefbaad708-250x250.png" # noqa
_documentation_url = "https://prefecthq.github.io/prefect-gcp/aiplatform/#prefect_gcp.aiplatform.VertexAICustomTrainingJob" # noqa: E501

type: Literal["vertex-ai-custom-training-job"] = Field(
Expand Down Expand Up @@ -184,7 +184,6 @@ class VertexAICustomTrainingJob(Infrastructure):
"and required if a service account cannot be detected in gcp_credentials."
),
)

job_watch_poll_interval: float = Field(
default=5.0,
description=(
Expand All @@ -200,17 +199,14 @@ def job_name(self):
https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform.CustomJob#google_cloud_aiplatform_CustomJob_display_name
""" # noqa
try:
repo_name = self.image.split("/")[2] # `gcr.io/<project_name>/<repo>/`"
base_name = self.name or self.image.split("/")[2]
return f"{base_name}-{uuid4().hex}"
except IndexError:
raise ValueError(
"The provided image must be from either Google Container Registry "
"or Google Artifact Registry"
)

unique_suffix = uuid4().hex
job_name = f"{repo_name}-{unique_suffix}"
return job_name

def _get_compatible_labels(self) -> Dict[str, str]:
"""
Ensures labels are compatible with GCP label requirements.
Expand Down Expand Up @@ -430,6 +426,7 @@ async def run(
raise RuntimeError(f"{self._log_prefix}: {error_msg}")

status_code = 0 if final_job_run.state == JobState.JOB_STATE_SUCCEEDED else 1

return VertexAICustomTrainingJobResult(
identifier=final_job_run.display_name, status_code=status_code
)
Expand Down
2 changes: 1 addition & 1 deletion prefect_gcp/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ class BigQueryWarehouse(DatabaseBlock):
""" # noqa

_block_type_name = "BigQuery Warehouse"
_logo_url = "https://images.ctfassets.net/gm98wzqotmnx/4CD4wwbiIKPkZDt4U3TEuW/c112fe85653da054b6d5334ef662bec4/gcp.png?h=250" # noqa
_logo_url = "https://cdn.sanity.io/images/3ugk85nk/production/10424e311932e31c477ac2b9ef3d53cefbaad708-250x250.png" # noqa
_documentation_url = "https://prefecthq.github.io/prefect-gcp/bigquery/#prefect_gcp.bigquery.BigQueryWarehouse" # noqa: E501

gcp_credentials: GcpCredentials
Expand Down
2 changes: 1 addition & 1 deletion prefect_gcp/cloud_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class CloudRunJob(Infrastructure):
_block_type_slug = "cloud-run-job"
_block_type_name = "GCP Cloud Run Job"
_description = "Infrastructure block used to run GCP Cloud Run Jobs. Note this block is experimental. The interface may change without notice." # noqa
_logo_url = "https://images.ctfassets.net/gm98wzqotmnx/4CD4wwbiIKPkZDt4U3TEuW/c112fe85653da054b6d5334ef662bec4/gcp.png?h=250" # noqa
_logo_url = "https://cdn.sanity.io/images/3ugk85nk/production/10424e311932e31c477ac2b9ef3d53cefbaad708-250x250.png" # noqa
_documentation_url = "https://prefecthq.github.io/prefect-gcp/cloud_run/#prefect_gcp.cloud_run.CloudRunJob" # noqa: E501

type: Literal["cloud-run-job"] = Field(
Expand Down
22 changes: 17 additions & 5 deletions prefect_gcp/cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ class GcsBucket(WritableDeploymentStorage, WritableFileSystem, ObjectStorageBloc
```
"""

_logo_url = "https://images.ctfassets.net/gm98wzqotmnx/4CD4wwbiIKPkZDt4U3TEuW/c112fe85653da054b6d5334ef662bec4/gcp.png?h=250" # noqa
_logo_url = "https://cdn.sanity.io/images/3ugk85nk/production/10424e311932e31c477ac2b9ef3d53cefbaad708-250x250.png" # noqa
_block_type_name = "GCS Bucket"
_documentation_url = "https://prefecthq.github.io/prefect-gcp/cloud_storage/#prefect_gcp.cloud_storage.GcsBucket" # noqa: E501

Expand Down Expand Up @@ -870,7 +870,12 @@ async def list_blobs(self, folder: str = "") -> List["Blob"]:
client = self.gcp_credentials.get_cloud_storage_client()

bucket_path = self._join_bucket_folder(folder)
self.logger.info(f"Listing blobs in bucket {bucket_path}.")
if bucket_path is None:
self.logger.info(f"Listing blobs in bucket {self.bucket!r}.")
else:
self.logger.info(
f"Listing blobs in folder {bucket_path!r} in bucket {self.bucket!r}."
)
blobs = await run_sync_in_worker_thread(
client.list_blobs, self.bucket, prefix=bucket_path
)
Expand Down Expand Up @@ -903,12 +908,19 @@ async def list_folders(self, folder: str = "") -> List[str]:
from prefect_gcp.cloud_storage import GcsBucket
gcs_bucket = GcsBucket.load("my-bucket")
gcs_bucket.list_folders('years)
gcs_bucket.list_folders("years")
```
"""

bucket_path = self._join_bucket_folder()
self.logger.info(f"Listing folders in bucket {bucket_path}.")
# Beware of calling _join_bucket_folder twice, see note in method.
# However, we just want to use it to check if we are listing the root folder
bucket_path = self._join_bucket_folder(folder)
if bucket_path is None:
self.logger.info(f"Listing folders in bucket {self.bucket!r}.")
else:
self.logger.info(
f"Listing folders in {bucket_path!r} in bucket {self.bucket!r}."
)

blobs = await self.list_blobs(folder)
# gets all folders with full path
Expand Down
2 changes: 1 addition & 1 deletion prefect_gcp/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class GcpCredentials(CredentialsBlock):
```
""" # noqa

_logo_url = "https://images.ctfassets.net/gm98wzqotmnx/4CD4wwbiIKPkZDt4U3TEuW/c112fe85653da054b6d5334ef662bec4/gcp.png?h=250" # noqa
_logo_url = "https://cdn.sanity.io/images/3ugk85nk/production/10424e311932e31c477ac2b9ef3d53cefbaad708-250x250.png" # noqa
_block_type_name = "GCP Credentials"
_documentation_url = "https://prefecthq.github.io/prefect-gcp/credentials/#prefect_gcp.credentials.GcpCredentials" # noqa: E501

Expand Down
2 changes: 1 addition & 1 deletion prefect_gcp/secret_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class GcpSecret(SecretBlock):
secret_version: Version number of the secret to use, or "latest".
"""

_logo_url = "https://images.ctfassets.net/gm98wzqotmnx/4CD4wwbiIKPkZDt4U3TEuW/c112fe85653da054b6d5334ef662bec4/gcp.png?h=250" # noqa
_logo_url = "https://cdn.sanity.io/images/3ugk85nk/production/10424e311932e31c477ac2b9ef3d53cefbaad708-250x250.png" # noqa
_documentation_url = "https://prefecthq.github.io/prefect-gcp/secret_manager/#prefect_gcp.secret_manager.GcpSecret" # noqa: E501

gcp_credentials: GcpCredentials
Expand Down
Empty file added prefect_gcp/workers/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions prefect_gcp/worker.py → prefect_gcp/workers/cloud_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ class CloudRunWorker(BaseWorker):
"a Google Cloud Platform account."
)
_display_name = "Google Cloud Run"
_documentation_url = "https://prefecthq.github.io/prefect-gcp/worker/"
_logo_url = "https://images.ctfassets.net/gm98wzqotmnx/4SpnOBvMYkHp6z939MDKP6/549a91bc1ce9afd4fb12c68db7b68106/social-icon-google-cloud-1200-630.png?h=250" # noqa
_documentation_url = "https://prefecthq.github.io/prefect-gcp/cloud_run_worker/"
_logo_url = "https://cdn.sanity.io/images/3ugk85nk/production/10424e311932e31c477ac2b9ef3d53cefbaad708-250x250.png" # noqa

def _create_job_error(self, exc, configuration):
"""Provides a nicer error for 404s when trying to create a Cloud Run Job."""
Expand Down
Loading

0 comments on commit a3c5ea7

Please sign in to comment.