GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allows Explicitly Enabling/Disabling GAX for Logging/Pubsub by waprin · Pull Request #2553 · googleapis/google-cloud-python

Allows Explicitly Enabling/Disabling GAX for Logging/Pubsub #2553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
dhermes merged 6 commits into googleapis:master from waprin:logging_gax_optional
Oct 21, 2016

Uh oh!

There was an error while loading. Please reload this page.

Merged

Allows Explicitly Enabling/Disabling GAX for Logging/Pubsub #2553

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
bda9705
Enable forced HTTP for Error Reporting
Oct 17, 2016
fceaacf
dhermes review
Oct 17, 2016
088e8b4
Add pubs
Oct 20, 2016
cbd8155
dhermes review
Oct 21, 2016
8bfa396
more dhermes
Oct 21, 2016
20e3f47
fix docstrings
Oct 21, 2016
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

16 changes: 15 additions & 1 deletion 16 logging/google/cloud/logging/client.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,25 @@ class Client(JSONClient):
:param http: An optional HTTP object to make requests. If not passed, an
``http`` object is created that is bound to the
``credentials`` for the current object.

:type use_gax: bool
:param use_gax: (Optional) Explicitly specifies whether
to use the gRPC transport (via GAX) or HTTP. If unset,
falls back to the ``GOOGLE_CLOUD_DISABLE_GRPC`` environment
variable
"""

_connection_class = Connection
_logging_api = _sinks_api = _metrics_api = None

def __init__(self, project=None, credentials=None,
http=None, use_gax=None):
super(Client, self).__init__(project, credentials, http)
if use_gax is None:
self._use_gax = _USE_GAX
else:
self._use_gax = use_gax

@property
def logging_api(self):
"""Helper for logging-related API calls.
Expand All @@ -85,7 +99,7 @@ def logging_api(self):
https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.logs
"""
if self._logging_api is None:
if _USE_GAX:
if self._use_gax:
generated = GeneratedLoggingAPI()
self._logging_api = GAXLoggingAPI(generated)
else:
Expand Down
23 changes: 18 additions & 5 deletions 23 logging/unit_tests/test_client.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def test_ctor(self):
self.assertEqual(client.project, self.PROJECT)

def test_logging_api_wo_gax(self):
from google.cloud.logging.connection import _LoggingAPI
from google.cloud.logging import client as MUT
from google.cloud._testing import _Monkey
client = self._makeOne(self.PROJECT, credentials=_Credentials())
conn = client.connection = object()
from google.cloud.logging import client as MUT
from google.cloud.logging.connection import _LoggingAPI

with _Monkey(MUT, _USE_GAX=False):
api = client.logging_api
client = self._makeOne(self.PROJECT, credentials=_Credentials())
conn = client.connection = object()
api = client.logging_api

self.assertIsInstance(api, _LoggingAPI)
self.assertIs(api._connection, conn)
Expand Down Expand Up @@ -85,6 +85,19 @@ def __init__(self, _wrapped):
again = client.logging_api
self.assertIs(again, api)

def test_no_gax_ctor(self):
from google.cloud._testing import _Monkey
Comment thread

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

from google.cloud.logging import client as MUT
from google.cloud.logging.connection import _LoggingAPI

creds = _Credentials()
with _Monkey(MUT, _USE_GAX=True):
client = self._makeOne(project=self.PROJECT, credentials=creds,
use_gax=False)

api = client.logging_api
self.assertIsInstance(api, _LoggingAPI)

def test_sinks_api_wo_gax(self):
from google.cloud.logging.connection import _SinksAPI
from google.cloud.logging import client as MUT
Expand Down
17 changes: 15 additions & 2 deletions 17 pubsub/google/cloud/pubsub/client.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,20 @@ class Client(JSONClient):
:param http: An optional HTTP object to make requests. If not passed, an
``http`` object is created that is bound to the
``credentials`` for the current object.

:type use_gax: bool
:param use_gax: (Optional) Explicitly specifies whether
to use the gRPC transport (via GAX) or HTTP. If unset,
falls back to the ``GOOGLE_CLOUD_DISABLE_GRPC`` environment
variable
"""
def __init__(self, project=None, credentials=None,
http=None, use_gax=None):
super(Client, self).__init__(project, credentials, http)
if use_gax is None:
self._use_gax = _USE_GAX
else:
self._use_gax = use_gax

_connection_class = Connection
_publisher_api = _subscriber_api = _iam_policy_api = None
Expand All @@ -72,7 +85,7 @@ class Client(JSONClient):
def publisher_api(self):
"""Helper for publisher-related API calls."""
if self._publisher_api is None:
if _USE_GAX:
if self._use_gax:
generated = make_gax_publisher_api(self.connection)
self._publisher_api = GAXPublisherAPI(generated)
else:
Expand All @@ -83,7 +96,7 @@ def publisher_api(self):
def subscriber_api(self):
"""Helper for subscriber-related API calls."""
if self._subscriber_api is None:
if _USE_GAX:
if self._use_gax:
generated = make_gax_subscriber_api(self.connection)
self._subscriber_api = GAXSubscriberAPI(generated)
else:
Expand Down
28 changes: 22 additions & 6 deletions 28 pubsub/unit_tests/test_client.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,33 @@ def test_publisher_api_wo_gax(self):
from google.cloud.pubsub import client as MUT
from google.cloud._testing import _Monkey
creds = _Credentials()
client = self._makeOne(project=self.PROJECT, credentials=creds)
conn = client.connection = object()

with _Monkey(MUT, _USE_GAX=False):
api = client.publisher_api
client = self._makeOne(project=self.PROJECT, credentials=creds)
Comment thread

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.


conn = client.connection = object()
api = client.publisher_api

self.assertIsInstance(api, _PublisherAPI)
self.assertIs(api._connection, conn)
# API instance is cached
again = client.publisher_api
self.assertIs(again, api)

def test_no_gax_ctor(self):
from google.cloud._testing import _Monkey
from google.cloud.pubsub.connection import _PublisherAPI
from google.cloud.pubsub import client as MUT

creds = _Credentials()
with _Monkey(MUT, _USE_GAX=True):
client = self._makeOne(project=self.PROJECT, credentials=creds,
use_gax=False)

self.assertFalse(client._use_gax)
api = client.publisher_api
self.assertIsInstance(api, _PublisherAPI)

def test_publisher_api_w_gax(self):
from google.cloud.pubsub import client as MUT
from google.cloud._testing import _Monkey
Expand Down Expand Up @@ -84,11 +99,12 @@ def test_subscriber_api_wo_gax(self):
from google.cloud.pubsub import client as MUT
from google.cloud._testing import _Monkey
creds = _Credentials()
client = self._makeOne(project=self.PROJECT, credentials=creds)
conn = client.connection = object()

with _Monkey(MUT, _USE_GAX=False):
api = client.subscriber_api
client = self._makeOne(project=self.PROJECT, credentials=creds)
Comment thread

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.


conn = client.connection = object()
api = client.subscriber_api

self.assertIsInstance(api, _SubscriberAPI)
self.assertIs(api._connection, conn)
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.