From 7fa86958795096e5869fadc02e8e373271cd8045 Mon Sep 17 00:00:00 2001 From: rtg0795 <36429068+rtg0795@users.noreply.github.com> Date: Mon, 6 Dec 2021 20:44:06 -0500 Subject: [PATCH] Fix error where Vertex endpoints with the same name is not deduped (#4514) * Fix error where Vertex endpoints with the same name is not deduped PiperOrigin-RevId: 409465659 * Update README.md * Update RELEASE.md Co-authored-by: tfx-team --- README.md | 1 + RELEASE.md | 7 +++--- .../prediction_clients.py | 24 ++++++++++--------- .../google_cloud_ai_platform/runner_test.py | 12 ++++++---- tfx/version.py | 2 +- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ba349df9fe..b77287717a 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ but other *untested* combinations may also work. tfx | apache-beam[gcp] | ml-metadata | pyarrow | tensorflow | tensorflow-data-validation | tensorflow-metadata | tensorflow-model-analysis | tensorflow-serving-api | tensorflow-transform | tfx-bsl ------------------------------------------------------------------------- | ---------------- | ----------- | ------- | ----------------- | -------------------------- | ------------------- | ------------------------- | ---------------------- | -------------------- | ------- [GitHub master](https://github.com/tensorflow/tfx/blob/master/RELEASE.md) | 2.32.0 | 1.3.0 | 2.0.0 | nightly (1.x/2.x) | 1.3.0 | 1.2.0 | 0.34.1 | 2.6.0 | 1.3.0 | 1.3.0 +1.3.4 | 2.32.0 | 1.3.0 | 2.0.0 | 1.15.0 / 2.6.0 | 1.3.0 | 1.2.0 | 0.34.1 | 2.6.0 | 1.3.0 | 1.3.0 1.3.3 | 2.32.0 | 1.3.0 | 2.0.0 | 1.15.0 / 2.6.0 | 1.3.0 | 1.2.0 | 0.34.1 | 2.6.0 | 1.3.0 | 1.3.0 1.3.2 | 2.32.0 | 1.3.0 | 2.0.0 | 1.15.0 / 2.6.0 | 1.3.0 | 1.2.0 | 0.34.1 | 2.6.0 | 1.3.0 | 1.3.0 1.3.1 | 2.32.0 | 1.3.0 | 2.0.0 | 1.15.0 / 2.6.0 | 1.3.0 | 1.2.0 | 0.34.1 | 2.6.0 | 1.3.0 | 1.3.0 diff --git a/RELEASE.md b/RELEASE.md index 1f3da6f73a..f986e8037c 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,9 +1,11 @@ -# Version 1.3.3 +# Version 1.3.4 ## Major Features and Improvements * N/A +## Breaking Changes + ### For Pipeline Authors * N/A @@ -17,8 +19,7 @@ * N/A ## Bug Fixes and Other Changes - -* Depends on `tensorflow>=1.15.2,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,<2.7`. +* Fixed error where Vertex Endpoints of the same name is not deduped ## Documentation Updates diff --git a/tfx/extensions/google_cloud_ai_platform/prediction_clients.py b/tfx/extensions/google_cloud_ai_platform/prediction_clients.py index b2a5dd803d..4aa612b013 100644 --- a/tfx/extensions/google_cloud_ai_platform/prediction_clients.py +++ b/tfx/extensions/google_cloud_ai_platform/prediction_clients.py @@ -500,21 +500,23 @@ def create_model_for_aip_prediction_if_not_exist( Raises: RuntimeError if endpoint creation failed. """ - endpoint_name = ai_platform_serving_args['endpoint_name'] - endpoint_labels = {**ai_platform_serving_args.get('labels', {}), - **labels} endpoint = None + endpoint_name = ai_platform_serving_args['endpoint_name'] try: - endpoint = aiplatform.Endpoint.create( - display_name=endpoint_name, labels=endpoint_labels) - except errors.HttpError as e: - # If the error is to create an already existing endpoint, - # it's ok to ignore. - if e.resp.status == 409: - logging.warn('Endpoint %s already exists', endpoint_name) - else: + self._get_endpoint(ai_platform_serving_args) + except RuntimeError: + # Endpoint doesn't exist + endpoint_labels = {**ai_platform_serving_args.get('labels', {}), + **labels} + try: + endpoint = aiplatform.Endpoint.create( + display_name=endpoint_name, labels=endpoint_labels) + except errors.HttpError as e: raise RuntimeError( 'Creating endpoint in AI Platform failed.') from e + else: + logging.warn('Endpoint %s already exists', endpoint_name) + return endpoint is not None def delete_model_from_aip_if_exists( diff --git a/tfx/extensions/google_cloud_ai_platform/runner_test.py b/tfx/extensions/google_cloud_ai_platform/runner_test.py index ce72373528..4d4c8e237e 100644 --- a/tfx/extensions/google_cloud_ai_platform/runner_test.py +++ b/tfx/extensions/google_cloud_ai_platform/runner_test.py @@ -341,7 +341,7 @@ def _setUpVertexPredictionMocks(self): self._mock_endpoint_list = mock.Mock() aiplatform.Endpoint.list = self._mock_endpoint_list - self._mock_endpoint_list.return_value = [self._mock_endpoint] + self._mock_endpoint_list.return_value = [] self._mock_model_upload = mock.Mock() aiplatform.Model.upload = self._mock_model_upload @@ -642,6 +642,7 @@ def testDeleteModelForAIPPrediction(self, mock_discovery): def testDeployModelForVertexPrediction(self): self._setUpVertexPredictionMocks() + self._mock_endpoint_list.side_effect = [[], [self._mock_endpoint]] runner.deploy_model_for_aip_prediction( serving_path=self._serving_path, @@ -673,6 +674,7 @@ def testDeployModelForVertexPrediction(self): def testDeployModelForVertexPredictionError(self): self._setUpVertexPredictionMocks() + self._mock_endpoint_list.side_effect = [[], [self._mock_endpoint]] self._mock_model_deploy.side_effect = errors.HttpError( httplib2.Response(info={'status': 429}), b'') @@ -715,11 +717,9 @@ def testCreateVertexModel(self): ai_platform_serving_args=self._ai_platform_serving_args_vertex, enable_vertex=True)) - def testCreateVertexEndpointCreateError(self): + def testCreateVertexEndpointCreateErrorAlreadyExist(self): self._setUpVertexPredictionMocks() - - self._mock_endpoint_create.side_effect = ( - errors.HttpError(httplib2.Response(info={'status': 409}), b'')) + self._mock_endpoint_list.return_value = [self._mock_endpoint] self.assertFalse( runner.create_model_for_aip_prediction_if_not_exist( @@ -729,6 +729,7 @@ def testCreateVertexEndpointCreateError(self): def testDeployModelForVertexPredictionWithCustomRegion(self): self._setUpVertexPredictionMocks() + self._mock_endpoint_list.side_effect = [[], [self._mock_endpoint]] self._mock_init = mock.Mock() aiplatform.init = self._mock_init @@ -751,6 +752,7 @@ def testDeployModelForVertexPredictionWithCustomRegion(self): def testDeployModelForVertexPredictionWithCustomMachineType(self): self._setUpVertexPredictionMocks() + self._mock_endpoint_list.side_effect = [[], [self._mock_endpoint]] self._ai_platform_serving_args_vertex[ 'machine_type'] = 'custom_machine_type' diff --git a/tfx/version.py b/tfx/version.py index 95eb7cd09a..9926131d33 100644 --- a/tfx/version.py +++ b/tfx/version.py @@ -14,4 +14,4 @@ """Contains the version string of TFX.""" # Note that setup.py uses this version. -__version__ = '1.3.3' +__version__ = '1.3.4'