Skip to content

Commit

Permalink
GAPIC Header Consistency: Logging (#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesneeringer authored Feb 23, 2017
1 parent c525b44 commit ab1ce15
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
10 changes: 7 additions & 3 deletions logging/google/cloud/logging/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from google.cloud.exceptions import Conflict
from google.cloud.exceptions import NotFound
from google.cloud.iterator import GAXIterator
from google.cloud.logging import __version__
from google.cloud.logging._helpers import entry_from_resource
from google.cloud.logging.sink import Sink
from google.cloud.logging.metric import Metric
Expand Down Expand Up @@ -534,7 +535,8 @@ def make_gax_logging_api(client):
channel = make_secure_channel(
client._connection.credentials, DEFAULT_USER_AGENT,
LoggingServiceV2Client.SERVICE_ADDRESS)
generated = LoggingServiceV2Client(channel=channel)
generated = LoggingServiceV2Client(
channel=channel, lib_name='gccl', lib_version=__version__)
return _LoggingAPI(generated, client)


Expand All @@ -550,7 +552,8 @@ def make_gax_metrics_api(client):
channel = make_secure_channel(
client._connection.credentials, DEFAULT_USER_AGENT,
MetricsServiceV2Client.SERVICE_ADDRESS)
generated = MetricsServiceV2Client(channel=channel)
generated = MetricsServiceV2Client(
channel=channel, lib_name='gccl', lib_version=__version__)
return _MetricsAPI(generated, client)


Expand All @@ -566,5 +569,6 @@ def make_gax_sinks_api(client):
channel = make_secure_channel(
client._connection.credentials, DEFAULT_USER_AGENT,
ConfigServiceV2Client.SERVICE_ADDRESS)
generated = ConfigServiceV2Client(channel=channel)
generated = ConfigServiceV2Client(
channel=channel, lib_name='gccl', lib_version=__version__)
return _SinksAPI(generated, client)
4 changes: 2 additions & 2 deletions logging/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
REQUIREMENTS = [
'google-cloud-core >= 0.23.0, < 0.24dev',
'grpcio >= 1.0.2, < 2.0dev',
'gapic-google-cloud-logging-v2 >= 0.90.0, < 0.91dev',
'gapic-google-cloud-logging-v2 >= 0.90.1, < 0.91dev',
]

setup(
name='google-cloud-logging',
version='0.22.0',
version='0.23.0',
description='Python Client for Stackdriver Logging',
long_description=README,
namespace_packages=[
Expand Down
27 changes: 24 additions & 3 deletions logging/unit_tests/test__gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ def _call_fut(self, client):
return make_gax_logging_api(client)

def test_it(self):
from google.cloud.logging import __version__
from google.cloud.logging._gax import _LoggingAPI
from google.cloud.logging._gax import DEFAULT_USER_AGENT

Expand All @@ -1116,15 +1117,17 @@ def test_it(self):
client = mock.Mock(_connection=conn, spec=['_connection'])
channels = []
channel_args = []
generated_api_kwargs = []
channel_obj = object()
generated = object()

def make_channel(*args):
channel_args.append(args)
return channel_obj

def generated_api(channel=None):
def generated_api(channel=None, **kwargs):
channels.append(channel)
generated_api_kwargs.append(kwargs)
return generated

host = 'foo.apis.invalid'
Expand All @@ -1141,6 +1144,10 @@ def generated_api(channel=None):
self.assertEqual(channel_args,
[(creds, DEFAULT_USER_AGENT, host)])

self.assertEqual(len(generated_api_kwargs), 1)
self.assertEqual(generated_api_kwargs[0]['lib_name'], 'gccl')
self.assertEqual(generated_api_kwargs[0]['lib_version'], __version__)

self.assertIsInstance(logging_api, _LoggingAPI)
self.assertIs(logging_api._gax_api, generated)
self.assertIs(logging_api._client, client)
Expand All @@ -1155,6 +1162,7 @@ def _call_fut(self, client):
return make_gax_metrics_api(client)

def test_it(self):
from google.cloud.logging import __version__
from google.cloud.logging._gax import _MetricsAPI
from google.cloud.logging._gax import DEFAULT_USER_AGENT

Expand All @@ -1163,15 +1171,17 @@ def test_it(self):
client = mock.Mock(_connection=conn, spec=['_connection'])
channels = []
channel_args = []
generated_api_kwargs = []
channel_obj = object()
generated = object()

def make_channel(*args):
channel_args.append(args)
return channel_obj

def generated_api(channel=None):
def generated_api(channel=None, **kwargs):
channels.append(channel)
generated_api_kwargs.append(kwargs)
return generated

host = 'foo.apis.invalid'
Expand All @@ -1188,6 +1198,10 @@ def generated_api(channel=None):
self.assertEqual(channel_args,
[(creds, DEFAULT_USER_AGENT, host)])

self.assertEqual(len(generated_api_kwargs), 1)
self.assertEqual(generated_api_kwargs[0]['lib_name'], 'gccl')
self.assertEqual(generated_api_kwargs[0]['lib_version'], __version__)

self.assertIsInstance(metrics_api, _MetricsAPI)
self.assertIs(metrics_api._gax_api, generated)
self.assertIs(metrics_api._client, client)
Expand All @@ -1202,6 +1216,7 @@ def _call_fut(self, client):
return make_gax_sinks_api(client)

def test_it(self):
from google.cloud.logging import __version__
from google.cloud.logging._gax import _SinksAPI
from google.cloud.logging._gax import DEFAULT_USER_AGENT

Expand All @@ -1210,15 +1225,17 @@ def test_it(self):
client = mock.Mock(_connection=conn, spec=['_connection'])
channels = []
channel_args = []
generated_api_kwargs = []
channel_obj = object()
generated = object()

def make_channel(*args):
channel_args.append(args)
return channel_obj

def generated_api(channel=None):
def generated_api(channel=None, **kwargs):
channels.append(channel)
generated_api_kwargs.append(kwargs)
return generated

host = 'foo.apis.invalid'
Expand All @@ -1235,6 +1252,10 @@ def generated_api(channel=None):
self.assertEqual(channel_args,
[(creds, DEFAULT_USER_AGENT, host)])

self.assertEqual(len(generated_api_kwargs), 1)
self.assertEqual(generated_api_kwargs[0]['lib_name'], 'gccl')
self.assertEqual(generated_api_kwargs[0]['lib_version'], __version__)

self.assertIsInstance(sinks_api, _SinksAPI)
self.assertIs(sinks_api._gax_api, generated)
self.assertIs(sinks_api._client, client)
Expand Down

0 comments on commit ab1ce15

Please sign in to comment.