Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1c83353

Browse filesBrowse files
authored
Monitoring: Add Transports Layer, Remove gRPC size restrictions (4MB default) (#5594)
* regenerate monitoring to add transports layer * fix #5574 by removing gRPC size limits
1 parent 4e572d6 commit 1c83353
Copy full SHA for 1c83353
Expand file treeCollapse file tree

12 files changed

+1293
-306
lines changed

‎packages/google-cloud-monitoring/google/cloud/monitoring_v3/gapic/alert_policy_service_client.py

Copy file name to clipboardExpand all lines: packages/google-cloud-monitoring/google/cloud/monitoring_v3/gapic/alert_policy_service_client.py
+64-58Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import functools
1717
import pkg_resources
18+
import warnings
1819

1920
import google.api_core.gapic_v1.client_info
2021
import google.api_core.gapic_v1.config
@@ -26,6 +27,7 @@
2627

2728
from google.cloud.monitoring_v3.gapic import alert_policy_service_client_config
2829
from google.cloud.monitoring_v3.gapic import enums
30+
from google.cloud.monitoring_v3.gapic.transports import alert_policy_service_grpc_transport
2931
from google.cloud.monitoring_v3.proto import alert_pb2
3032
from google.cloud.monitoring_v3.proto import alert_service_pb2
3133
from google.cloud.monitoring_v3.proto import alert_service_pb2_grpc
@@ -52,17 +54,8 @@ class AlertPolicyServiceClient(object):
5254
SERVICE_ADDRESS = 'monitoring.googleapis.com:443'
5355
"""The default address of the service."""
5456

55-
# The scopes needed to make gRPC calls to all of the methods defined in
56-
# this service
57-
_DEFAULT_SCOPES = (
58-
'https://www.googleapis.com/auth/cloud-platform',
59-
'https://www.googleapis.com/auth/monitoring',
60-
'https://www.googleapis.com/auth/monitoring.read',
61-
'https://www.googleapis.com/auth/monitoring.write',
62-
)
63-
64-
# The name of the interface for this client. This is the key used to find
65-
# method configuration in the client_config dictionary.
57+
# The name of the interface for this client. This is the key used to
58+
# find the method configuration in the client_config dictionary.
6659
_INTERFACE_NAME = 'google.monitoring.v3.AlertPolicyService'
6760

6861
@classmethod
@@ -93,48 +86,71 @@ def alert_policy_condition_path(cls, project, alert_policy, condition):
9386
)
9487

9588
def __init__(self,
89+
transport=None,
9690
channel=None,
9791
credentials=None,
9892
client_config=alert_policy_service_client_config.config,
9993
client_info=None):
10094
"""Constructor.
10195
10296
Args:
103-
channel (grpc.Channel): A ``Channel`` instance through
104-
which to make calls. This argument is mutually exclusive
97+
transport (Union[~.AlertPolicyServiceGrpcTransport,
98+
Callable[[~.Credentials, type], ~.AlertPolicyServiceGrpcTransport]): A transport
99+
instance, responsible for actually making the API calls.
100+
The default transport uses the gRPC protocol.
101+
This argument may also be a callable which returns a
102+
transport instance. Callables will be sent the credentials
103+
as the first argument and the default transport class as
104+
the second argument.
105+
channel (grpc.Channel): DEPRECATED. A ``Channel`` instance
106+
through which to make calls. This argument is mutually exclusive
105107
with ``credentials``; providing both will raise an exception.
106108
credentials (google.auth.credentials.Credentials): The
107109
authorization credentials to attach to requests. These
108110
credentials identify this application to the service. If none
109111
are specified, the client will attempt to ascertain the
110112
credentials from the environment.
111-
client_config (dict): A dictionary of call options for each
112-
method. If not specified, the default configuration is used.
113+
This argument is mutually exclusive with providing a
114+
transport instance to ``transport``; doing so will raise
115+
an exception.
116+
client_config (dict): DEPRECATED. A dictionary of call options for
117+
each method. If not specified, the default configuration is used.
113118
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
114119
The client info used to send a user-agent string along with
115120
API requests. If ``None``, then default info will be used.
116121
Generally, you only need to set this if you're developing
117122
your own client library.
118123
"""
119-
# If both `channel` and `credentials` are specified, raise an
120-
# exception (channels come with credentials baked in already).
121-
if channel is not None and credentials is not None:
122-
raise ValueError(
123-
'The `channel` and `credentials` arguments to {} are mutually '
124-
'exclusive.'.format(self.__class__.__name__), )
125-
126-
# Create the channel.
127-
self.channel = channel
128-
if self.channel is None:
129-
self.channel = google.api_core.grpc_helpers.create_channel(
130-
self.SERVICE_ADDRESS,
131-
credentials=credentials,
132-
scopes=self._DEFAULT_SCOPES,
133-
)
134-
135-
# Create the gRPC stubs.
136-
self._alert_policy_service_stub = (
137-
alert_service_pb2_grpc.AlertPolicyServiceStub(self.channel))
124+
# Raise deprecation warnings for things we want to go away.
125+
if client_config:
126+
warnings.warn('The `client_config` argument is deprecated.',
127+
PendingDeprecationWarning)
128+
if channel:
129+
warnings.warn(
130+
'The `channel` argument is deprecated; use '
131+
'`transport` instead.', PendingDeprecationWarning)
132+
133+
# Instantiate the transport.
134+
# The transport is responsible for handling serialization and
135+
# deserialization and actually sending data to the service.
136+
if transport:
137+
if callable(transport):
138+
self.transport = transport(
139+
credentials=credentials,
140+
default_class=alert_policy_service_grpc_transport.
141+
AlertPolicyServiceGrpcTransport,
142+
)
143+
else:
144+
if credentials:
145+
raise ValueError(
146+
'Received both a transport instance and '
147+
'credentials; these are mutually exclusive.')
148+
self.transport = transport
149+
self.transport = alert_policy_service_grpc_transport.AlertPolicyServiceGrpcTransport(
150+
address=self.SERVICE_ADDRESS,
151+
channel=channel,
152+
credentials=credentials,
153+
)
138154

