Skip to content

Commit

Permalink
Merge pull request #2795 from dhermes/update-gapic-0.14
Browse files Browse the repository at this point in the history
Upgrading GAPIC deps to 0.14 series.
  • Loading branch information
dhermes authored Dec 3, 2016
2 parents 40d77e3 + dc10367 commit 7c73b58
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 94 deletions.
45 changes: 23 additions & 22 deletions logging/google/cloud/logging/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

import functools

from google.cloud.gapic.logging.v2.config_service_v2_api import (
ConfigServiceV2Api)
from google.cloud.gapic.logging.v2.logging_service_v2_api import (
LoggingServiceV2Api)
from google.cloud.gapic.logging.v2.metrics_service_v2_api import (
MetricsServiceV2Api)
from google.cloud.gapic.logging.v2.config_service_v2_client import (
ConfigServiceV2Client)
from google.cloud.gapic.logging.v2.logging_service_v2_client import (
LoggingServiceV2Client)
from google.cloud.gapic.logging.v2.metrics_service_v2_client import (
MetricsServiceV2Client)
from google.gax import CallOptions
from google.gax import INITIAL_PAGE
from google.gax.errors import GaxError
from google.gax.grpc import exc_to_code
from google.logging.v2.logging_config_pb2 import LogSink
from google.logging.v2.logging_metrics_pb2 import LogMetric
from google.logging.v2.log_entry_pb2 import LogEntry
from google.cloud.grpc.logging.v2.logging_config_pb2 import LogSink
from google.cloud.grpc.logging.v2.logging_metrics_pb2 import LogMetric
from google.cloud.grpc.logging.v2.log_entry_pb2 import LogEntry
from google.protobuf.json_format import MessageToDict
from google.protobuf.json_format import ParseDict
from grpc import StatusCode
Expand All @@ -48,7 +48,7 @@ class _LoggingAPI(object):
"""Helper mapping logging-related APIs.
:type gax_api:
:class:`google.logging.v2.logging_service_v2_api.LoggingServiceV2Api`
:class:`.logging_service_v2_client.LoggingServiceV2Client`
:param gax_api: API object used to make GAX requests.
:type client: :class:`~google.cloud.logging.client.Client`
Expand Down Expand Up @@ -92,7 +92,7 @@ def list_entries(self, projects, filter_='', order_by='',
page_token = INITIAL_PAGE
options = CallOptions(page_token=page_token)
page_iter = self._gax_api.list_log_entries(
projects, filter_=filter_, order_by=order_by,
[], project_ids=projects, filter_=filter_, order_by=order_by,
page_size=page_size, options=options)

# We attach a mutable loggers dictionary so that as Logger
Expand Down Expand Up @@ -152,7 +152,7 @@ class _SinksAPI(object):
"""Helper mapping sink-related APIs.
:type gax_api:
:class:`google.logging.v2.config_service_v2_api.ConfigServiceV2Api`
:class:`.config_service_v2_client.ConfigServiceV2Client`
:param gax_api: API object used to make GAX requests.
:type client: :class:`~google.cloud.logging.client.Client`
Expand Down Expand Up @@ -300,7 +300,8 @@ class _MetricsAPI(object):
"""Helper mapping sink-related APIs.
:type gax_api:
:class:`google.logging.v2.metrics_service_v2_api.MetricsServiceV2Api`
:class:`.metrics_service_v2_client.MetricsServiceV2Client`
:param gax_api: API object used to make GAX requests.
:type client: :class:`~google.cloud.logging.client.Client`
Expand Down Expand Up @@ -471,7 +472,7 @@ def _item_to_entry(iterator, entry_pb, loggers):
:type iterator: :class:`~google.cloud.iterator.Iterator`
:param iterator: The iterator that is currently in use.
:type entry_pb: :class:`~google.logging.v2.log_entry_pb2.LogEntry`
:type entry_pb: :class:`.log_entry_pb2.LogEntry`
:param entry_pb: Log entry protobuf returned from the API.
:type loggers: dict
Expand All @@ -494,7 +495,7 @@ def _item_to_sink(iterator, log_sink_pb):
:param iterator: The iterator that is currently in use.
:type log_sink_pb:
:class:`~google.logging.v2.logging_config_pb2.LogSink`
:class:`.logging_config_pb2.LogSink`
:param log_sink_pb: Sink protobuf returned from the API.
:rtype: :class:`~google.cloud.logging.sink.Sink`
Expand All @@ -511,7 +512,7 @@ def _item_to_metric(iterator, log_metric_pb):
:param iterator: The iterator that is currently in use.
:type log_metric_pb:
:class:`~google.logging.v2.logging_metrics_pb2.LogMetric`
:class:`.logging_metrics_pb2.LogMetric`
:param log_metric_pb: Metric protobuf returned from the API.
:rtype: :class:`~google.cloud.logging.metric.Metric`
Expand All @@ -532,8 +533,8 @@ def make_gax_logging_api(client):
"""
channel = make_secure_channel(
client._connection.credentials, DEFAULT_USER_AGENT,
LoggingServiceV2Api.SERVICE_ADDRESS)
generated = LoggingServiceV2Api(channel=channel)
LoggingServiceV2Client.SERVICE_ADDRESS)
generated = LoggingServiceV2Client(channel=channel)
return _LoggingAPI(generated, client)


