|
17 | 17 |
|
18 | 18 |
|
19 | 19 | from concurrent import futures
|
| 20 | +import enum |
20 | 21 | import functools
|
21 | 22 | import inspect
|
22 | 23 | import logging
|
|
53 | 54 | _TOP_GOOGLE_CONSTRUCTOR_METHOD_TAG = "top_google_constructor_method"
|
54 | 55 |
|
55 | 56 |
|
| 57 | +class _Product(enum.Enum): |
| 58 | + """Notebook product types.""" |
| 59 | + |
| 60 | + WORKBENCH_INSTANCE = "WORKBENCH_INSTANCE" |
| 61 | + COLAB_ENTERPRISE = "COLAB_ENTERPRISE" |
| 62 | + WORKBENCH_CUSTOM_CONTAINER = "WORKBENCH_CUSTOM_CONTAINER" |
| 63 | + |
| 64 | + |
56 | 65 | class _Config:
|
57 | 66 | """Stores common parameters and options for API calls."""
|
58 | 67 |
|
@@ -110,6 +119,7 @@ def __init__(self):
|
110 | 119 | self._api_endpoint = None
|
111 | 120 | self._api_transport = None
|
112 | 121 | self._request_metadata = None
|
| 122 | + self._resource_type = None |
113 | 123 |
|
114 | 124 | def init(
|
115 | 125 | self,
|
@@ -242,6 +252,7 @@ def init(
|
242 | 252 | self._service_account = service_account
|
243 | 253 | if request_metadata is not None:
|
244 | 254 | self._request_metadata = request_metadata
|
| 255 | + self._resource_type = None |
245 | 256 |
|
246 | 257 | # Finally, perform secondary state updates
|
247 | 258 | if experiment_tensorboard and not isinstance(experiment_tensorboard, bool):
|
@@ -370,6 +381,21 @@ def experiment_name(self) -> Optional[str]:
|
370 | 381 | """Default experiment name, if provided."""
|
371 | 382 | return metadata._experiment_tracker.experiment_name
|
372 | 383 |
|
| 384 | + def get_resource_type(self) -> _Product: |
| 385 | + """Returns the resource type from environment variables.""" |
| 386 | + if self._resource_type: |
| 387 | + return self._resource_type |
| 388 | + |
| 389 | + vertex_product = os.getenv("VERTEX_PRODUCT") |
| 390 | + if vertex_product == "COLAB_ENTERPRISE": |
| 391 | + self._resource_type = _Product.COLAB_ENTERPRISE |
| 392 | + if vertex_product == "WORKBENCH_CUSTOM_CONTAINER": |
| 393 | + self._resource_type = _Product.WORKBENCH_CUSTOM_CONTAINER |
| 394 | + if vertex_product == "WORKBENCH_INSTANCE": |
| 395 | + self._resource_type = _Product.WORKBENCH_INSTANCE |
| 396 | + |
| 397 | + return self._resource_type |
| 398 | + |
373 | 399 | def get_client_options(
|
374 | 400 | self,
|
375 | 401 | location_override: Optional[str] = None,
|
@@ -489,6 +515,10 @@ def create_client(
|
489 | 515 | except Exception: # pylint: disable=broad-exception-caught
|
490 | 516 | pass
|
491 | 517 |
|
| 518 | + resource_type = self.get_resource_type() |
| 519 | + if resource_type: |
| 520 | + gapic_version += f"+environment+{resource_type.value}" |
| 521 | + |
492 | 522 | if telemetry._tool_names_to_append:
|
493 | 523 | # Must append to gapic_version due to b/259738581.
|
494 | 524 | gapic_version = f"{gapic_version}+tools+{'+'.join(telemetry._tool_names_to_append[::-1])}"
|
|
0 commit comments