139155
if client_info is None:
140156
client_info = (
@@ -149,27 +165,12 @@ def __init__(self,
149165
self._method_configs = google.api_core.gapic_v1.config.parse_method_configs(
150166
client_config['interfaces'][self._INTERFACE_NAME], )
151167

168+
# Save a dictionary of cached API call functions.
169+
# These are the actual callables which invoke the proper
170+
# transport methods, wrapped with `wrap_method` to add retry,
171+
# timeout, and the like.
152172
self._inner_api_calls = {}
153173

154-
def _intercept_channel(self, *interceptors):
155-
""" Experimental. Bind gRPC interceptors to the gRPC channel.
156-
157-
Args:
158-
interceptors (*Union[grpc.UnaryUnaryClientInterceptor, grpc.UnaryStreamingClientInterceptor, grpc.StreamingUnaryClientInterceptor, grpc.StreamingStreamingClientInterceptor]):
159-
Zero or more gRPC interceptors. Interceptors are given control in the order
160-
they are listed.
161-
Raises:
162-
TypeError: If interceptor does not derive from any of
163-
UnaryUnaryClientInterceptor,
164-
UnaryStreamClientInterceptor,
165-
StreamUnaryClientInterceptor, or
166-
StreamStreamClientInterceptor.
167-
"""
168-
self.channel = grpc.intercept_channel(self.channel, *interceptors)
169-
self._alert_policy_service_stub = (
170-
alert_service_pb2_grpc.AlertPolicyServiceStub(self.channel))
171-
self._inner_api_calls.clear()
172-
173174
# Service calls
174175
def list_alert_policies(self,
175176
name,
@@ -254,10 +255,11 @@ def list_alert_policies(self,
254255
if metadata is None:
255256
metadata = []
256257
metadata = list(metadata)
258+
# Wrap the transport method to add retry and timeout logic.
257259
if 'list_alert_policies' not in self._inner_api_calls:
258260
self._inner_api_calls[
259261
'list_alert_policies'] = google.api_core.gapic_v1.method.wrap_method(
260-
self._alert_policy_service_stub.ListAlertPolicies,
262+
self.transport.list_alert_policies,
261263
default_retry=self._method_configs[
262264
'ListAlertPolicies'].retry,
263265
default_timeout=self._method_configs['ListAlertPolicies']
@@ -328,10 +330,11 @@ def get_alert_policy(self,
328330
if metadata is None:
329331
metadata = []
330332
metadata = list(metadata)
333+
# Wrap the transport method to add retry and timeout logic.
331334
if 'get_alert_policy' not in self._inner_api_calls:
332335
self._inner_api_calls[
333336
'get_alert_policy'] = google.api_core.gapic_v1.method.wrap_method(
334-
self._alert_policy_service_stub.GetAlertPolicy,
337+
self.transport.get_alert_policy,
335338
default_retry=self._method_configs['GetAlertPolicy'].retry,
336339
default_timeout=self._method_configs['GetAlertPolicy']
337340
.timeout,
@@ -399,10 +402,11 @@ def create_alert_policy(self,
399402
if metadata is None:
400403
metadata = []
401404
metadata = list(metadata)
405+
# Wrap the transport method to add retry and timeout logic.
402406
if 'create_alert_policy' not in self._inner_api_calls:
403407
self._inner_api_calls[
404408
'create_alert_policy'] = google.api_core.gapic_v1.method.wrap_method(
405-
self._alert_policy_service_stub.CreateAlertPolicy,
409+
self.transport.create_alert_policy,
406410
default_retry=self._method_configs[
407411
'CreateAlertPolicy'].retry,
408412
default_timeout=self._method_configs['CreateAlertPolicy']
@@ -459,10 +463,11 @@ def delete_alert_policy(self,
459463
if metadata is None:
460464
metadata = []
461465
metadata = list(metadata)
466+
# Wrap the transport method to add retry and timeout logic.
462467
if 'delete_alert_policy' not in self._inner_api_calls:
463468
self._inner_api_calls[
464469
'delete_alert_policy'] = google.api_core.gapic_v1.method.wrap_method(
465-
self._alert_policy_service_stub.DeleteAlertPolicy,
470+
self.transport.delete_alert_policy,
466471
default_retry=self._method_configs[
467472
'DeleteAlertPolicy'].retry,
468473
default_timeout=self._method_configs['DeleteAlertPolicy']
@@ -549,10 +554,11 @@ def update_alert_policy(self,
549554
if metadata is None:
550555
metadata = []
551556
metadata = list(metadata)
557+
# Wrap the transport method to add retry and timeout logic.
552558
if 'update_alert_policy' not in self._inner_api_calls:
553559
self._inner_api_calls[
554560
'update_alert_policy'] = google.api_core.gapic_v1.method.wrap_method(
555-
self._alert_policy_service_stub.UpdateAlertPolicy,
561+
self.transport.update_alert_policy,
556562
default_retry=self._method_configs[
557563
'UpdateAlertPolicy'].retry,
558564
default_timeout=self._method_configs['UpdateAlertPolicy']

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.