Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 688cde1

Browse files
fix: use correct retry deadline (#3)
1 parent e50bdfd commit 688cde1

File tree

11 files changed

+137
-189
lines changed

11 files changed

+137
-189
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2021 Google LLC
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
#
151
# See https://pre-commit.com for more information
162
# See https://pre-commit.com/hooks.html for more hooks
173
repos:
@@ -26,6 +12,6 @@ repos:
2612
hooks:
2713
- id: black
2814
- repo: https://gitlab.com/pycqa/flake8
29-
rev: 3.8.4
15+
rev: 3.9.0
3016
hooks:
3117
- id: flake8

docs/conf.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright 2021 Google LLC
3-
#
4-
# Licensed under the Apache License, Version 2.0 (the "License");
5-
# you may not use this file except in compliance with the License.
6-
# You may obtain a copy of the License at
7-
#
8-
# http://www.apache.org/licenses/LICENSE-2.0
9-
#
10-
# Unless required by applicable law or agreed to in writing, software
11-
# distributed under the License is distributed on an "AS IS" BASIS,
12-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
# See the License for the specific language governing permissions and
14-
# limitations under the License.
152
#
163
# google-cloud-api-gateway documentation build configuration file
174
#

google/cloud/apigateway_v1/services/api_gateway_service/async_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ async def create_gateway(
437437
predicate=retries.if_exception_type(
438438
exceptions.ServiceUnavailable, exceptions.Unknown,
439439
),
440+
deadline=60.0,
440441
),
441442
default_timeout=60.0,
442443
client_info=DEFAULT_CLIENT_INFO,
@@ -542,6 +543,7 @@ async def update_gateway(
542543
predicate=retries.if_exception_type(
543544
exceptions.ServiceUnavailable, exceptions.Unknown,
544545
),
546+
deadline=60.0,
545547
),
546548
default_timeout=60.0,
547549
client_info=DEFAULT_CLIENT_INFO,
@@ -646,6 +648,7 @@ async def delete_gateway(
646648
predicate=retries.if_exception_type(
647649
exceptions.ServiceUnavailable, exceptions.Unknown,
648650
),
651+
deadline=60.0,
649652
),
650653
default_timeout=60.0,
651654
client_info=DEFAULT_CLIENT_INFO,
@@ -912,6 +915,7 @@ async def create_api(
912915
predicate=retries.if_exception_type(
913916
exceptions.ServiceUnavailable, exceptions.Unknown,
914917
),
918+
deadline=60.0,
915919
),
916920
default_timeout=60.0,
917921
client_info=DEFAULT_CLIENT_INFO,
@@ -1016,6 +1020,7 @@ async def update_api(
10161020
predicate=retries.if_exception_type(
10171021
exceptions.ServiceUnavailable, exceptions.Unknown,
10181022
),
1023+
deadline=60.0,
10191024
),
10201025
default_timeout=60.0,
10211026
client_info=DEFAULT_CLIENT_INFO,
@@ -1118,6 +1123,7 @@ async def delete_api(
11181123
predicate=retries.if_exception_type(
11191124
exceptions.ServiceUnavailable, exceptions.Unknown,
11201125
),
1126+
deadline=60.0,
11211127
),
11221128
default_timeout=60.0,
11231129
client_info=DEFAULT_CLIENT_INFO,
@@ -1385,6 +1391,7 @@ async def create_api_config(
13851391
predicate=retries.if_exception_type(
13861392
exceptions.ServiceUnavailable, exceptions.Unknown,
13871393
),
1394+
deadline=60.0,
13881395
),
13891396
default_timeout=60.0,
13901397
client_info=DEFAULT_CLIENT_INFO,
@@ -1488,6 +1495,7 @@ async def update_api_config(
14881495
predicate=retries.if_exception_type(
14891496
exceptions.ServiceUnavailable, exceptions.Unknown,
14901497
),
1498+
deadline=60.0,
14911499
),
14921500
default_timeout=60.0,
14931501
client_info=DEFAULT_CLIENT_INFO,
@@ -1592,6 +1600,7 @@ async def delete_api_config(
15921600
predicate=retries.if_exception_type(
15931601
exceptions.ServiceUnavailable, exceptions.Unknown,
15941602
),
1603+
deadline=60.0,
15951604
),
15961605
default_timeout=60.0,
15971606
client_info=DEFAULT_CLIENT_INFO,

google/cloud/apigateway_v1/services/api_gateway_service/transports/base.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,20 @@ def __init__(
7171
scope (Optional[Sequence[str]]): A list of scopes.
7272
quota_project_id (Optional[str]): An optional project to use for billing
7373
and quota.
74-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
75-
The client info used to send a user-agent string along with
76-
API requests. If ``None``, then default info will be used.
77-
Generally, you only need to set this if you're developing
74+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
75+
The client info used to send a user-agent string along with
76+
API requests. If ``None``, then default info will be used.
77+
Generally, you only need to set this if you're developing
7878
your own client library.
7979
"""
8080
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
8181
if ":" not in host:
8282
host += ":443"
8383
self._host = host
8484

85+
# Save the scopes.
86+
self._scopes = scopes or self.AUTH_SCOPES
87+
8588
# If no credentials are provided, then determine the appropriate
8689
# defaults.
8790
if credentials and credentials_file:
@@ -91,20 +94,17 @@ def __init__(
9194

9295
if credentials_file is not None:
9396
credentials, _ = auth.load_credentials_from_file(
94-
credentials_file, scopes=scopes, quota_project_id=quota_project_id
97+
credentials_file, scopes=self._scopes, quota_project_id=quota_project_id
9598
)
9699

97100
elif credentials is None:
98101
credentials, _ = auth.default(
99-
scopes=scopes, quota_project_id=quota_project_id
102+
scopes=self._scopes, quota_project_id=quota_project_id
100103
)
101104

102105
# Save the credentials.
103106
self._credentials = credentials
104107

105-
# Lifted into its own function so it can be stubbed out during tests.
106-
self._prep_wrapped_messages(client_info)
107-
108108
def _prep_wrapped_messages(self, client_info):
109109
# Precompute the wrapped methods.
110110
self._wrapped_methods = {
@@ -123,6 +123,7 @@ def _prep_wrapped_messages(self, client_info):
123123
predicate=retries.if_exception_type(
124124
exceptions.ServiceUnavailable, exceptions.Unknown,
125125
),
126+
deadline=60.0,
126127
),
127128
default_timeout=60.0,
128129
client_info=client_info,
@@ -136,6 +137,7 @@ def _prep_wrapped_messages(self, client_info):
136137
predicate=retries.if_exception_type(
137138
exceptions.ServiceUnavailable, exceptions.Unknown,
138139
),
140+
deadline=60.0,
139141
),
140142
default_timeout=60.0,
141143
client_info=client_info,
@@ -149,6 +151,7 @@ def _prep_wrapped_messages(self, client_info):
149151
predicate=retries.if_exception_type(
150152
exceptions.ServiceUnavailable, exceptions.Unknown,
151153
),
154+
deadline=60.0,
152155
),
153156
default_timeout=60.0,
154157
client_info=client_info,
@@ -168,6 +171,7 @@ def _prep_wrapped_messages(self, client_info):
168171
predicate=retries.if_exception_type(
169172
exceptions.ServiceUnavailable, exceptions.Unknown,
170173
),
174+
deadline=60.0,
171175
),
172176
default_timeout=60.0,
173177
client_info=client_info,
@@ -181,6 +185,7 @@ def _prep_wrapped_messages(self, client_info):
181185
predicate=retries.if_exception_type(
182186
exceptions.ServiceUnavailable, exceptions.Unknown,
183187
),
188+
deadline=60.0,
184189
),
185190
default_timeout=60.0,
186191
client_info=client_info,
@@ -194,6 +199,7 @@ def _prep_wrapped_messages(self, client_info):
194199
predicate=retries.if_exception_type(
195200
exceptions.ServiceUnavailable, exceptions.Unknown,
196201
),
202+
deadline=60.0,
197203
),
198204
default_timeout=60.0,
199205
client_info=client_info,
@@ -213,6 +219,7 @@ def _prep_wrapped_messages(self, client_info):
213219
predicate=retries.if_exception_type(
214220
exceptions.ServiceUnavailable, exceptions.Unknown,
215221
),
222+
deadline=60.0,
216223
),
217224
default_timeout=60.0,
218225
client_info=client_info,
@@ -226,6 +233,7 @@ def _prep_wrapped_messages(self, client_info):
226233
predicate=retries.if_exception_type(
227234
exceptions.ServiceUnavailable, exceptions.Unknown,
228235
),
236+
deadline=60.0,
229237
),
230238
default_timeout=60.0,
231239
client_info=client_info,
@@ -239,6 +247,7 @@ def _prep_wrapped_messages(self, client_info):
239247
predicate=retries.if_exception_type(
240248
exceptions.ServiceUnavailable, exceptions.Unknown,
241249
),
250+
deadline=60.0,
242251
),
243252
default_timeout=60.0,
244253
client_info=client_info,

google/cloud/apigateway_v1/services/api_gateway_service/transports/grpc.py

Lines changed: 38 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -109,97 +109,70 @@ def __init__(
109109
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
110110
and ``credentials_file`` are passed.
111111
"""
112+
self._grpc_channel = None
112113
self._ssl_channel_credentials = ssl_channel_credentials
114+
self._stubs: Dict[str, Callable] = {}
115+
self._operations_client = None
113116

114117
if api_mtls_endpoint:
115118
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
116119
if client_cert_source:
117120
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
118121

119122
if channel:
120-
# Sanity check: Ensure that channel and credentials are not both
121-
# provided.
123+
# Ignore credentials if a channel was passed.
122124
credentials = False
123-
124125
# If a channel was explicitly provided, set it.
125126
self._grpc_channel = channel
126127
self._ssl_channel_credentials = None
127-
elif api_mtls_endpoint:
128-
host = (
129-
api_mtls_endpoint
130-
if ":" in api_mtls_endpoint
131-
else api_mtls_endpoint + ":443"
132-
)
133-
134-
if credentials is None:
135-
credentials, _ = auth.default(
136-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
137-
)
138-
139-
# Create SSL credentials with client_cert_source or application
140-
# default SSL credentials.
141-
if client_cert_source:
142-
cert, key = client_cert_source()
143-
ssl_credentials = grpc.ssl_channel_credentials(
144-
certificate_chain=cert, private_key=key
145-
)
146-
else:
147-
ssl_credentials = SslCredentials().ssl_credentials
148128

149-
# create a new channel. The provided one is ignored.
150-
self._grpc_channel = type(self).create_channel(
151-
host,
152-
credentials=credentials,
153-
credentials_file=credentials_file,
154-
ssl_credentials=ssl_credentials,
155-
scopes=scopes or self.AUTH_SCOPES,
156-
quota_project_id=quota_project_id,
157-
options=[
158-
("grpc.max_send_message_length", -1),
159-
("grpc.max_receive_message_length", -1),
160-
],
161-
)
162-
self._ssl_channel_credentials = ssl_credentials
163129
else:
164-
host = host if ":" in host else host + ":443"
130+
if api_mtls_endpoint:
131+
host = api_mtls_endpoint
132+
133+
# Create SSL credentials with client_cert_source or application
134+
# default SSL credentials.
135+
if client_cert_source:
136+
cert, key = client_cert_source()
137+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
138+
certificate_chain=cert, private_key=key
139+
)
140+
else:
141+
self._ssl_channel_credentials = SslCredentials().ssl_credentials
165142

166-
if credentials is None:
167-
credentials, _ = auth.default(
168-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
169-
)
143+
else:
144+
if client_cert_source_for_mtls and not ssl_channel_credentials:
145+
cert, key = client_cert_source_for_mtls()
146+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
147+
certificate_chain=cert, private_key=key
148+
)
170149

