From ca0ed912793009faa5268a66cee00846cee9f6b3 Mon Sep 17 00:00:00 2001 From: Sai Cheemalapati Date: Tue, 26 Jan 2016 16:11:28 -0800 Subject: [PATCH] Add logging client --- gcloud/logging/__init__.py | 15 ++ gcloud/logging/config_service_v2_api.py | 204 ++++++++++++++++++++++ gcloud/logging/logging_service_v2_api.py | 208 +++++++++++++++++++++++ gcloud/logging/metrics_service_v2_api.py | 204 ++++++++++++++++++++++ setup.py | 4 +- tox.ini | 1 + 6 files changed, 635 insertions(+), 1 deletion(-) create mode 100644 gcloud/logging/__init__.py create mode 100644 gcloud/logging/config_service_v2_api.py create mode 100644 gcloud/logging/logging_service_v2_api.py create mode 100644 gcloud/logging/metrics_service_v2_api.py diff --git a/gcloud/logging/__init__.py b/gcloud/logging/__init__.py new file mode 100644 index 000000000000..b3bc8b72e91e --- /dev/null +++ b/gcloud/logging/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Cloud Logging API wrapper.""" diff --git a/gcloud/logging/config_service_v2_api.py b/gcloud/logging/config_service_v2_api.py new file mode 100644 index 000000000000..37fc918cec90 --- /dev/null +++ b/gcloud/logging/config_service_v2_api.py @@ -0,0 +1,204 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# EDITING INSTRUCTIONS +# This file was generated from the file +# https://github.com/google/googleapis/blob/7710ead495227e80a0f06ceb66bdf3238d926f77/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! + +from google.gax import api_callable +from google.gax import api_utils +from google.gax import page_descriptor +from google.logging.v2 import logging_config_pb2 + + +class ConfigServiceV2Api(object): + + # The default address of the logging service. + _SERVICE_ADDRESS = 'logging.googleapis.com' + + # The default port of the logging service. + _DEFAULT_SERVICE_PORT = 443 + + # 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( + logging_config_pb2.beta_create_ConfigServiceV2_stub, + service_path, + port, + ssl_creds=ssl_creds, + 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 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.""" + 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.""" + 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. + # ======== diff --git a/gcloud/logging/logging_service_v2_api.py b/gcloud/logging/logging_service_v2_api.py new file mode 100644 index 000000000000..1afbeb1bf043 --- /dev/null +++ b/gcloud/logging/logging_service_v2_api.py @@ -0,0 +1,208 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# EDITING INSTRUCTIONS +# This file was generated from the file +# https://github.com/google/googleapis/blob/7710ead495227e80a0f06ceb66bdf3238d926f77/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! + +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.logging.v2 import log_entry_pb2 +from google.logging.v2 import logging_pb2 + + +class LoggingServiceV2Api(object): + """Service for ingesting and querying logs.""" + + # The default address of the logging service. + _SERVICE_ADDRESS = 'logging.googleapis.com' + + # The default port of the logging service. + _DEFAULT_SERVICE_PORT = 443 + + # 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( + logging_pb2.beta_create_LoggingServiceV2_stub, + service_path, + port, + ssl_creds=ssl_creds, + 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): + """ + Deletes a log and all its log entries. + The log will reappear if it receives new entries. + """ + 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): + """ + Writes log entries to Cloud Logging. + All log entries in Cloud Logging are written by this method. + """ + if resource is None: + resource = monitored_resource_pb2.MonitoredResource() + if labels is None: + 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): + """ + 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). + """ + 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( + 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. + # ======== diff --git a/gcloud/logging/metrics_service_v2_api.py b/gcloud/logging/metrics_service_v2_api.py new file mode 100644 index 000000000000..52fa30b47828 --- /dev/null +++ b/gcloud/logging/metrics_service_v2_api.py @@ -0,0 +1,204 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# EDITING INSTRUCTIONS +# This file was generated from the file +# https://github.com/google/googleapis/blob/7710ead495227e80a0f06ceb66bdf3238d926f77/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! + +from google.gax import api_callable +from google.gax import api_utils +from google.gax import page_descriptor +from google.logging.v2 import logging_metrics_pb2 + + +class MetricsServiceV2Api(object): + + # The default address of the logging service. + _SERVICE_ADDRESS = 'logging.googleapis.com' + + # The default port of the logging service. + _DEFAULT_SERVICE_PORT = 443 + + # 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( + logging_metrics_pb2.beta_create_MetricsServiceV2_stub, + service_path, + port, + ssl_creds=ssl_creds, + 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 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.""" + if metric is None: + metric = logging_metrics_pb2.LogMetric() + create_log_metric_request = 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.""" + if metric is None: + metric = logging_metrics_pb2.LogMetric() + update_log_metric_request = 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. + # ======== diff --git a/setup.py b/setup.py index 0cd32748c562..bb620df8c515 100644 --- a/setup.py +++ b/setup.py @@ -12,8 +12,10 @@ REQUIREMENTS = [ - 'httplib2 >= 0.9.1', + 'google-gax', 'googleapis-common-protos', + 'grpc-google-logging-v2', + 'httplib2 >= 0.9.1', 'oauth2client >= 1.4.6', 'protobuf >= 3.0.0b2', 'pyOpenSSL', diff --git a/tox.ini b/tox.ini index fb5492590273..1955313fa1d8 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,7 @@ 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 \