Skip to content

Commit 184f7f3

Browse files
authored
feat: add timeout arg across SDK (#1099)
* feat: add timeout arg and tests to model upload * feat: add timeout arg and tests to dataset create method * feat: add tiemout arg to dataset import and tensorboard create * Update system tests with timeout arg * rename timeout arg with method name and update tests * add deploy_request_timeout to Model deploy * add create_timeout_request arg to pipeline job run and submit * add timeout arg and tests to training_jobs * add timeout arg tests for training_jobs * update system tests with timeout arg * add timeout arg tests and run linter * add timeout arg and tests to tensorboard * add timeout arg and tests to featurestore * fix failing tests * update system tests with timeout arg * fix broken tests and run linter * update handling of import_request_timeout arg * update timeout arg in tests and run linter * finish moving timeout arg to end of function signatures
1 parent a3ce143 commit 184f7f3

32 files changed

+2275
-57
lines changed

google/cloud/aiplatform/datasets/dataset.py

+41-6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def create(
119119
labels: Optional[Dict[str, str]] = None,
120120
encryption_spec_key_name: Optional[str] = None,
121121
sync: bool = True,
122+
create_request_timeout: Optional[float] = None,
122123
) -> "_Dataset":
123124
"""Creates a new dataset and optionally imports data into dataset when
124125
source and import_schema_uri are passed.
@@ -203,6 +204,8 @@ def create(
203204
Whether to execute this method synchronously. If False, this method
204205
will be executed in concurrent Future and any downstream object will
205206
be immediately returned and synced when the Future has completed.
207+
create_request_timeout (float):
208+
Optional. The timeout for the create request in seconds.
206209
207210
Returns:
208211
dataset (Dataset):
@@ -240,6 +243,7 @@ def create(
240243
encryption_spec_key_name=encryption_spec_key_name
241244
),
242245
sync=sync,
246+
create_request_timeout=create_request_timeout,
243247
)
244248

245249
@classmethod
@@ -258,6 +262,8 @@ def _create_and_import(
258262
labels: Optional[Dict[str, str]] = None,
259263
encryption_spec: Optional[gca_encryption_spec.EncryptionSpec] = None,
260264
sync: bool = True,
265+
create_request_timeout: Optional[float] = None,
266+
import_request_timeout: Optional[float] = None,
261267
) -> "_Dataset":
262268
"""Creates a new dataset and optionally imports data into dataset when
263269
source and import_schema_uri are passed.
@@ -313,6 +319,10 @@ def _create_and_import(
313319
Whether to execute this method synchronously. If False, this method
314320
will be executed in concurrent Future and any downstream object will
315321
be immediately returned and synced when the Future has completed.
322+
create_request_timeout (float):
323+
Optional. The timeout for the create request in seconds.
324+
import_request_timeout (float):
325+
Optional. The timeout for the import request in seconds.
316326
317327
Returns:
318328
dataset (Dataset):
@@ -328,6 +338,7 @@ def _create_and_import(
328338
request_metadata=request_metadata,
329339
labels=labels,
330340
encryption_spec=encryption_spec,
341+
create_request_timeout=create_request_timeout,
331342
)
332343

333344
_LOGGER.log_create_with_lro(cls, create_dataset_lro)
@@ -345,18 +356,26 @@ def _create_and_import(
345356

346357
# Import if import datasource is DatasourceImportable
347358
if isinstance(datasource, _datasources.DatasourceImportable):
348-
dataset_obj._import_and_wait(datasource)
359+
dataset_obj._import_and_wait(
360+
datasource, import_request_timeout=import_request_timeout
361+
)
349362

350363
return dataset_obj
351364

352-
def _import_and_wait(self, datasource):
365+
def _import_and_wait(
366+
self,
367+
datasource,
368+
import_request_timeout: Optional[float] = None,
369+
):
353370
_LOGGER.log_action_start_against_resource(
354371
"Importing",
355372
"data",
356373
self,
357374
)
358375

359-
import_lro = self._import(datasource=datasource)
376+
import_lro = self._import(
377+
datasource=datasource, import_request_timeout=import_request_timeout
378+
)
360379

361380
_LOGGER.log_action_started_against_resource_with_lro(
362381
"Import", "data", self.__class__, import_lro
@@ -377,6 +396,7 @@ def _create(
377396
request_metadata: Sequence[Tuple[str, str]] = (),
378397
labels: Optional[Dict[str, str]] = None,
379398
encryption_spec: Optional[gca_encryption_spec.EncryptionSpec] = None,
399+
create_request_timeout: Optional[float] = None,
380400
) -> operation.Operation:
381401
"""Creates a new managed dataset by directly calling API client.
382402
@@ -419,6 +439,8 @@ def _create(
419439
resource is created.
420440
421441
If set, this Dataset and all sub-resources of this Dataset will be secured by this key.
442+
create_request_timeout (float):
443+
Optional. The timeout for the create request in seconds.
422444
Returns:
423445
operation (Operation):
424446
An object representing a long-running operation.
@@ -433,25 +455,33 @@ def _create(
433455
)
434456

435457
return api_client.create_dataset(
436-
parent=parent, dataset=gapic_dataset, metadata=request_metadata
458+
parent=parent,
459+
dataset=gapic_dataset,
460+
metadata=request_metadata,
461+
timeout=create_request_timeout,
437462
)
438463

439464
def _import(
440465
self,
441466
datasource: _datasources.DatasourceImportable,
467+
import_request_timeout: Optional[float] = None,
442468
) -> operation.Operation:
443469
"""Imports data into managed dataset by directly calling API client.
444470
445471
Args:
446472
datasource (_datasources.DatasourceImportable):
447473
Required. Datasource for importing data to an existing dataset for Vertex AI.
474+
import_request_timeout (float):
475+
Optional. The timeout for the import request in seconds.
448476
449477
Returns:
450478
operation (Operation):
451479
An object representing a long-running operation.
452480
"""
453481
return self.api_client.import_data(
454-
name=self.resource_name, import_configs=[datasource.import_data_config]
482+
name=self.resource_name,
483+
import_configs=[datasource.import_data_config],
484+
timeout=import_request_timeout,
455485
)
456486

457487
@base.optional_sync(return_input_arg="self")
@@ -461,6 +491,7 @@ def import_data(
461491
import_schema_uri: str,
462492
data_item_labels: Optional[Dict] = None,
463493
sync: bool = True,
494+
import_request_timeout: Optional[float] = None,
464495
) -> "_Dataset":
465496
"""Upload data to existing managed dataset.
466497
@@ -498,6 +529,8 @@ def import_data(
498529
Whether to execute this method synchronously. If False, this method
499530
will be executed in concurrent Future and any downstream object will
500531
be immediately returned and synced when the Future has completed.
532+
import_request_timeout (float):
533+
Optional. The timeout for the import request in seconds.
501534
502535
Returns:
503536
dataset (Dataset):
@@ -510,7 +543,9 @@ def import_data(
510543
data_item_labels=data_item_labels,
511544
)
512545

513-
self._import_and_wait(datasource=datasource)
546+
self._import_and_wait(
547+
datasource=datasource, import_request_timeout=import_request_timeout
548+
)
514549
return self
515550

516551
# TODO(b/174751568) add optional sync support

google/cloud/aiplatform/datasets/image_dataset.py

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def create(
4747
labels: Optional[Dict[str, str]] = None,
4848
encryption_spec_key_name: Optional[str] = None,
4949
sync: bool = True,
50+
create_request_timeout: Optional[float] = None,
5051
) -> "ImageDataset":
5152
"""Creates a new image dataset and optionally imports data into dataset
5253
when source and import_schema_uri are passed.
@@ -121,6 +122,8 @@ def create(
121122
Whether to execute this method synchronously. If False, this method
122123
will be executed in concurrent Future and any downstream object will
123124
be immediately returned and synced when the Future has completed.
125+
create_request_timeout (float):
126+
Optional. The timeout for the create request in seconds.
124127
125128
Returns:
126129
image_dataset (ImageDataset):
@@ -159,4 +162,5 @@ def create(
159162
encryption_spec_key_name=encryption_spec_key_name
160163
),
161164
sync=sync,
165+
create_request_timeout=create_request_timeout,
162166
)

google/cloud/aiplatform/datasets/tabular_dataset.py

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def create(
4646
labels: Optional[Dict[str, str]] = None,
4747
encryption_spec_key_name: Optional[str] = None,
4848
sync: bool = True,
49+
create_request_timeout: Optional[float] = None,
4950
) -> "TabularDataset":
5051
"""Creates a new tabular dataset.
5152
@@ -102,6 +103,8 @@ def create(
102103
Whether to execute this method synchronously. If False, this method
103104
will be executed in concurrent Future and any downstream object will
104105
be immediately returned and synced when the Future has completed.
106+
create_request_timeout (float):
107+
Optional. The timeout for the create request in seconds.
105108
106109
Returns:
107110
tabular_dataset (TabularDataset):
@@ -139,6 +142,7 @@ def create(
139142
encryption_spec_key_name=encryption_spec_key_name
140143
),
141144
sync=sync,
145+
create_request_timeout=create_request_timeout,
142146
)
143147

144148
def import_data(self):

google/cloud/aiplatform/datasets/text_dataset.py

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def create(
4747
labels: Optional[Dict[str, str]] = None,
4848
encryption_spec_key_name: Optional[str] = None,
4949
sync: bool = True,
50+
create_request_timeout: Optional[float] = None,
5051
) -> "TextDataset":
5152
"""Creates a new text dataset and optionally imports data into dataset
5253
when source and import_schema_uri are passed.
@@ -124,6 +125,8 @@ def create(
124125
If set, this Dataset and all sub-resources of this Dataset will be secured by this key.
125126
126127
Overrides encryption_spec_key_name set in aiplatform.init.
128+
create_request_timeout (float):
129+
Optional. The timeout for the create request in seconds.
127130
sync (bool):
128131
Whether to execute this method synchronously. If False, this method
129132
will be executed in concurrent Future and any downstream object will
@@ -166,4 +169,5 @@ def create(
166169
encryption_spec_key_name=encryption_spec_key_name
167170
),
168171
sync=sync,
172+
create_request_timeout=create_request_timeout,
169173
)

google/cloud/aiplatform/datasets/video_dataset.py

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def create(
4747
labels: Optional[Dict[str, str]] = None,
4848
encryption_spec_key_name: Optional[str] = None,
4949
sync: bool = True,
50+
create_request_timeout: Optional[float] = None,
5051
) -> "VideoDataset":
5152
"""Creates a new video dataset and optionally imports data into dataset
5253
when source and import_schema_uri are passed.
@@ -117,6 +118,8 @@ def create(
117118
If set, this Dataset and all sub-resources of this Dataset will be secured by this key.
118119
119120
Overrides encryption_spec_key_name set in aiplatform.init.
121+
create_request_timeout (float):
122+
Optional. The timeout for the create request in seconds.
120123
sync (bool):
121124
Whether to execute this method synchronously. If False, this method
122125
will be executed in concurrent Future and any downstream object will
@@ -159,4 +162,5 @@ def create(
159162
encryption_spec_key_name=encryption_spec_key_name
160163
),
161164
sync=sync,
165+
create_request_timeout=create_request_timeout,
162166
)

0 commit comments

Comments
 (0)