171-
if client_cert_source_for_mtls and not ssl_channel_credentials:
172-
cert, key = client_cert_source_for_mtls()
173-
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
174-
certificate_chain=cert, private_key=key
175-
)
150+
# The base transport sets the host, credentials and scopes
151+
super().__init__(
152+
host=host,
153+
credentials=credentials,
154+
credentials_file=credentials_file,
155+
scopes=scopes,
156+
quota_project_id=quota_project_id,
157+
client_info=client_info,
158+
)
176159

177-
# create a new channel. The provided one is ignored.
160+
if not self._grpc_channel:
178161
self._grpc_channel = type(self).create_channel(
179-
host,
180-
credentials=credentials,
162+
self._host,
163+
credentials=self._credentials,
181164
credentials_file=credentials_file,
165+
scopes=self._scopes,
182166
ssl_credentials=self._ssl_channel_credentials,
183-
scopes=scopes or self.AUTH_SCOPES,
184167
quota_project_id=quota_project_id,
185168
options=[
186169
("grpc.max_send_message_length", -1),
187170
("grpc.max_receive_message_length", -1),
188171
],
189172
)
190173

191-
self._stubs = {} # type: Dict[str, Callable]
192-
self._operations_client = None
193-
194-
# Run the base constructor.
195-
super().__init__(
196-
host=host,
197-
credentials=credentials,
198-
credentials_file=credentials_file,
199-
scopes=scopes or self.AUTH_SCOPES,
200-
quota_project_id=quota_project_id,
201-
client_info=client_info,
202-
)
174+
# Wrap messages. This must be done after self._grpc_channel exists
175+
self._prep_wrapped_messages(client_info)
203176

204177
@classmethod
205178
def create_channel(
@@ -213,7 +186,7 @@ def create_channel(
213186
) -> grpc.Channel:
214187
"""Create and return a gRPC channel object.
215188
Args:
216-
address (Optional[str]): The host for the channel to use.
189+
host (Optional[str]): The host for the channel to use.
217190
credentials (Optional[~.Credentials]): The
218191
authorization credentials to attach to requests. These
219192
credentials identify this application to the service. If

0 commit comments

Comments
 (0)