From f5af16439807a0954ee78fa91cb69b9493b80176 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 12 Oct 2021 14:20:05 -0400 Subject: [PATCH] feat: add context manager support in client (#415) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add context manager support in client chore: fix docstring for first attribute of protos committer: @busunkim96 PiperOrigin-RevId: 401271153 Source-Link: https://github.com/googleapis/googleapis/commit/787f8c9a731f44e74a90b9847d48659ca9462d10 Source-Link: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- .../config_service_v2/async_client.py | 6 +++ .../services/config_service_v2/client.py | 18 +++++-- .../config_service_v2/transports/base.py | 9 ++++ .../config_service_v2/transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ .../logging_service_v2/async_client.py | 6 +++ .../services/logging_service_v2/client.py | 18 +++++-- .../logging_service_v2/transports/base.py | 9 ++++ .../logging_service_v2/transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ .../metrics_service_v2/async_client.py | 6 +++ .../services/metrics_service_v2/client.py | 18 +++++-- .../metrics_service_v2/transports/base.py | 9 ++++ .../metrics_service_v2/transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ google/cloud/logging_v2/types/log_entry.py | 1 + google/cloud/logging_v2/types/logging.py | 15 +++++- .../cloud/logging_v2/types/logging_config.py | 27 ++++++++++ .../cloud/logging_v2/types/logging_metrics.py | 6 +++ .../logging_v2/test_config_service_v2.py | 50 +++++++++++++++++++ .../logging_v2/test_logging_service_v2.py | 50 +++++++++++++++++++ .../logging_v2/test_metrics_service_v2.py | 50 +++++++++++++++++++ 22 files changed, 303 insertions(+), 13 deletions(-) diff --git a/google/cloud/logging_v2/services/config_service_v2/async_client.py b/google/cloud/logging_v2/services/config_service_v2/async_client.py index 634c106b..f6dfc328 100644 --- a/google/cloud/logging_v2/services/config_service_v2/async_client.py +++ b/google/cloud/logging_v2/services/config_service_v2/async_client.py @@ -1929,6 +1929,12 @@ async def update_cmek_settings( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/logging_v2/services/config_service_v2/client.py b/google/cloud/logging_v2/services/config_service_v2/client.py index d14827a1..f24b6caf 100644 --- a/google/cloud/logging_v2/services/config_service_v2/client.py +++ b/google/cloud/logging_v2/services/config_service_v2/client.py @@ -397,10 +397,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def list_buckets( @@ -2091,6 +2088,19 @@ def update_cmek_settings( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/logging_v2/services/config_service_v2/transports/base.py b/google/cloud/logging_v2/services/config_service_v2/transports/base.py index 1ffcb227..cf32b364 100644 --- a/google/cloud/logging_v2/services/config_service_v2/transports/base.py +++ b/google/cloud/logging_v2/services/config_service_v2/transports/base.py @@ -322,6 +322,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def list_buckets( self, diff --git a/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py b/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py index 7fb2560b..cd06eac4 100644 --- a/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py +++ b/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py @@ -883,5 +883,8 @@ def update_cmek_settings( ) return self._stubs["update_cmek_settings"] + def close(self): + self.grpc_channel.close() + __all__ = ("ConfigServiceV2GrpcTransport",) diff --git a/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py b/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py index 9a844e7c..4fd93295 100644 --- a/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py +++ b/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py @@ -915,5 +915,8 @@ def update_cmek_settings( ) return self._stubs["update_cmek_settings"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ConfigServiceV2GrpcAsyncIOTransport",) diff --git a/google/cloud/logging_v2/services/logging_service_v2/async_client.py b/google/cloud/logging_v2/services/logging_service_v2/async_client.py index 6a11e96c..01b369de 100644 --- a/google/cloud/logging_v2/services/logging_service_v2/async_client.py +++ b/google/cloud/logging_v2/services/logging_service_v2/async_client.py @@ -779,6 +779,12 @@ def tail_log_entries( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/logging_v2/services/logging_service_v2/client.py b/google/cloud/logging_v2/services/logging_service_v2/client.py index 73909c7f..75410c30 100644 --- a/google/cloud/logging_v2/services/logging_service_v2/client.py +++ b/google/cloud/logging_v2/services/logging_service_v2/client.py @@ -341,10 +341,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def delete_log( @@ -886,6 +883,19 @@ def tail_log_entries( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/logging_v2/services/logging_service_v2/transports/base.py b/google/cloud/logging_v2/services/logging_service_v2/transports/base.py index 05c273d6..8b3ff755 100644 --- a/google/cloud/logging_v2/services/logging_service_v2/transports/base.py +++ b/google/cloud/logging_v2/services/logging_service_v2/transports/base.py @@ -257,6 +257,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def delete_log( self, diff --git a/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py b/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py index a1031e93..146f97cb 100644 --- a/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py +++ b/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py @@ -404,5 +404,8 @@ def tail_log_entries( ) return self._stubs["tail_log_entries"] + def close(self): + self.grpc_channel.close() + __all__ = ("LoggingServiceV2GrpcTransport",) diff --git a/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py b/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py index a71fb28f..cc2e1368 100644 --- a/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py +++ b/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py @@ -415,5 +415,8 @@ def tail_log_entries( ) return self._stubs["tail_log_entries"] + def close(self): + return self.grpc_channel.close() + __all__ = ("LoggingServiceV2GrpcAsyncIOTransport",) diff --git a/google/cloud/logging_v2/services/metrics_service_v2/async_client.py b/google/cloud/logging_v2/services/metrics_service_v2/async_client.py index defd64a1..8c719a64 100644 --- a/google/cloud/logging_v2/services/metrics_service_v2/async_client.py +++ b/google/cloud/logging_v2/services/metrics_service_v2/async_client.py @@ -635,6 +635,12 @@ async def delete_log_metric( request, retry=retry, timeout=timeout, metadata=metadata, ) + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/logging_v2/services/metrics_service_v2/client.py b/google/cloud/logging_v2/services/metrics_service_v2/client.py index 7d1e2a21..f03e3cb0 100644 --- a/google/cloud/logging_v2/services/metrics_service_v2/client.py +++ b/google/cloud/logging_v2/services/metrics_service_v2/client.py @@ -344,10 +344,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def list_log_metrics( @@ -777,6 +774,19 @@ def delete_log_metric( request, retry=retry, timeout=timeout, metadata=metadata, ) + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py b/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py index 1ce8b3a6..f8855cc3 100644 --- a/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py +++ b/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py @@ -228,6 +228,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def list_log_metrics( self, diff --git a/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py b/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py index 49e7263d..4dc00d79 100644 --- a/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py +++ b/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py @@ -358,5 +358,8 @@ def delete_log_metric( ) return self._stubs["delete_log_metric"] + def close(self): + self.grpc_channel.close() + __all__ = ("MetricsServiceV2GrpcTransport",) diff --git a/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py b/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py index 9ddc1975..2623e7d0 100644 --- a/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py +++ b/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py @@ -368,5 +368,8 @@ def delete_log_metric( ) return self._stubs["delete_log_metric"] + def close(self): + return self.grpc_channel.close() + __all__ = ("MetricsServiceV2GrpcAsyncIOTransport",) diff --git a/google/cloud/logging_v2/types/log_entry.py b/google/cloud/logging_v2/types/log_entry.py index 6c57b22d..2b7aed28 100644 --- a/google/cloud/logging_v2/types/log_entry.py +++ b/google/cloud/logging_v2/types/log_entry.py @@ -31,6 +31,7 @@ class LogEntry(proto.Message): r"""An individual entry in a log. + Attributes: log_name (str): Required. The resource name of the log to which this log diff --git a/google/cloud/logging_v2/types/logging.py b/google/cloud/logging_v2/types/logging.py index 6d64b9a9..8477c2a4 100644 --- a/google/cloud/logging_v2/types/logging.py +++ b/google/cloud/logging_v2/types/logging.py @@ -42,6 +42,7 @@ class DeleteLogRequest(proto.Message): r"""The parameters to DeleteLog. + Attributes: log_name (str): Required. The resource name of the log to delete: @@ -65,6 +66,7 @@ class DeleteLogRequest(proto.Message): class WriteLogEntriesRequest(proto.Message): r"""The parameters to WriteLogEntries. + Attributes: log_name (str): Optional. A default log resource name that is assigned to @@ -164,11 +166,13 @@ class WriteLogEntriesRequest(proto.Message): class WriteLogEntriesResponse(proto.Message): - r"""Result returned from WriteLogEntries. """ + r"""Result returned from WriteLogEntries. + """ class WriteLogEntriesPartialErrors(proto.Message): r"""Error details for WriteLogEntries with partial success. + Attributes: log_entry_errors (Sequence[google.cloud.logging_v2.types.WriteLogEntriesPartialErrors.LogEntryErrorsEntry]): When ``WriteLogEntriesRequest.partial_success`` is true, @@ -187,6 +191,7 @@ class WriteLogEntriesPartialErrors(proto.Message): class ListLogEntriesRequest(proto.Message): r"""The parameters to ``ListLogEntries``. + Attributes: resource_names (Sequence[str]): Required. Names of one or more parent resources from which @@ -249,6 +254,7 @@ class ListLogEntriesRequest(proto.Message): class ListLogEntriesResponse(proto.Message): r"""Result returned from ``ListLogEntries``. + Attributes: entries (Sequence[google.cloud.logging_v2.types.LogEntry]): A list of log entries. If ``entries`` is empty, @@ -281,6 +287,7 @@ def raw_page(self): class ListMonitoredResourceDescriptorsRequest(proto.Message): r"""The parameters to ListMonitoredResourceDescriptors + Attributes: page_size (int): Optional. The maximum number of results to return from this @@ -301,6 +308,7 @@ class ListMonitoredResourceDescriptorsRequest(proto.Message): class ListMonitoredResourceDescriptorsResponse(proto.Message): r"""Result returned from ListMonitoredResourceDescriptors. + Attributes: resource_descriptors (Sequence[google.api.monitored_resource_pb2.MonitoredResourceDescriptor]): A list of resource descriptors. @@ -325,6 +333,7 @@ def raw_page(self): class ListLogsRequest(proto.Message): r"""The parameters to ListLogs. + Attributes: parent (str): Required. The resource name that owns the logs: @@ -366,6 +375,7 @@ class ListLogsRequest(proto.Message): class ListLogsResponse(proto.Message): r"""Result returned from ListLogs. + Attributes: log_names (Sequence[str]): A list of log names. For example, @@ -388,6 +398,7 @@ def raw_page(self): class TailLogEntriesRequest(proto.Message): r"""The parameters to ``TailLogEntries``. + Attributes: resource_names (Sequence[str]): Required. Name of a parent resource from which to retrieve @@ -431,6 +442,7 @@ class TailLogEntriesRequest(proto.Message): class TailLogEntriesResponse(proto.Message): r"""Result returned from ``TailLogEntries``. + Attributes: entries (Sequence[google.cloud.logging_v2.types.LogEntry]): A list of log entries. Each response in the stream will @@ -450,6 +462,7 @@ class TailLogEntriesResponse(proto.Message): class SuppressionInfo(proto.Message): r"""Information about entries that were omitted from the session. + Attributes: reason (google.cloud.logging_v2.types.TailLogEntriesResponse.SuppressionInfo.Reason): The reason that entries were omitted from the diff --git a/google/cloud/logging_v2/types/logging_config.py b/google/cloud/logging_v2/types/logging_config.py index 9b628073..795efbf9 100644 --- a/google/cloud/logging_v2/types/logging_config.py +++ b/google/cloud/logging_v2/types/logging_config.py @@ -69,6 +69,7 @@ class LifecycleState(proto.Enum): class LogBucket(proto.Message): r"""Describes a repository of logs. + Attributes: name (str): The resource name of the bucket. For example: @@ -114,6 +115,7 @@ class LogBucket(proto.Message): class LogView(proto.Message): r"""Describes a view over logs in a bucket. + Attributes: name (str): The resource name of the view. @@ -303,6 +305,7 @@ class BigQueryOptions(proto.Message): class ListBucketsRequest(proto.Message): r"""The parameters to ``ListBuckets``. + Attributes: parent (str): Required. The parent resource whose buckets are to be @@ -338,6 +341,7 @@ class ListBucketsRequest(proto.Message): class ListBucketsResponse(proto.Message): r"""The response from ListBuckets. + Attributes: buckets (Sequence[google.cloud.logging_v2.types.LogBucket]): A list of buckets. @@ -358,6 +362,7 @@ def raw_page(self): class CreateBucketRequest(proto.Message): r"""The parameters to ``CreateBucket``. + Attributes: parent (str): Required. The resource in which to create the bucket: @@ -386,6 +391,7 @@ class CreateBucketRequest(proto.Message): class UpdateBucketRequest(proto.Message): r"""The parameters to ``UpdateBucket``. + Attributes: name (str): Required. The full resource name of the bucket to update. @@ -425,6 +431,7 @@ class UpdateBucketRequest(proto.Message): class GetBucketRequest(proto.Message): r"""The parameters to ``GetBucket``. + Attributes: name (str): Required. The resource name of the bucket: @@ -445,6 +452,7 @@ class GetBucketRequest(proto.Message): class DeleteBucketRequest(proto.Message): r"""The parameters to ``DeleteBucket``. + Attributes: name (str): Required. The full resource name of the bucket to delete. @@ -465,6 +473,7 @@ class DeleteBucketRequest(proto.Message): class UndeleteBucketRequest(proto.Message): r"""The parameters to ``UndeleteBucket``. + Attributes: name (str): Required. The full resource name of the bucket to undelete. @@ -485,6 +494,7 @@ class UndeleteBucketRequest(proto.Message): class ListViewsRequest(proto.Message): r"""The parameters to ``ListViews``. + Attributes: parent (str): Required. The bucket whose views are to be listed: @@ -512,6 +522,7 @@ class ListViewsRequest(proto.Message): class ListViewsResponse(proto.Message): r"""The response from ListViews. + Attributes: views (Sequence[google.cloud.logging_v2.types.LogView]): A list of views. @@ -532,6 +543,7 @@ def raw_page(self): class CreateViewRequest(proto.Message): r"""The parameters to ``CreateView``. + Attributes: parent (str): Required. The bucket in which to create the view @@ -555,6 +567,7 @@ class CreateViewRequest(proto.Message): class UpdateViewRequest(proto.Message): r"""The parameters to ``UpdateView``. + Attributes: name (str): Required. The full resource name of the view to update @@ -588,6 +601,7 @@ class UpdateViewRequest(proto.Message): class GetViewRequest(proto.Message): r"""The parameters to ``GetView``. + Attributes: name (str): Required. The resource name of the policy: @@ -605,6 +619,7 @@ class GetViewRequest(proto.Message): class DeleteViewRequest(proto.Message): r"""The parameters to ``DeleteView``. + Attributes: name (str): Required. The full resource name of the view to delete: @@ -622,6 +637,7 @@ class DeleteViewRequest(proto.Message): class ListSinksRequest(proto.Message): r"""The parameters to ``ListSinks``. + Attributes: parent (str): Required. The parent resource whose sinks are to be listed: @@ -652,6 +668,7 @@ class ListSinksRequest(proto.Message): class ListSinksResponse(proto.Message): r"""Result returned from ``ListSinks``. + Attributes: sinks (Sequence[google.cloud.logging_v2.types.LogSink]): A list of sinks. @@ -672,6 +689,7 @@ def raw_page(self): class GetSinkRequest(proto.Message): r"""The parameters to ``GetSink``. + Attributes: sink_name (str): Required. The resource name of the sink: @@ -691,6 +709,7 @@ class GetSinkRequest(proto.Message): class CreateSinkRequest(proto.Message): r"""The parameters to ``CreateSink``. + Attributes: parent (str): Required. The resource in which to create the sink: @@ -731,6 +750,7 @@ class CreateSinkRequest(proto.Message): class UpdateSinkRequest(proto.Message): r"""The parameters to ``UpdateSink``. + Attributes: sink_name (str): Required. The full resource name of the sink to update, @@ -791,6 +811,7 @@ class UpdateSinkRequest(proto.Message): class DeleteSinkRequest(proto.Message): r"""The parameters to ``DeleteSink``. + Attributes: sink_name (str): Required. The full resource name of the sink to delete, @@ -865,6 +886,7 @@ class LogExclusion(proto.Message): class ListExclusionsRequest(proto.Message): r"""The parameters to ``ListExclusions``. + Attributes: parent (str): Required. The parent resource whose exclusions are to be @@ -896,6 +918,7 @@ class ListExclusionsRequest(proto.Message): class ListExclusionsResponse(proto.Message): r"""Result returned from ``ListExclusions``. + Attributes: exclusions (Sequence[google.cloud.logging_v2.types.LogExclusion]): A list of exclusions. @@ -916,6 +939,7 @@ def raw_page(self): class GetExclusionRequest(proto.Message): r"""The parameters to ``GetExclusion``. + Attributes: name (str): Required. The resource name of an existing exclusion: @@ -936,6 +960,7 @@ class GetExclusionRequest(proto.Message): class CreateExclusionRequest(proto.Message): r"""The parameters to ``CreateExclusion``. + Attributes: parent (str): Required. The parent resource in which to create the @@ -962,6 +987,7 @@ class CreateExclusionRequest(proto.Message): class UpdateExclusionRequest(proto.Message): r"""The parameters to ``UpdateExclusion``. + Attributes: name (str): Required. The resource name of the exclusion to update: @@ -1000,6 +1026,7 @@ class UpdateExclusionRequest(proto.Message): class DeleteExclusionRequest(proto.Message): r"""The parameters to ``DeleteExclusion``. + Attributes: name (str): Required. The resource name of an existing exclusion to diff --git a/google/cloud/logging_v2/types/logging_metrics.py b/google/cloud/logging_v2/types/logging_metrics.py index 4b39650f..26d85568 100644 --- a/google/cloud/logging_v2/types/logging_metrics.py +++ b/google/cloud/logging_v2/types/logging_metrics.py @@ -187,6 +187,7 @@ class ApiVersion(proto.Enum): class ListLogMetricsRequest(proto.Message): r"""The parameters to ListLogMetrics. + Attributes: parent (str): Required. The name of the project containing the metrics: @@ -214,6 +215,7 @@ class ListLogMetricsRequest(proto.Message): class ListLogMetricsResponse(proto.Message): r"""Result returned from ListLogMetrics. + Attributes: metrics (Sequence[google.cloud.logging_v2.types.LogMetric]): A list of logs-based metrics. @@ -234,6 +236,7 @@ def raw_page(self): class GetLogMetricRequest(proto.Message): r"""The parameters to GetLogMetric. + Attributes: metric_name (str): Required. The resource name of the desired metric: @@ -248,6 +251,7 @@ class GetLogMetricRequest(proto.Message): class CreateLogMetricRequest(proto.Message): r"""The parameters to CreateLogMetric. + Attributes: parent (str): Required. The resource name of the project in which to @@ -269,6 +273,7 @@ class CreateLogMetricRequest(proto.Message): class UpdateLogMetricRequest(proto.Message): r"""The parameters to UpdateLogMetric. + Attributes: metric_name (str): Required. The resource name of the metric to update: @@ -291,6 +296,7 @@ class UpdateLogMetricRequest(proto.Message): class DeleteLogMetricRequest(proto.Message): r"""The parameters to DeleteLogMetric. + Attributes: metric_name (str): Required. The resource name of the metric to delete: diff --git a/tests/unit/gapic/logging_v2/test_config_service_v2.py b/tests/unit/gapic/logging_v2/test_config_service_v2.py index 12a5cf89..c796dc65 100644 --- a/tests/unit/gapic/logging_v2/test_config_service_v2.py +++ b/tests/unit/gapic/logging_v2/test_config_service_v2.py @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.logging_v2.services.config_service_v2 import ( @@ -5437,6 +5438,9 @@ def test_config_service_v2_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + @requires_google_auth_gte_1_25_0 def test_config_service_v2_base_transport_with_credentials_file(): @@ -6040,3 +6044,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/logging_v2/test_logging_service_v2.py b/tests/unit/gapic/logging_v2/test_logging_service_v2.py index 1bf1ac26..df261666 100644 --- a/tests/unit/gapic/logging_v2/test_logging_service_v2.py +++ b/tests/unit/gapic/logging_v2/test_logging_service_v2.py @@ -30,6 +30,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.logging_v2.services.logging_service_v2 import ( @@ -1969,6 +1970,9 @@ def test_logging_service_v2_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + @requires_google_auth_gte_1_25_0 def test_logging_service_v2_base_transport_with_credentials_file(): @@ -2489,3 +2493,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = LoggingServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/logging_v2/test_metrics_service_v2.py b/tests/unit/gapic/logging_v2/test_metrics_service_v2.py index 7455f075..4d2e8dba 100644 --- a/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +++ b/tests/unit/gapic/logging_v2/test_metrics_service_v2.py @@ -33,6 +33,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.logging_v2.services.metrics_service_v2 import ( @@ -1892,6 +1893,9 @@ def test_metrics_service_v2_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + @requires_google_auth_gte_1_25_0 def test_metrics_service_v2_base_transport_with_credentials_file(): @@ -2414,3 +2418,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = MetricsServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called()