Skip to content
Open
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
11 changes: 9 additions & 2 deletions google/cloud/aiplatform/tensorboard/uploader_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

from tensorboard.util import tb_logging

_GS_BUCKET_REGEX = re.compile(r"gs:\/\/(.*?)(?=\/|$)")

TensorboardServiceClient = tensorboard_service_client.TensorboardServiceClient
DEFAULT_RUN_NAME = "default"
DEFAULT_PROFILE_RUN_NAME = "profile"
Expand Down Expand Up @@ -461,10 +463,15 @@ def get_source_bucket(logdir: str) -> Optional[storage.Bucket]:
bucket (Optional[storage.Bucket]):
A bucket if the path is a gs bucket, None otherwise.
"""
m = re.match(r"gs:\/\/(.*?)(?=\/|$)", logdir)
m = _GS_BUCKET_REGEX.match(logdir)
if not m:
return None
bucket = storage.Client().bucket(m[1])
# Avoid creating a new storage.Client on every call;
# Use a module-level singleton client for efficiency.
# This avoids repeated auth/local computations.
if not hasattr(get_source_bucket, "_storage_client"):
get_source_bucket._storage_client = storage.Client()
bucket = get_source_bucket._storage_client.bucket(m[1])
return bucket


Expand Down