Expand All @@ -548,8 +549,8 @@ def make_gax_metrics_api(client):
"""
channel = make_secure_channel(
client._connection.credentials, DEFAULT_USER_AGENT,
MetricsServiceV2Api.SERVICE_ADDRESS)
generated = MetricsServiceV2Api(channel=channel)
MetricsServiceV2Client.SERVICE_ADDRESS)
generated = MetricsServiceV2Client(channel=channel)
return _MetricsAPI(generated, client)


Expand All @@ -564,6 +565,6 @@ def make_gax_sinks_api(client):
"""
channel = make_secure_channel(
client._connection.credentials, DEFAULT_USER_AGENT,
ConfigServiceV2Api.SERVICE_ADDRESS)
generated = ConfigServiceV2Api(channel=channel)
ConfigServiceV2Client.SERVICE_ADDRESS)
generated = ConfigServiceV2Client(channel=channel)
return _SinksAPI(generated, client)
5 changes: 1 addition & 4 deletions logging/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@

REQUIREMENTS = [
'google-cloud-core >= 0.21.0, < 0.22dev',
'grpcio >= 1.0.0, < 2.0dev',
'google-gax >= 0.14.1, < 0.15dev',
'gapic-google-logging-v2 >= 0.10.1, < 0.11dev',
'grpc-google-logging-v2 >= 0.10.1, < 0.11dev',
'gapic-google-cloud-logging-v2 >= 0.14.0, < 0.15dev',
]

