diff --git a/gcloud/logging/config_service_v2_api.py b/gcloud/logging/config_service_v2_api.py index 37fc918cec90..0f32255bfa2f 100644 --- a/gcloud/logging/config_service_v2_api.py +++ b/gcloud/logging/config_service_v2_api.py @@ -14,64 +14,130 @@ # # EDITING INSTRUCTIONS # This file was generated from the file -# https://github.com/google/googleapis/blob/7710ead495227e80a0f06ceb66bdf3238d926f77/google/logging/v2/logging_config.proto, +# https://github.com/google/googleapis/blob/master/google/logging/v2/logging_config.proto, # and updates to that file get reflected here through a refresh process. # For the short term, the refresh process will only be runnable by Google engineers. -# Manual additions are allowed because the refresh process performs -# a 3-way merge in order to preserve those manual additions. In order to not -# break the refresh process, only certain types of modifications are -# allowed. # -# Allowed modifications: -# 1. New methods (these should be added to the end of the class) -# -# Happy editing! +# The only allowed edits are to method and file documentation. A 3-way +# merge preserves those additions if the generated source changes. +"""Accesses the google.logging.v2 ConfigServiceV2 API.""" + +import json +import os +import pkg_resources +import platform from google.gax import api_callable -from google.gax import api_utils -from google.gax import page_descriptor +from google.gax import config +from google.gax import path_template +import google.gax + from google.logging.v2 import logging_config_pb2 +_PageDesc = google.gax.PageDescriptor + class ConfigServiceV2Api(object): + SERVICE_ADDRESS = 'logging.googleapis.com' + """The default address of the service.""" - # The default address of the logging service. - _SERVICE_ADDRESS = 'logging.googleapis.com' + DEFAULT_SERVICE_PORT = 443 + """The default port of the service.""" - # The default port of the logging service. - _DEFAULT_SERVICE_PORT = 443 + _CODE_GEN_NAME_VERSION = 'gapic/0.1.0' + + _GAX_VERSION = pkg_resources.get_distribution('google-gax').version + + _DEFAULT_TIMEOUT = 30 + + _PAGE_DESCRIPTORS = { + 'list_sinks': _PageDesc('page_token', 'next_page_token', 'sinks') + } # The scopes needed to make gRPC calls to all of the methods defined in # this service - _ALL_SCOPES = ( - 'https://www.googleapis.com/auth/logging.write', - 'https://www.googleapis.com/auth/logging.admin', - 'https://www.googleapis.com/auth/logging.read', - 'https://www.googleapis.com/auth/cloud-platform.read-only', - 'https://www.googleapis.com/auth/cloud-platform', - ) - - _LIST_SINKS_DESCRIPTOR = page_descriptor.PageDescriptor( - 'page_token', - 'next_page_token', - 'sinks', - ) - - def __init__( - self, - service_path=_SERVICE_ADDRESS, - port=_DEFAULT_SERVICE_PORT, - channel=None, - ssl_creds=None, - scopes=_ALL_SCOPES, - is_idempotent_retrying=True, - max_attempts=3, - timeout=30): - self.defaults = api_callable.ApiCallableDefaults( - timeout=timeout, - max_attempts=max_attempts, - is_idempotent_retrying=is_idempotent_retrying) - self.stub = api_utils.create_stub( + _ALL_SCOPES = ('https://www.googleapis.com/auth/logging.write', + 'https://www.googleapis.com/auth/logging.admin', + 'https://www.googleapis.com/auth/logging.read', + 'https://www.googleapis.com/auth/cloud-platform.read-only', + 'https://www.googleapis.com/auth/cloud-platform', ) + + _PROJECT_PATH_TEMPLATE = path_template.PathTemplate('projects/{project}') + _SINK_PATH_TEMPLATE = path_template.PathTemplate( + 'projects/{project}/sinks/{sink}') + + @classmethod + def project_path(cls, project): + """Returns a fully-qualified project resource name string.""" + return cls._PROJECT_PATH_TEMPLATE.instantiate({'project': project, }) + + @classmethod + def sink_path(cls, project, sink): + """Returns a fully-qualified sink resource name string.""" + return cls._SINK_PATH_TEMPLATE.instantiate({ + 'project': project, + 'sink': sink, + }) + + def __init__(self, + service_path=SERVICE_ADDRESS, + port=DEFAULT_SERVICE_PORT, + channel=None, + ssl_creds=None, + scopes=None, + retrying_override=None, + bundling_override=None, + timeout=_DEFAULT_TIMEOUT, + app_name='gax', + app_version=_GAX_VERSION): + """Constructor. + + Args: + service_path (string): The domain name of the API remote host. + port (int): The port on which to connect to the remote host. + channel (:class:`grpc.beta.implementations.Channel`): A ``Channel`` + object through which to make calls. + ssl_creds (:class:`grpc.beta.implementations.ClientCredentials`): + A `ClientCredentials` for use with an SSL-enabled channel. + retrying_override (dict[string, :class:`google.gax.RetryOptions`]): A + dictionary that overrides default retrying settings. + ``retrying_override`` maps method names (e.g., ``'list_foo'``) to + custom RetryOptions objects, or to None. A value of None indicates + that the method in question should not retry. + bundling_override (dict[string, :class:`google.gax.BundleOptions`]): A + dictionary that overrides default bundling settings. + ``bundling_override`` maps bundling method names (e.g., + 'publish_foo') to custom BundleOptions objects, or to None. It is + invalid to have a key for a method that is not bundling-enabled. A + value of None indicates that the method in question should not + bundle. + timeout (int): The default timeout, in seconds, for calls made + through this client + app_name (string): The codename of the calling service. + app_version (string): The version of the calling service. + + Returns: + A ConfigServiceV2Api object. + """ + if scopes is None: + scopes = self._ALL_SCOPES + bundling_override = bundling_override or {} + retrying_override = retrying_override or {} + client_config = pkg_resources.resource_string( + __name__, 'config_service_v2_client_config.json') + self._defaults = api_callable.construct_settings( + 'google.logging.v2.ConfigServiceV2', + json.loads(client_config), + bundling_override, + retrying_override, + config.STATUS_CODE_NAMES, + timeout, + page_descriptors=self._PAGE_DESCRIPTORS) + google_apis_agent = '{}/{};{};gax/{};python/{}'.format( + app_name, app_version, self._CODE_GEN_NAME_VERSION, + self._GAX_VERSION, platform.python_version()) + self._headers = [('x-google-apis-agent', google_apis_agent)] + self.stub = config.create_stub( logging_config_pb2.beta_create_ConfigServiceV2_stub, service_path, port, @@ -79,126 +145,131 @@ def __init__( channel=channel, scopes=scopes) - def __enter__(self): - return self + # Service calls + def list_sinks(self, project_name='', options=None): + """ + Lists sinks. + + Args: + project_name (string): Required. The resource name of the project containing the sinks. + Example: `"projects/my-logging-project"`, `"projects/01234567890"`. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. - def __exit__(self, exc_type, exc_val, exc_tb): - self.close() + Yields: + Instances of :class:`google.logging.v2.logging_config_pb2.LogSink` + unless page streaming is disabled through the call options. If + page streaming is disabled, a single + :class:`google.logging.v2.logging_config_pb2.ListSinksResponse` instance + is returned. - def close(self): - del self.stub + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + """ + req = logging_config_pb2.ListSinksRequest(project_name=project_name) + settings = self._defaults['list_sinks'].merge(options) + api_call = api_callable.create_api_call(self.stub.ListSinks, + settings=settings) + return api_call(req, metadata=self._headers) - # Service calls - def list_sinks( - self, - project_name='', - **kwargs): - """Lists sinks.""" - list_sinks_request = logging_config_pb2.ListSinksRequest( - project_name=project_name, - **kwargs) - return self.list_sinks_callable()(list_sinks_request) - - def list_sinks_callable( - self, - is_retrying=None, - max_attempts=None, - page_streaming=_LIST_SINKS_DESCRIPTOR): - return api_callable.idempotent_callable( - self.stub.ListSinks, - page_streaming=page_streaming, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - def get_sink( - self, - sink_name='', - **kwargs): - """Gets a sink.""" - get_sink_request = logging_config_pb2.GetSinkRequest( - sink_name=sink_name, - **kwargs) - return self.get_sink_callable()(get_sink_request) - - def get_sink_callable( - self, - is_retrying=None, - max_attempts=None): - return api_callable.idempotent_callable( - self.stub.GetSink, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - def create_sink( - self, - project_name='', - sink=None, - **kwargs): - """Creates a sink.""" + def get_sink(self, sink_name='', options=None): + """ + Gets a sink. + + Args: + sink_name (string): The resource name of the sink to return. + Example: `"projects/my-project-id/sinks/my-sink-id"`. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`google.logging.v2.logging_config_pb2.LogSink` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + """ + req = logging_config_pb2.GetSinkRequest(sink_name=sink_name) + settings = self._defaults['get_sink'].merge(options) + api_call = api_callable.create_api_call(self.stub.GetSink, + settings=settings) + return api_call(req, metadata=self._headers) + + def create_sink(self, project_name='', sink=None, options=None): + """ + Creates a sink. + + Args: + project_name (string): The resource name of the project in which to create the sink. + Example: `"projects/my-project-id"`. + + The new sink must be provided in the request. + sink (:class:`google.logging.v2.logging_config_pb2.LogSink`): The new sink, which must not have an identifier that already + exists. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`google.logging.v2.logging_config_pb2.LogSink` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + """ if sink is None: sink = logging_config_pb2.LogSink() - create_sink_request = logging_config_pb2.CreateSinkRequest( - project_name=project_name, - sink=sink, - **kwargs) - return self.create_sink_callable()(create_sink_request) - - def create_sink_callable( - self, - is_retrying=None, - max_attempts=None): - return api_callable.idempotent_callable( - self.stub.CreateSink, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - def update_sink( - self, - sink_name='', - sink=None, - **kwargs): - """Creates or updates a sink.""" + req = logging_config_pb2.CreateSinkRequest(project_name=project_name, + sink=sink) + settings = self._defaults['create_sink'].merge(options) + api_call = api_callable.create_api_call(self.stub.CreateSink, + settings=settings) + return api_call(req, metadata=self._headers) + + def update_sink(self, sink_name='', sink=None, options=None): + """ + Creates or updates a sink. + + Args: + sink_name (string): The resource name of the sink to update. + Example: `"projects/my-project-id/sinks/my-sink-id"`. + + The updated sink must be provided in the request and have the + same name that is specified in `sinkName`. If the sink does not + exist, it is created. + sink (:class:`google.logging.v2.logging_config_pb2.LogSink`): The updated sink, whose name must be the same as the sink + identifier in `sinkName`. If `sinkName` does not exist, then + this method creates a new sink. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`google.logging.v2.logging_config_pb2.LogSink` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + """ if sink is None: sink = logging_config_pb2.LogSink() - update_sink_request = logging_config_pb2.UpdateSinkRequest( - sink_name=sink_name, - sink=sink, - **kwargs) - return self.update_sink_callable()(update_sink_request) - - def update_sink_callable( - self, - is_retrying=None, - max_attempts=None): - return api_callable.idempotent_callable( - self.stub.UpdateSink, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - def delete_sink( - self, - sink_name='', - **kwargs): - """Deletes a sink.""" - delete_sink_request = logging_config_pb2.DeleteSinkRequest( - sink_name=sink_name, - **kwargs) - return self.delete_sink_callable()(delete_sink_request) - - def delete_sink_callable( - self, - is_retrying=None, - max_attempts=None): - return api_callable.idempotent_callable( - self.stub.DeleteSink, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - # ======== - # Manually-added methods: add custom (non-generated) methods after this point. - # ======== + req = logging_config_pb2.UpdateSinkRequest(sink_name=sink_name, + sink=sink) + settings = self._defaults['update_sink'].merge(options) + api_call = api_callable.create_api_call(self.stub.UpdateSink, + settings=settings) + return api_call(req, metadata=self._headers) + + def delete_sink(self, sink_name='', options=None): + """ + Deletes a sink. + + Args: + sink_name (string): The resource name of the sink to delete. + Example: `"projects/my-project-id/sinks/my-sink-id"`. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + """ + req = logging_config_pb2.DeleteSinkRequest(sink_name=sink_name) + settings = self._defaults['delete_sink'].merge(options) + api_call = api_callable.create_api_call(self.stub.DeleteSink, + settings=settings) + api_call(req, metadata=self._headers) diff --git a/gcloud/logging/config_service_v2_client_config.json b/gcloud/logging/config_service_v2_client_config.json new file mode 100644 index 000000000000..15c0855ea5fe --- /dev/null +++ b/gcloud/logging/config_service_v2_client_config.json @@ -0,0 +1,43 @@ +{ + "interfaces": { + "google.logging.v2.ConfigServiceV2": { + "retry_codes": { + "idempotent": ["UNAVAILABLE", "DEADLINE_EXCEEDED"], + "non_idempotent": [] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.2, + "max_retry_delay_millis": 1000, + "initial_rpc_timeout_millis": 7000, + "rpc_timeout_multiplier": 1.5, + "max_rpc_timeout_millis": 30000, + "total_timeout_millis": 45000 + } + }, + "methods": { + "ListSinks": { + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "GetSink": { + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "CreateSink": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "UpdateSink": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "DeleteSink": { + "retry_codes_name": "idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/gcloud/logging/logging_service_v2_api.py b/gcloud/logging/logging_service_v2_api.py index 1afbeb1bf043..5e05fb085451 100644 --- a/gcloud/logging/logging_service_v2_api.py +++ b/gcloud/logging/logging_service_v2_api.py @@ -14,71 +14,137 @@ # # EDITING INSTRUCTIONS # This file was generated from the file -# https://github.com/google/googleapis/blob/7710ead495227e80a0f06ceb66bdf3238d926f77/google/logging/v2/logging.proto, +# https://github.com/google/googleapis/blob/master/google/logging/v2/logging.proto, # and updates to that file get reflected here through a refresh process. # For the short term, the refresh process will only be runnable by Google engineers. -# Manual additions are allowed because the refresh process performs -# a 3-way merge in order to preserve those manual additions. In order to not -# break the refresh process, only certain types of modifications are -# allowed. # -# Allowed modifications: -# 1. New methods (these should be added to the end of the class) -# -# Happy editing! +# The only allowed edits are to method and file documentation. A 3-way +# merge preserves those additions if the generated source changes. +"""Accesses the google.logging.v2 LoggingServiceV2 API.""" + +import json +import os +import pkg_resources +import platform -from google.api import monitored_resource_pb2 from google.gax import api_callable -from google.gax import api_utils -from google.gax import page_descriptor +from google.gax import config +from google.gax import path_template +import google.gax + +from google.api import monitored_resource_pb2 from google.logging.v2 import log_entry_pb2 from google.logging.v2 import logging_pb2 +_PageDesc = google.gax.PageDescriptor + class LoggingServiceV2Api(object): """Service for ingesting and querying logs.""" - # The default address of the logging service. - _SERVICE_ADDRESS = 'logging.googleapis.com' + SERVICE_ADDRESS = 'logging.googleapis.com' + """The default address of the service.""" + + DEFAULT_SERVICE_PORT = 443 + """The default port of the service.""" + + _CODE_GEN_NAME_VERSION = 'gapic/0.1.0' + + _GAX_VERSION = pkg_resources.get_distribution('google-gax').version - # The default port of the logging service. - _DEFAULT_SERVICE_PORT = 443 + _DEFAULT_TIMEOUT = 30 + + _PAGE_DESCRIPTORS = { + 'list_log_entries': _PageDesc('page_token', 'next_page_token', + 'entries'), + 'list_monitored_resource_descriptors': _PageDesc( + 'page_token', 'next_page_token', 'resource_descriptors') + } # The scopes needed to make gRPC calls to all of the methods defined in # this service - _ALL_SCOPES = ( - 'https://www.googleapis.com/auth/logging.write', - 'https://www.googleapis.com/auth/logging.admin', - 'https://www.googleapis.com/auth/logging.read', - 'https://www.googleapis.com/auth/cloud-platform.read-only', - 'https://www.googleapis.com/auth/cloud-platform', - ) - - _LIST_LOG_ENTRIES_DESCRIPTOR = page_descriptor.PageDescriptor( - 'page_token', - 'next_page_token', - 'entries', - ) - _LIST_MONITORED_RESOURCE_DESCRIPTORS_DESCRIPTOR = page_descriptor.PageDescriptor( - 'page_token', - 'next_page_token', - 'resource_descriptors') - - def __init__( - self, - service_path=_SERVICE_ADDRESS, - port=_DEFAULT_SERVICE_PORT, - channel=None, - ssl_creds=None, - scopes=_ALL_SCOPES, - is_idempotent_retrying=True, - max_attempts=3, - timeout=30): - self.defaults = api_callable.ApiCallableDefaults( - timeout=timeout, - max_attempts=max_attempts, - is_idempotent_retrying=is_idempotent_retrying) - self.stub = api_utils.create_stub( + _ALL_SCOPES = ('https://www.googleapis.com/auth/logging.write', + 'https://www.googleapis.com/auth/logging.admin', + 'https://www.googleapis.com/auth/logging.read', + 'https://www.googleapis.com/auth/cloud-platform.read-only', + 'https://www.googleapis.com/auth/cloud-platform', ) + + _PROJECT_PATH_TEMPLATE = path_template.PathTemplate('projects/{project}') + _LOG_PATH_TEMPLATE = path_template.PathTemplate( + 'projects/{project}/logs/{log}') + + @classmethod + def project_path(cls, project): + """Returns a fully-qualified project resource name string.""" + return cls._PROJECT_PATH_TEMPLATE.instantiate({'project': project, }) + + @classmethod + def log_path(cls, project, log): + """Returns a fully-qualified log resource name string.""" + return cls._LOG_PATH_TEMPLATE.instantiate({ + 'project': project, + 'log': log, + }) + + def __init__(self, + service_path=SERVICE_ADDRESS, + port=DEFAULT_SERVICE_PORT, + channel=None, + ssl_creds=None, + scopes=None, + retrying_override=None, + bundling_override=None, + timeout=_DEFAULT_TIMEOUT, + app_name='gax', + app_version=_GAX_VERSION): + """Constructor. + + Args: + service_path (string): The domain name of the API remote host. + port (int): The port on which to connect to the remote host. + channel (:class:`grpc.beta.implementations.Channel`): A ``Channel`` + object through which to make calls. + ssl_creds (:class:`grpc.beta.implementations.ClientCredentials`): + A `ClientCredentials` for use with an SSL-enabled channel. + retrying_override (dict[string, :class:`google.gax.RetryOptions`]): A + dictionary that overrides default retrying settings. + ``retrying_override`` maps method names (e.g., ``'list_foo'``) to + custom RetryOptions objects, or to None. A value of None indicates + that the method in question should not retry. + bundling_override (dict[string, :class:`google.gax.BundleOptions`]): A + dictionary that overrides default bundling settings. + ``bundling_override`` maps bundling method names (e.g., + 'publish_foo') to custom BundleOptions objects, or to None. It is + invalid to have a key for a method that is not bundling-enabled. A + value of None indicates that the method in question should not + bundle. + timeout (int): The default timeout, in seconds, for calls made + through this client + app_name (string): The codename of the calling service. + app_version (string): The version of the calling service. + + Returns: + A LoggingServiceV2Api object. + """ + if scopes is None: + scopes = self._ALL_SCOPES + bundling_override = bundling_override or {} + retrying_override = retrying_override or {} + client_config = pkg_resources.resource_string( + __name__, 'logging_service_v2_client_config.json') + self._defaults = api_callable.construct_settings( + 'google.logging.v2.LoggingServiceV2', + json.loads(client_config), + bundling_override, + retrying_override, + config.STATUS_CODE_NAMES, + timeout, + page_descriptors=self._PAGE_DESCRIPTORS) + google_apis_agent = '{}/{};{};gax/{};python/{}'.format( + app_name, app_version, self._CODE_GEN_NAME_VERSION, + self._GAX_VERSION, platform.python_version()) + self._headers = [('x-google-apis-agent', google_apis_agent)] + self.stub = config.create_stub( logging_pb2.beta_create_LoggingServiceV2_stub, service_path, port, @@ -86,49 +152,55 @@ def __init__( channel=channel, scopes=scopes) - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_val, exc_tb): - self.close() - - def close(self): - del self.stub - # Service calls - def delete_log( - self, - log_name='', - **kwargs): + def delete_log(self, log_name='', options=None): """ Deletes a log and all its log entries. The log will reappear if it receives new entries. + + Args: + log_name (string): Required. The resource name of the log to delete. Example: + `"projects/my-project/logs/syslog"`. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. """ - delete_log_request = logging_pb2.DeleteLogRequest( - log_name=log_name, - **kwargs) - return self.delete_log_callable()(delete_log_request) - - def delete_log_callable( - self, - is_retrying=None, - max_attempts=None): - return api_callable.idempotent_callable( - self.stub.DeleteLog, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - def write_log_entries( - self, - log_name='', - resource=None, - labels=None, - entries=None, - **kwargs): + req = logging_pb2.DeleteLogRequest(log_name=log_name) + settings = self._defaults['delete_log'].merge(options) + api_call = api_callable.create_api_call(self.stub.DeleteLog, + settings=settings) + api_call(req, metadata=self._headers) + + def write_log_entries(self, + log_name='', + resource=None, + labels=None, + entries=None, + options=None): """ Writes log entries to Cloud Logging. All log entries in Cloud Logging are written by this method. + + Args: + log_name (string): Optional. A default log resource name for those log entries in `entries` + that do not specify their own `logName`. Example: + `"projects/my-project/logs/syslog"`. See + [LogEntry][google.logging.v2.LogEntry]. + resource (:class:`google.api.monitored_resource_pb2.MonitoredResource`): Optional. A default monitored resource for those log entries in `entries` + that do not specify their own `resource`. + labels (list[:class:`google.logging.v2.logging_pb2.WriteLogEntriesRequest.LabelsEntry`]): Optional. User-defined `key:value` items that are added to + the `labels` field of each log entry in `entries`, except when a log + entry specifies its own `key:value` item with the same key. + Example: `{ "size": "large", "color":"red" }` + entries (list[:class:`google.logging.v2.log_entry_pb2.LogEntry`]): Required. The log entries to write. The log entries must have values for + all required fields. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. """ if resource is None: resource = monitored_resource_pb2.MonitoredResource() @@ -136,73 +208,83 @@ def write_log_entries( labels = [] if entries is None: entries = [] - write_log_entries_request = logging_pb2.WriteLogEntriesRequest( - log_name=log_name, - resource=resource, - labels=labels, - entries=entries, - **kwargs) - return self.write_log_entries_callable()(write_log_entries_request) - - def write_log_entries_callable( - self, - is_retrying=None, - max_attempts=None): - return api_callable.idempotent_callable( - self.stub.WriteLogEntries, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - def list_log_entries( - self, - project_ids=None, - filter_='', - order_by='', - **kwargs): + req = logging_pb2.WriteLogEntriesRequest(log_name=log_name, + resource=resource, + labels=labels, + entries=entries) + settings = self._defaults['write_log_entries'].merge(options) + api_call = api_callable.create_api_call(self.stub.WriteLogEntries, + settings=settings) + api_call(req, metadata=self._headers) + + def list_log_entries(self, + project_ids=None, + filter_='', + order_by='', + options=None): """ Lists log entries. Use this method to retrieve log entries from Cloud Logging. For ways to export log entries, see - [Exporting Logs](/logging/docs/export). + `Exporting Logs `_. + + Args: + project_ids (list[string]): Required. One or more project IDs or project numbers from which to retrieve + log entries. Examples of a project ID: `"my-project-1A"`, `"1234567890"`. + filter (string): Optional. An [advanced logs filter](/logging/docs/view/advanced_filters). + The filter is compared against all log entries in the projects specified by + `projectIds`. Only entries that match the filter are retrieved. An empty + filter matches all log entries. + order_by (string): Optional. How the results should be sorted. Presently, the only permitted + values are `"timestamp"` (default) and `"timestamp desc"`. The first + option returns entries in order of increasing values of + `LogEntry.timestamp` (oldest first), and the second option returns entries + in order of decreasing timestamps (newest first). Entries with equal + timestamps are returned in order of `LogEntry.insertId`. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Yields: + Instances of :class:`google.logging.v2.log_entry_pb2.LogEntry` + unless page streaming is disabled through the call options. If + page streaming is disabled, a single + :class:`google.logging.v2.logging_pb2.ListLogEntriesResponse` instance + is returned. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. """ if project_ids is None: project_ids = [] - list_log_entries_request = logging_pb2.ListLogEntriesRequest( - project_ids=project_ids, - filter=filter_, - order_by=order_by, - **kwargs) - return self.list_log_entries_callable()(list_log_entries_request) - - def list_log_entries_callable( - self, - is_retrying=None, - max_attempts=None, - page_streaming=_LIST_LOG_ENTRIES_DESCRIPTOR): - return api_callable.idempotent_callable( - self.stub.ListLogEntries, - page_streaming=page_streaming, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - def list_monitored_resource_descriptors(self, **kwargs): - """Lists monitored resource descriptors that are used by Cloud Logging.""" - list_monitored_resource_descriptors_request = logging_pb2.ListMonitoredResourceDescriptorsRequest(**kwargs) - return self.list_monitored_resource_descriptors_callable()(list_monitored_resource_descriptors_request) - - def list_monitored_resource_descriptors_callable( - self, - is_retrying=None, - max_attempts=None, - page_streaming=_LIST_MONITORED_RESOURCE_DESCRIPTORS_DESCRIPTOR): - return api_callable.idempotent_callable( + req = logging_pb2.ListLogEntriesRequest(project_ids=project_ids, + filter=filter_, + order_by=order_by) + settings = self._defaults['list_log_entries'].merge(options) + api_call = api_callable.create_api_call(self.stub.ListLogEntries, + settings=settings) + return api_call(req, metadata=self._headers) + + def list_monitored_resource_descriptors(self, options=None): + """ + Lists monitored resource descriptors that are used by Cloud Logging. + + Args: + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Yields: + Instances of :class:`google.api.monitored_resource_pb2.MonitoredResourceDescriptor` + unless page streaming is disabled through the call options. If + page streaming is disabled, a single + :class:`google.logging.v2.logging_pb2.ListMonitoredResourceDescriptorsResponse` instance + is returned. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + """ + req = logging_pb2.ListMonitoredResourceDescriptorsRequest() + settings = self._defaults['list_monitored_resource_descriptors'].merge( + options) + api_call = api_callable.create_api_call( self.stub.ListMonitoredResourceDescriptors, - page_streaming=page_streaming, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - # ======== - # Manually-added methods: add custom (non-generated) methods after this point. - # ======== + settings=settings) + return api_call(req, metadata=self._headers) diff --git a/gcloud/logging/logging_service_v2_client_config.json b/gcloud/logging/logging_service_v2_client_config.json new file mode 100644 index 000000000000..5f0f3d072f2d --- /dev/null +++ b/gcloud/logging/logging_service_v2_client_config.json @@ -0,0 +1,39 @@ +{ + "interfaces": { + "google.logging.v2.LoggingServiceV2": { + "retry_codes": { + "idempotent": ["UNAVAILABLE", "DEADLINE_EXCEEDED"], + "non_idempotent": [] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.2, + "max_retry_delay_millis": 1000, + "initial_rpc_timeout_millis": 7000, + "rpc_timeout_multiplier": 1.5, + "max_rpc_timeout_millis": 30000, + "total_timeout_millis": 45000 + } + }, + "methods": { + "DeleteLog": { + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "WriteLogEntries": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "ListLogEntries": { + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "ListMonitoredResourceDescriptors": { + "retry_codes_name": "idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/gcloud/logging/metrics_service_v2_api.py b/gcloud/logging/metrics_service_v2_api.py index 52fa30b47828..167d8c7d3b92 100644 --- a/gcloud/logging/metrics_service_v2_api.py +++ b/gcloud/logging/metrics_service_v2_api.py @@ -14,64 +14,131 @@ # # EDITING INSTRUCTIONS # This file was generated from the file -# https://github.com/google/googleapis/blob/7710ead495227e80a0f06ceb66bdf3238d926f77/google/logging/v2/logging_metrics.proto, +# https://github.com/google/googleapis/blob/master/google/logging/v2/logging_metrics.proto, # and updates to that file get reflected here through a refresh process. # For the short term, the refresh process will only be runnable by Google engineers. -# Manual additions are allowed because the refresh process performs -# a 3-way merge in order to preserve those manual additions. In order to not -# break the refresh process, only certain types of modifications are -# allowed. # -# Allowed modifications: -# 1. New methods (these should be added to the end of the class) -# -# Happy editing! +# The only allowed edits are to method and file documentation. A 3-way +# merge preserves those additions if the generated source changes. +"""Accesses the google.logging.v2 MetricsServiceV2 API.""" + +import json +import os +import pkg_resources +import platform from google.gax import api_callable -from google.gax import api_utils -from google.gax import page_descriptor +from google.gax import config +from google.gax import path_template +import google.gax + from google.logging.v2 import logging_metrics_pb2 +_PageDesc = google.gax.PageDescriptor + class MetricsServiceV2Api(object): + SERVICE_ADDRESS = 'logging.googleapis.com' + """The default address of the service.""" + + DEFAULT_SERVICE_PORT = 443 + """The default port of the service.""" - # The default address of the logging service. - _SERVICE_ADDRESS = 'logging.googleapis.com' + _CODE_GEN_NAME_VERSION = 'gapic/0.1.0' - # The default port of the logging service. - _DEFAULT_SERVICE_PORT = 443 + _GAX_VERSION = pkg_resources.get_distribution('google-gax').version + + _DEFAULT_TIMEOUT = 30 + + _PAGE_DESCRIPTORS = { + 'list_log_metrics': _PageDesc('page_token', 'next_page_token', + 'metrics') + } # The scopes needed to make gRPC calls to all of the methods defined in # this service - _ALL_SCOPES = ( - 'https://www.googleapis.com/auth/logging.write', - 'https://www.googleapis.com/auth/logging.admin', - 'https://www.googleapis.com/auth/logging.read', - 'https://www.googleapis.com/auth/cloud-platform.read-only', - 'https://www.googleapis.com/auth/cloud-platform', - ) - - _LIST_LOG_METRICS_DESCRIPTOR = page_descriptor.PageDescriptor( - 'page_token', - 'next_page_token', - 'metrics', - ) - - def __init__( - self, - service_path=_SERVICE_ADDRESS, - port=_DEFAULT_SERVICE_PORT, - channel=None, - ssl_creds=None, - scopes=_ALL_SCOPES, - is_idempotent_retrying=True, - max_attempts=3, - timeout=30): - self.defaults = api_callable.ApiCallableDefaults( - timeout=timeout, - max_attempts=max_attempts, - is_idempotent_retrying=is_idempotent_retrying) - self.stub = api_utils.create_stub( + _ALL_SCOPES = ('https://www.googleapis.com/auth/logging.write', + 'https://www.googleapis.com/auth/logging.admin', + 'https://www.googleapis.com/auth/logging.read', + 'https://www.googleapis.com/auth/cloud-platform.read-only', + 'https://www.googleapis.com/auth/cloud-platform', ) + + _PROJECT_PATH_TEMPLATE = path_template.PathTemplate('projects/{project}') + _METRIC_PATH_TEMPLATE = path_template.PathTemplate( + 'projects/{project}/metrics/{metric}') + + @classmethod + def project_path(cls, project): + """Returns a fully-qualified project resource name string.""" + return cls._PROJECT_PATH_TEMPLATE.instantiate({'project': project, }) + + @classmethod + def metric_path(cls, project, metric): + """Returns a fully-qualified metric resource name string.""" + return cls._METRIC_PATH_TEMPLATE.instantiate({ + 'project': project, + 'metric': metric, + }) + + def __init__(self, + service_path=SERVICE_ADDRESS, + port=DEFAULT_SERVICE_PORT, + channel=None, + ssl_creds=None, + scopes=None, + retrying_override=None, + bundling_override=None, + timeout=_DEFAULT_TIMEOUT, + app_name='gax', + app_version=_GAX_VERSION): + """Constructor. + + Args: + service_path (string): The domain name of the API remote host. + port (int): The port on which to connect to the remote host. + channel (:class:`grpc.beta.implementations.Channel`): A ``Channel`` + object through which to make calls. + ssl_creds (:class:`grpc.beta.implementations.ClientCredentials`): + A `ClientCredentials` for use with an SSL-enabled channel. + retrying_override (dict[string, :class:`google.gax.RetryOptions`]): A + dictionary that overrides default retrying settings. + ``retrying_override`` maps method names (e.g., ``'list_foo'``) to + custom RetryOptions objects, or to None. A value of None indicates + that the method in question should not retry. + bundling_override (dict[string, :class:`google.gax.BundleOptions`]): A + dictionary that overrides default bundling settings. + ``bundling_override`` maps bundling method names (e.g., + 'publish_foo') to custom BundleOptions objects, or to None. It is + invalid to have a key for a method that is not bundling-enabled. A + value of None indicates that the method in question should not + bundle. + timeout (int): The default timeout, in seconds, for calls made + through this client + app_name (string): The codename of the calling service. + app_version (string): The version of the calling service. + + Returns: + A MetricsServiceV2Api object. + """ + if scopes is None: + scopes = self._ALL_SCOPES + bundling_override = bundling_override or {} + retrying_override = retrying_override or {} + client_config = pkg_resources.resource_string( + __name__, 'metrics_service_v2_client_config.json') + self._defaults = api_callable.construct_settings( + 'google.logging.v2.MetricsServiceV2', + json.loads(client_config), + bundling_override, + retrying_override, + config.STATUS_CODE_NAMES, + timeout, + page_descriptors=self._PAGE_DESCRIPTORS) + google_apis_agent = '{}/{};{};gax/{};python/{}'.format( + app_name, app_version, self._CODE_GEN_NAME_VERSION, + self._GAX_VERSION, platform.python_version()) + self._headers = [('x-google-apis-agent', google_apis_agent)] + self.stub = config.create_stub( logging_metrics_pb2.beta_create_MetricsServiceV2_stub, service_path, port, @@ -79,126 +146,135 @@ def __init__( channel=channel, scopes=scopes) - def __enter__(self): - return self + # Service calls + def list_log_metrics(self, project_name='', options=None): + """ + Lists logs-based metrics. - def __exit__(self, exc_type, exc_val, exc_tb): - self.close() + Args: + project_name (string): Required. The resource name of the project containing the metrics. + Example: `"projects/my-project-id"`. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. - def close(self): - del self.stub + Yields: + Instances of :class:`google.logging.v2.logging_metrics_pb2.LogMetric` + unless page streaming is disabled through the call options. If + page streaming is disabled, a single + :class:`google.logging.v2.logging_metrics_pb2.ListLogMetricsResponse` instance + is returned. - # Service calls - def list_log_metrics( - self, - project_name='', - **kwargs): - """Lists logs-based metrics.""" - list_log_metrics_request = logging_metrics_pb2.ListLogMetricsRequest( - project_name=project_name, - **kwargs) - return self.list_log_metrics_callable()(list_log_metrics_request) - - def list_log_metrics_callable( - self, - is_retrying=None, - max_attempts=None, - page_streaming=_LIST_LOG_METRICS_DESCRIPTOR): - return api_callable.idempotent_callable( - self.stub.ListLogMetrics, - page_streaming=page_streaming, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - def get_log_metric( - self, - metric_name='', - **kwargs): - """Gets a logs-based metric.""" - get_log_metric_request = logging_metrics_pb2.GetLogMetricRequest( - metric_name=metric_name, - **kwargs) - return self.get_log_metric_callable()(get_log_metric_request) - - def get_log_metric_callable( - self, - is_retrying=None, - max_attempts=None): - return api_callable.idempotent_callable( - self.stub.GetLogMetric, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - def create_log_metric( - self, - project_name='', - metric=None, - **kwargs): - """Creates a logs-based metric.""" + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + """ + req = logging_metrics_pb2.ListLogMetricsRequest( + project_name=project_name) + settings = self._defaults['list_log_metrics'].merge(options) + api_call = api_callable.create_api_call(self.stub.ListLogMetrics, + settings=settings) + return api_call(req, metadata=self._headers) + + def get_log_metric(self, metric_name='', options=None): + """ + Gets a logs-based metric. + + Args: + metric_name (string): The resource name of the desired metric. + Example: `"projects/my-project-id/metrics/my-metric-id"`. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`google.logging.v2.logging_metrics_pb2.LogMetric` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + """ + req = logging_metrics_pb2.GetLogMetricRequest(metric_name=metric_name) + settings = self._defaults['get_log_metric'].merge(options) + api_call = api_callable.create_api_call(self.stub.GetLogMetric, + settings=settings) + return api_call(req, metadata=self._headers) + + def create_log_metric(self, project_name='', metric=None, options=None): + """ + Creates a logs-based metric. + + Args: + project_name (string): The resource name of the project in which to create the metric. + Example: `"projects/my-project-id"`. + + The new metric must be provided in the request. + metric (:class:`google.logging.v2.logging_metrics_pb2.LogMetric`): The new logs-based metric, which must not have an identifier that + already exists. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`google.logging.v2.logging_metrics_pb2.LogMetric` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + """ if metric is None: metric = logging_metrics_pb2.LogMetric() - create_log_metric_request = logging_metrics_pb2.CreateLogMetricRequest( + req = logging_metrics_pb2.CreateLogMetricRequest( project_name=project_name, - metric=metric, - **kwargs) - return self.create_log_metric_callable()(create_log_metric_request) - - def create_log_metric_callable( - self, - is_retrying=None, - max_attempts=None): - return api_callable.idempotent_callable( - self.stub.CreateLogMetric, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - def update_log_metric( - self, - metric_name='', - metric=None, - **kwargs): - """Creates or updates a logs-based metric.""" + metric=metric) + settings = self._defaults['create_log_metric'].merge(options) + api_call = api_callable.create_api_call(self.stub.CreateLogMetric, + settings=settings) + return api_call(req, metadata=self._headers) + + def update_log_metric(self, metric_name='', metric=None, options=None): + """ + Creates or updates a logs-based metric. + + Args: + metric_name (string): The resource name of the metric to update. + Example: `"projects/my-project-id/metrics/my-metric-id"`. + + The updated metric must be provided in the request and have the + same identifier that is specified in `metricName`. + If the metric does not exist, it is created. + metric (:class:`google.logging.v2.logging_metrics_pb2.LogMetric`): The updated metric, whose name must be the same as the + metric identifier in `metricName`. If `metricName` does not + exist, then a new metric is created. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`google.logging.v2.logging_metrics_pb2.LogMetric` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + """ if metric is None: metric = logging_metrics_pb2.LogMetric() - update_log_metric_request = logging_metrics_pb2.UpdateLogMetricRequest( + req = logging_metrics_pb2.UpdateLogMetricRequest( metric_name=metric_name, - metric=metric, - **kwargs) - return self.update_log_metric_callable()(update_log_metric_request) - - def update_log_metric_callable( - self, - is_retrying=None, - max_attempts=None): - return api_callable.idempotent_callable( - self.stub.UpdateLogMetric, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - def delete_log_metric( - self, - metric_name='', - **kwargs): - """Deletes a logs-based metric.""" - delete_log_metric_request = logging_metrics_pb2.DeleteLogMetricRequest( - metric_name=metric_name, - **kwargs) - return self.delete_log_metric_callable()(delete_log_metric_request) - - def delete_log_metric_callable( - self, - is_retrying=None, - max_attempts=None): - return api_callable.idempotent_callable( - self.stub.DeleteLogMetric, - is_retrying=is_retrying, - max_attempts=max_attempts, - defaults=self.defaults) - - # ======== - # Manually-added methods: add custom (non-generated) methods after this point. - # ======== + metric=metric) + settings = self._defaults['update_log_metric'].merge(options) + api_call = api_callable.create_api_call(self.stub.UpdateLogMetric, + settings=settings) + return api_call(req, metadata=self._headers) + + def delete_log_metric(self, metric_name='', options=None): + """ + Deletes a logs-based metric. + + Args: + metric_name (string): The resource name of the metric to delete. + Example: `"projects/my-project-id/metrics/my-metric-id"`. + options (:class:`google.gax.CallOptions`): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + """ + req = logging_metrics_pb2.DeleteLogMetricRequest( + metric_name=metric_name) + settings = self._defaults['delete_log_metric'].merge(options) + api_call = api_callable.create_api_call(self.stub.DeleteLogMetric, + settings=settings) + api_call(req, metadata=self._headers) diff --git a/gcloud/logging/metrics_service_v2_client_config.json b/gcloud/logging/metrics_service_v2_client_config.json new file mode 100644 index 000000000000..b3f3402f9628 --- /dev/null +++ b/gcloud/logging/metrics_service_v2_client_config.json @@ -0,0 +1,43 @@ +{ + "interfaces": { + "google.logging.v2.MetricsServiceV2": { + "retry_codes": { + "idempotent": ["UNAVAILABLE", "DEADLINE_EXCEEDED"], + "non_idempotent": [] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.2, + "max_retry_delay_millis": 1000, + "initial_rpc_timeout_millis": 7000, + "rpc_timeout_multiplier": 1.5, + "max_rpc_timeout_millis": 30000, + "total_timeout_millis": 45000 + } + }, + "methods": { + "ListLogMetrics": { + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "GetLogMetric": { + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "CreateLogMetric": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "UpdateLogMetric": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "DeleteLogMetric": { + "retry_codes_name": "idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/setup.py b/setup.py index bb620df8c515..2777406744f0 100644 --- a/setup.py +++ b/setup.py @@ -12,13 +12,14 @@ REQUIREMENTS = [ - 'google-gax', - 'googleapis-common-protos', - 'grpc-google-logging-v2', + 'google-gax >= 0.9.2', + 'googleapis-common-protos >= 1.1.0', + 'grpc-google-logging-v2 >= 1.0.3', 'httplib2 >= 0.9.1', 'oauth2client >= 1.4.6', 'protobuf >= 3.0.0b2', 'pyOpenSSL', + 'pyyaml >= 3.11', 'six', ] diff --git a/tox.ini b/tox.ini index 1955313fa1d8..fb5492590273 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,6 @@ deps = unittest2 setenv = PYTHONPATH = {toxinidir}/_testing - PIP_FIND_LINKS = https://gapi-pypi.appspot.com/admin/nurpc-dev covercmd = nosetests \ --ignore-files=run_system_test\.py \