Skip to content
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.

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

Error Reporting: Add client_options to constructor. #9152

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion error_reporting/google/cloud/error_reporting/_gapic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def make_report_error_api(client):
:returns: An Error Reporting API instance.
"""
gapic_api = report_errors_service_client.ReportErrorsServiceClient(
credentials=client._credentials, client_info=client._client_info
credentials=client._credentials,
client_info=client._client_info,
client_options=client._client_options,
)
return _ErrorReportingGapicApi(gapic_api, client.project)

Expand Down
20 changes: 18 additions & 2 deletions error_reporting/google/cloud/error_reporting/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,27 @@ class _ErrorReportingLoggingAPI(object):
requests. If ``None``, then default info will be used. Generally,
you only need to set this if you're developing your own library
or partner tool.

:type client_options: :class:`~google.api_core.client_options.ClientOptions`
or :class:`dict`
:param client_options: (Optional) Client options used to set user options
on the client. API Endpoint should be set through client_options.
"""

def __init__(self, project, credentials=None, _http=None, client_info=None):
def __init__(
self,
project,
credentials=None,
_http=None,
client_info=None,
client_options=None,
):
self.logging_client = google.cloud.logging.client.Client(
project, credentials, _http=_http, client_info=client_info
project,
credentials,
_http=_http,
client_info=client_info,
client_options=client_options,
)

def report_error_event(self, error_report):
Expand Down
13 changes: 12 additions & 1 deletion error_reporting/google/cloud/error_reporting/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class Client(ClientWithProject):
you only need to set this if you're developing your own library
or partner tool.

:type client_options: :class:`~google.api_core.client_options.ClientOptions`
or :class:`dict`
:param client_options: (Optional) Client options used to set user options
on the client. API Endpoint should be set through client_options.

:raises: :class:`ValueError` if the project is neither passed in nor
set in the environment.
"""
Expand All @@ -158,6 +163,7 @@ def __init__(
service=None,
version=None,
client_info=_CLIENT_INFO,
client_options=None,
_use_grpc=None,
):
super(Client, self).__init__(
Expand All @@ -168,6 +174,7 @@ def __init__(
self.service = service if service else self.DEFAULT_SERVICE
self.version = version
self._client_info = client_info
self._client_options = client_options

if _use_grpc is None:
self._use_grpc = _USE_GRPC
Expand Down Expand Up @@ -195,7 +202,11 @@ def report_errors_api(self):
self._report_errors_api = make_report_error_api(self)
else:
self._report_errors_api = _ErrorReportingLoggingAPI(
self.project, self._credentials, self._http, self._client_info
self.project,
self._credentials,
self._http,
self._client_info,
self._client_options,
)
return self._report_errors_api

Expand Down
8 changes: 6 additions & 2 deletions error_reporting/tests/unit/test__gapic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def _call_fut(client):
return make_report_error_api(client)

def test_make_report_error_api(self):
client = mock.Mock(spec=["project", "_credentials", "_client_info"])
client = mock.Mock(
spec=["project", "_credentials", "_client_info", "_client_options"]
)

# Call the function being tested.
patch = mock.patch(
Expand All @@ -41,7 +43,9 @@ def test_make_report_error_api(self):
self.assertIs(report_error_client._project, client.project)
self.assertIs(report_error_client._gapic_api, patched.return_value)
patched.assert_called_once_with(
credentials=client._credentials, client_info=client._client_info
credentials=client._credentials,
client_info=client._client_info,
client_options=client._client_options,
)


Expand Down
15 changes: 12 additions & 3 deletions error_reporting/tests/unit/test__logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,31 @@ def test_ctor_defaults(self, mocked_cls):

self.assertIs(logging_api.logging_client, mocked_cls.return_value)
mocked_cls.assert_called_once_with(
self.PROJECT, credentials, _http=None, client_info=None
self.PROJECT, credentials, _http=None, client_info=None, client_options=None
)

@mock.patch("google.cloud.logging.client.Client")
def test_ctor_explicit(self, mocked_cls):
credentials = _make_credentials()
http = mock.Mock()
client_info = mock.Mock()
client_options = mock.Mock()

logging_api = self._make_one(
self.PROJECT, credentials, _http=http, client_info=client_info
self.PROJECT,
credentials,
_http=http,
client_info=client_info,
client_options=client_options,
)

self.assertIs(logging_api.logging_client, mocked_cls.return_value)
mocked_cls.assert_called_once_with(
self.PROJECT, credentials, _http=http, client_info=client_info
self.PROJECT,
credentials,
_http=http,
client_info=client_info,
client_options=client_options,
)

@mock.patch("google.cloud.logging.client.Client")
Expand Down
9 changes: 8 additions & 1 deletion error_reporting/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,19 @@ def test_ctor_defaults(self, default_mock):
def test_ctor_explicit(self):
credentials = _make_credentials()
client_info = mock.Mock()
client_options = mock.Mock()
client = self._make_one(
project=self.PROJECT,
credentials=credentials,
service=self.SERVICE,
version=self.VERSION,
client_info=client_info,
client_options=client_options,
)
self.assertEqual(client.service, self.SERVICE)
self.assertEqual(client.version, self.VERSION)
self.assertIs(client._client_info, client_info)
self.assertIs(client._client_options, client_options)

def test_report_errors_api_already(self):
credentials = _make_credentials()
Expand All @@ -87,11 +90,13 @@ def test_report_errors_api_already(self):
def test_report_errors_api_wo_grpc(self):
credentials = _make_credentials()
client_info = mock.Mock()
client_options = mock.Mock()
http = mock.Mock()
client = self._make_one(
project=self.PROJECT,
credentials=credentials,
client_info=client_info,
client_options=client_options,
_http=http,
_use_grpc=False,
)
Expand All @@ -103,7 +108,9 @@ def test_report_errors_api_wo_grpc(self):
api = client.report_errors_api

self.assertIs(api, patched.return_value)
patched.assert_called_once_with(self.PROJECT, credentials, http, client_info)
patched.assert_called_once_with(
self.PROJECT, credentials, http, client_info, client_options
)

def test_report_errors_api_w_grpc(self):
credentials = _make_credentials()
Expand Down