setup(
Expand Down
56 changes: 31 additions & 25 deletions logging/unit_tests/test__gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_list_entries_no_paging(self):

from google.api.monitored_resource_pb2 import MonitoredResource
from google.gax import INITIAL_PAGE
from google.logging.v2.log_entry_pb2 import LogEntry
from google.cloud.grpc.logging.v2.log_entry_pb2 import LogEntry

from google.cloud._helpers import _datetime_to_pb_timestamp
from google.cloud._helpers import UTC
Expand Down Expand Up @@ -103,8 +103,9 @@ def test_list_entries_no_paging(self):
self.assertIsNone(entry.severity)
self.assertIsNone(entry.http_request)

projects, filter_, order_by, page_size, options = (
resource_names, projects, filter_, order_by, page_size, options = (
gax_api._list_log_entries_called_with)
self.assertEqual(resource_names, [])
self.assertEqual(projects, [self.PROJECT])
self.assertEqual(filter_, self.FILTER)
self.assertEqual(order_by, DESCENDING)
Expand All @@ -115,7 +116,7 @@ def _list_entries_with_paging_helper(self, payload, struct_pb):
import datetime

from google.api.monitored_resource_pb2 import MonitoredResource
from google.logging.v2.log_entry_pb2 import LogEntry
from google.cloud.grpc.logging.v2.log_entry_pb2 import LogEntry
from google.cloud._helpers import _datetime_to_pb_timestamp
from google.cloud._helpers import UTC
from google.cloud._testing import _GAXPageIterator
Expand Down Expand Up @@ -158,8 +159,9 @@ def _list_entries_with_paging_helper(self, payload, struct_pb):
self.assertIsNone(entry.severity)
self.assertIsNone(entry.http_request)

projects, filter_, order_by, page_size, options = (
resource_names, projects, filter_, order_by, page_size, options = (
gax_api._list_log_entries_called_with)
self.assertEqual(resource_names, [])
self.assertEqual(projects, [self.PROJECT])
self.assertEqual(filter_, '')
self.assertEqual(order_by, '')
Expand Down Expand Up @@ -205,8 +207,9 @@ def test_list_entries_with_paging_nested_payload(self):

def _make_log_entry_with_extras(self, labels, iid, type_url, now):
from google.api.monitored_resource_pb2 import MonitoredResource
from google.logging.v2.log_entry_pb2 import LogEntry
from google.logging.v2.log_entry_pb2 import LogEntryOperation
from google.cloud.grpc.logging.v2.log_entry_pb2 import LogEntry
from google.cloud.grpc.logging.v2.log_entry_pb2 import (
LogEntryOperation)
from google.logging.type.http_request_pb2 import HttpRequest
from google.logging.type.log_severity_pb2 import WARNING
from google.protobuf.any_pb2 import Any
Expand Down Expand Up @@ -311,16 +314,17 @@ def test_list_entries_with_extra_properties(self):
'cacheHit': entry_pb.http_request.cache_hit,
})

projects, filter_, order_by, page_size, options = (
resource_names, projects, filter_, order_by, page_size, options = (
gax_api._list_log_entries_called_with)
self.assertEqual(resource_names, [])
self.assertEqual(projects, [self.PROJECT])
self.assertEqual(filter_, '')
self.assertEqual(order_by, '')
self.assertEqual(page_size, SIZE)
self.assertEqual(options.page_token, TOKEN)

def test_write_entries_single(self):
from google.logging.v2.log_entry_pb2 import LogEntry
from google.cloud.grpc.logging.v2.log_entry_pb2 import LogEntry
TEXT = 'TEXT'
ENTRY = {
'logName': self.LOG_PATH,
Expand Down Expand Up @@ -353,7 +357,7 @@ def test_write_entries_w_extra_properties(self):
# pylint: disable=too-many-statements
from datetime import datetime
from google.logging.type.log_severity_pb2 import WARNING
from google.logging.v2.log_entry_pb2 import LogEntry
from google.cloud.grpc.logging.v2.log_entry_pb2 import LogEntry
from google.cloud._helpers import UTC, _pb_timestamp_to_datetime
NOW = datetime.utcnow().replace(tzinfo=UTC)
TEXT = 'TEXT'
Expand Down Expand Up @@ -448,7 +452,7 @@ def _write_entries_multiple_helper(self, json_payload, json_struct_pb):
# pylint: disable=too-many-statements
import datetime
from google.logging.type.log_severity_pb2 import WARNING
from google.logging.v2.log_entry_pb2 import LogEntry
from google.cloud.grpc.logging.v2.log_entry_pb2 import LogEntry
from google.protobuf.any_pb2 import Any
from google.cloud._helpers import _datetime_to_rfc3339, UTC
TEXT = 'TEXT'
Expand Down Expand Up @@ -616,7 +620,7 @@ def test_ctor(self):
def test_list_sinks_no_paging(self):
import six
from google.gax import INITIAL_PAGE
from google.logging.v2.logging_config_pb2 import LogSink
from google.cloud.grpc.logging.v2.logging_config_pb2 import LogSink
from google.cloud._testing import _GAXPageIterator
from google.cloud.logging.sink import Sink

Expand Down Expand Up @@ -651,7 +655,7 @@ def test_list_sinks_no_paging(self):
self.assertEqual(options.page_token, INITIAL_PAGE)

def test_list_sinks_w_paging(self):
from google.logging.v2.logging_config_pb2 import LogSink
from google.cloud.grpc.logging.v2.logging_config_pb2 import LogSink
from google.cloud._testing import _GAXPageIterator
from google.cloud.logging.sink import Sink

Expand Down Expand Up @@ -707,7 +711,7 @@ def test_sink_create_conflict(self):
self.DESTINATION_URI)

def test_sink_create_ok(self):
from google.logging.v2.logging_config_pb2 import LogSink
from google.cloud.grpc.logging.v2.logging_config_pb2 import LogSink
gax_api = _GAXSinksAPI()
api = self._make_one(gax_api, None)

Expand Down Expand Up @@ -740,7 +744,7 @@ def test_sink_get_miss(self):
api.sink_get(self.PROJECT, self.SINK_NAME)

def test_sink_get_hit(self):
from google.logging.v2.logging_config_pb2 import LogSink
from google.cloud.grpc.logging.v2.logging_config_pb2 import LogSink

RESPONSE = {
'name': self.SINK_PATH,
Expand Down Expand Up @@ -782,7 +786,7 @@ def test_sink_update_miss(self):
self.DESTINATION_URI)

def test_sink_update_hit(self):
from google.logging.v2.logging_config_pb2 import LogSink
from google.cloud.grpc.logging.v2.logging_config_pb2 import LogSink

response = LogSink(name=self.SINK_NAME,
destination=self.DESTINATION_URI,
Expand Down Expand Up @@ -848,7 +852,7 @@ def test_ctor(self):
def test_list_metrics_no_paging(self):
import six
from google.gax import INITIAL_PAGE
from google.logging.v2.logging_metrics_pb2 import LogMetric
from google.cloud.grpc.logging.v2.logging_metrics_pb2 import LogMetric
from google.cloud._testing import _GAXPageIterator
from google.cloud.logging.metric import Metric

Expand Down Expand Up @@ -883,7 +887,7 @@ def test_list_metrics_no_paging(self):
self.assertEqual(options.page_token, INITIAL_PAGE)

def test_list_metrics_w_paging(self):
from google.logging.v2.logging_metrics_pb2 import LogMetric
from google.cloud.grpc.logging.v2.logging_metrics_pb2 import LogMetric
from google.cloud._testing import _GAXPageIterator
from google.cloud.logging.metric import Metric

Expand Down Expand Up @@ -939,7 +943,7 @@ def test_metric_create_conflict(self):
self.DESCRIPTION)

def test_metric_create_ok(self):
from google.logging.v2.logging_metrics_pb2 import LogMetric
from google.cloud.grpc.logging.v2.logging_metrics_pb2 import LogMetric
gax_api = _GAXMetricsAPI()
api = self._make_one(gax_api, None)

Expand Down Expand Up @@ -972,7 +976,7 @@ def test_metric_get_miss(self):
api.metric_get(self.PROJECT, self.METRIC_NAME)

def test_metric_get_hit(self):
from google.logging.v2.logging_metrics_pb2 import LogMetric
from google.cloud.grpc.logging.v2.logging_metrics_pb2 import LogMetric

RESPONSE = {
'name': self.METRIC_PATH,
Expand Down Expand Up @@ -1014,7 +1018,7 @@ def test_metric_update_miss(self):
self.DESCRIPTION)

def test_metric_update_hit(self):
from google.logging.v2.logging_metrics_pb2 import LogMetric
from google.cloud.grpc.logging.v2.logging_metrics_pb2 import LogMetric

response = LogMetric(name=self.METRIC_NAME,
description=self.DESCRIPTION,
Expand Down Expand Up @@ -1093,7 +1097,7 @@ def generated_api(channel=None):

patch = mock.patch.multiple(
'google.cloud.logging._gax',
LoggingServiceV2Api=generated_api,
LoggingServiceV2Client=generated_api,
make_secure_channel=make_channel)
with patch:
logging_api = self._call_fut(client)
Expand Down Expand Up @@ -1139,7 +1143,7 @@ def generated_api(channel=None):

patch = mock.patch.multiple(
'google.cloud.logging._gax',
MetricsServiceV2Api=generated_api,
MetricsServiceV2Client=generated_api,
make_secure_channel=make_channel)
with patch:
metrics_api = self._call_fut(client)
Expand Down Expand Up @@ -1185,7 +1189,7 @@ def generated_api(channel=None):

patch = mock.patch.multiple(
'google.cloud.logging._gax',
ConfigServiceV2Api=generated_api,
ConfigServiceV2Client=generated_api,
make_secure_channel=make_channel)
with patch:
sinks_api = self._call_fut(client)
Expand All @@ -1204,9 +1208,11 @@ class _GAXLoggingAPI(_GAXBaseAPI):
_delete_not_found = False

def list_log_entries(
self, projects, filter_, order_by, page_size, options):
self, resource_names, project_ids, filter_,
order_by, page_size, options):
self._list_log_entries_called_with = (
projects, filter_, order_by, page_size, options)
resource_names, project_ids, filter_,
order_by, page_size, options)
return self._list_log_entries_response

def write_log_entries(self, entries, log_name, resource, labels,
Expand Down
Loading

0 comments on commit 7c73b58

Please sign in to comment.