Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from kubernetes import client as k8s_client_lib

from cloud_pipelines.orchestration.storage_providers import google_cloud_storage
from cloud_pipelines_backend.storage_providers import google_cloud_storage_with_timeout

from . import kubernetes_launchers

Expand All @@ -23,6 +23,9 @@ def __init__(
service_account_name: str | None = None,
request_timeout: int | tuple[int, int] = 10,
gcs_client: "storage.Client | None" = None,
gcs_request_timeout: (
google_cloud_storage_with_timeout.RequestTimeout | None
) = None,
pod_labels: dict[str, str] | None = None,
pod_annotations: dict[str, str] | None = None,
pod_postprocessor: kubernetes_launchers.PodPostProcessor | None = None,
Expand All @@ -44,8 +47,9 @@ def __init__(
pod_labels=pod_labels,
pod_annotations={"gke-gcsfuse/volumes": "true"} | (pod_annotations or {}),
pod_postprocessor=final_pod_postporocessor,
_storage_provider=google_cloud_storage.GoogleCloudStorageProvider(
gcs_client
_storage_provider=google_cloud_storage_with_timeout.GoogleCloudStorageProviderWithTimeout(
gcs_client,
request_timeout=gcs_request_timeout,
),
_create_volume_and_volume_mount=kubernetes_launchers._create_volume_and_volume_mount_google_cloud_storage,
)
Expand All @@ -64,6 +68,9 @@ def __init__(
service_account_name: str | None = None,
request_timeout: int | tuple[int, int] = 10,
gcs_client: "storage.Client | None" = None,
gcs_request_timeout: (
google_cloud_storage_with_timeout.RequestTimeout | None
) = None,
pod_labels: dict[str, str] | None = None,
pod_annotations: dict[str, str] | None = None,
pod_postprocessor: kubernetes_launchers.PodPostProcessor | None = None,
Expand All @@ -87,8 +94,9 @@ def __init__(
pod_annotations={"gke-gcsfuse/volumes": "true"} | (pod_annotations or {}),
pod_postprocessor=final_pod_postporocessor,
always_launch_jobs=always_launch_jobs,
_storage_provider=google_cloud_storage.GoogleCloudStorageProvider(
gcs_client
_storage_provider=google_cloud_storage_with_timeout.GoogleCloudStorageProviderWithTimeout(
gcs_client,
request_timeout=gcs_request_timeout,
),
_create_volume_and_volume_mount=kubernetes_launchers._create_volume_and_volume_mount_google_cloud_storage,
)
12 changes: 9 additions & 3 deletions cloud_pipelines_backend/launchers/kubernetes_launchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ def __init__(
request_timeout: int | tuple[int, int] = 10,
pod_name_prefix: str = "task-pod-",
gcs_client: "storage.Client | None" = None,
gcs_request_timeout: (
"google_cloud_storage_with_timeout.RequestTimeout | None"
) = None,
pod_labels: dict[str, str] | None = None,
pod_annotations: dict[str, str] | None = None,
pod_postprocessor: PodPostProcessor | None = None,
Expand All @@ -724,16 +727,19 @@ def __init__(
pod_postprocessors.append(pod_postprocessor)
final_pod_postporocessor = _create_pod_postprocessor_stack(pod_postprocessors)

from cloud_pipelines.orchestration.storage_providers import google_cloud_storage
from cloud_pipelines_backend.storage_providers import (
google_cloud_storage_with_timeout,
)

super().__init__(
namespace=namespace,
service_account_name=service_account_name,
api_client=api_client,
request_timeout=request_timeout,
pod_name_prefix=pod_name_prefix,
_storage_provider=google_cloud_storage.GoogleCloudStorageProvider(
gcs_client
_storage_provider=google_cloud_storage_with_timeout.GoogleCloudStorageProviderWithTimeout(
gcs_client,
request_timeout=gcs_request_timeout,
),
pod_labels=pod_labels,
pod_annotations={"gke-gcsfuse/volumes": "true"} | (pod_annotations or {}),
Expand Down
61 changes: 58 additions & 3 deletions cloud_pipelines_backend/orchestrator_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
DYNAMIC_DATA_SECRET_KEY = "secret"
DYNAMIC_DATA_SECRET_NAME_KEY = "name"

ORCHESTRATOR_RETRY_DEADLINE_ENV = "TANGLE_ORCHESTRATOR_RETRY_DEADLINE_SECONDS"
DEFAULT_ORCHESTRATOR_RETRY_DEADLINE_SECONDS = 180.0


class OrchestratorError(RuntimeError):
pass
Expand Down Expand Up @@ -1225,20 +1228,72 @@ def _update_dict_recursive(d1: dict, d2: dict):
d1[k] = v2


class RetryDeadlineExceededError(TimeoutError):
pass


def _retry(
func: typing.Callable[[], _T], max_retries: int = 5, wait_seconds: float = 1.0
func: typing.Callable[[], _T],
max_retries: int = 5,
wait_seconds: float = 1.0,
max_elapsed_seconds: float | None = None,
) -> _T:
if max_elapsed_seconds is None:
max_elapsed_seconds = _configured_retry_deadline_seconds()
deadline_at = time.monotonic() + max_elapsed_seconds
last_exception: Exception | None = None

for i in range(max_retries):
if time.monotonic() >= deadline_at:
raise RetryDeadlineExceededError(
f"Retry deadline expired before attempt {i + 1} of {max_retries} "
f"for {func}."
) from last_exception

try:
return func()
except Exception:
except Exception as ex:
last_exception = ex
_logger.exception(f"Exception calling {func}.")
time.sleep(wait_seconds)
if i == max_retries - 1:
raise

remaining_seconds = deadline_at - time.monotonic()
if remaining_seconds <= 0:
raise RetryDeadlineExceededError(
f"Retry deadline expired after attempt {i + 1} of "
f"{max_retries} for {func}."
) from ex
time.sleep(min(wait_seconds, remaining_seconds))
raise


def _configured_retry_deadline_seconds() -> float:
raw_value = os.environ.get(
ORCHESTRATOR_RETRY_DEADLINE_ENV,
str(DEFAULT_ORCHESTRATOR_RETRY_DEADLINE_SECONDS),
)
try:
timeout = float(raw_value)
except (TypeError, ValueError):
_logger.warning(
"Invalid %s=%r; using default %.1fs",
ORCHESTRATOR_RETRY_DEADLINE_ENV,
raw_value,
DEFAULT_ORCHESTRATOR_RETRY_DEADLINE_SECONDS,
)
return DEFAULT_ORCHESTRATOR_RETRY_DEADLINE_SECONDS
if timeout <= 0:
_logger.warning(
"Invalid %s=%r; using default %.1fs",
ORCHESTRATOR_RETRY_DEADLINE_ENV,
raw_value,
DEFAULT_ORCHESTRATOR_RETRY_DEADLINE_SECONDS,
)
return DEFAULT_ORCHESTRATOR_RETRY_DEADLINE_SECONDS
return timeout


def record_system_error_exception(execution: bts.ExecutionNode, exception: Exception):
app_metrics.execution_system_errors.add(1)
bugsnag_instrumentation.notify(
Expand Down
Loading
Loading