Add MonitoredResource to interface - #3386
Conversation
| :type timestamp: :class:`datetime.datetime` | ||
| :param timestamp: (Optional) timestamp of event being logged. | ||
|
|
||
| :type resource :class:``google.cloud.logging.resource` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| timestamp, resource)) | ||
|
|
||
| def commit(self, client=None): | ||
| def commit(self, client=None, resource=None): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| ).format(**self.__dict__) | ||
|
|
||
|
|
||
| class Resource(collections.namedtuple('Resource', 'type labels')): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Ya like I said just wanted +1 on overall direction before clean up tests docs since I hate writing all the tests/docs then being asked to totally change everything. |
|
@waprin direction looks good. Let me know when you're ready for another review. |
|
@jonparrott ready for review, looks like we have an unrelated BigQuery system test failure. |
theacodes
left a comment
There was a problem hiding this comment.
This mostly LGTM, with a few questions. I'd like @dhermes or @lukesneeringer to do a pass as well. :)
Thanks for doing this, @waprin!
| serious code quality issues. | ||
| """ | ||
| session.interpreter = 'python3.6' | ||
| session.interpreter = 'python3.5' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| self.assertEqual(entries[0].payload, text_payload) | ||
| self.assertEqual(entries[0].timestamp, now.replace(tzinfo=UTC)) | ||
|
|
||
| def test_log_text_with_resource(self): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
System test snafu, forgot they say success without running without service account locally, fixing now. |
dhermes
left a comment
There was a problem hiding this comment.
Mostly cosmetic changes, but one primary question:
Why does the Batch have self.resource but it's methods also accept resource different than self.resource?
| from google.cloud.logging.resource import Resource | ||
|
|
||
|
|
||
| _GLOBAL_RESOURCE = Resource(type='global', labels={}) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| :type timestamp: :class:`datetime.datetime` | ||
| :param timestamp: (Optional) timestamp of event being logged. | ||
|
|
||
| :type resource :class:`google.cloud.logging.resource.Resource` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| :param resource: (Optional) Monitored resource of the entry, defaults | ||
| to the global resource type. | ||
|
|
||
|
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| :param resource: (Optional) Monitored resource of the entry, defaults | ||
| to the global resource type. | ||
|
|
||
|
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| :param http_request: (optional) info about HTTP request associated with | ||
| the entry. | ||
|
|
||
| :type resource :class:``google.cloud.logging.resource.Resource` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| self.assertEqual(len(batch.entries), 0) | ||
|
|
||
| def test_log_text_defaults(self): | ||
| from google.cloud.logging.logger import _GLOBAL_RESOURCE |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| self.entries.append( | ||
| ('text', text, labels, insert_id, severity, http_request, | ||
| timestamp)) | ||
| timestamp, resource)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| self.entries.append( | ||
| ('struct', info, labels, insert_id, severity, http_request, | ||
| timestamp)) | ||
| timestamp, resource)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| self.entries.append( | ||
| ('proto', message, labels, insert_id, severity, http_request, | ||
| timestamp)) | ||
| timestamp, resource)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| else: | ||
| raise ValueError('Unknown entry type: %s' % (entry_type,)) | ||
| if resource is not None: | ||
| info['resource'] = resource._to_dict() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@dhermes as far as Batch resource goes... If you look at the API, when you write multiple entries, you can give each individual entry a resource but also the higher level write call (which we encapsulate as a Batch) a resource. The Batch resource ( Also since all the |
|
Right, I believe the way I did it best matches the API semantics. Only setting it at the Batch level is also not right because your Batch might contain entries of different resource type. Fixing coverage now... |
| :type http_request: dict | ||
| :param http_request: (optional) info about HTTP request associated with | ||
| the entry | ||
| :type resource :class:`google.cloud.logging.resource.Resource` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| :param http_request: (optional) info about HTTP request associated with | ||
| the entry | ||
|
|
||
| :type resource :class:`google.cloud.logging.resource.Resource` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| :type client: :class:`google.cloud.logging.client.Client` | ||
| :param client: The client to use. | ||
|
|
||
| :type resource: :class:`google.cloud.logging.resource.Resource` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| entry = { | ||
| 'logName': self.full_name, | ||
| 'resource': {'type': 'global'}, | ||
| 'resource': resource._to_dict() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| self.entries.append( | ||
| ('text', text, labels, insert_id, severity, http_request, | ||
| timestamp)) | ||
| timestamp, resource)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| test runs (not system test runs), and then erases coverage data. | ||
| """ | ||
| session.interpreter = 'python3.6' | ||
| session.interpreter = 'python3.5' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| @@ -1,4 +1,4 @@ | |||
| # Copyright 2016 Google Inc. | |||
| # Copyright 2017 Google Inc. | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| labels={ | ||
| 'module_id': 'default', | ||
| 'version_id': 'test' | ||
| }) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| 'labels': { | ||
| 'module_id':'default', | ||
| 'version': 'test' | ||
| }}) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| 'resource': { | ||
| 'type': 'global', | ||
| 'labels': {}, | ||
|
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@jonparrott @dhermes docs built, just looked carefully at all the styles/docs issue and all lgtm so this is ready for another pass |
| :type http_request: dict | ||
| :param http_request: (optional) info about HTTP request associated with | ||
| the entry | ||
| :type resource: :class:`~google.cloud.logging.resource.Resource` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| the entry. | ||
|
|
||
| :type resource: :class:`~google.cloud.logging.resource.Resource` | ||
| :param resource: Monitored resource of the entry |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| :param timestamp: (optional) timestamp of event being logged. | ||
|
|
||
| :type resource: :class:`~google.cloud.logging.resource.Resource` | ||
| :param resource: (Optional) Monitored resource of the entry |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@dhermes ready for another pass/merge |
theacodes
left a comment
There was a problem hiding this comment.
Looks almost good to me, two outstanding questions.
| labels=None, insert_id=None, severity=None, | ||
| http_request=None, timestamp=None): | ||
| http_request=None, timestamp=None, | ||
| resource=_GLOBAL_RESOURCE): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| self.assertEqual(entries[0].payload, text_payload) | ||
| self.assertEqual(entries[0].timestamp, now.replace(tzinfo=UTC)) | ||
|
|
||
| def test_log_text_with_resource(self): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
System tests default to whatever the Client defaults to which is usually gRPC unless it's not supported. It seems a reasonable idea to parametrize the system tests to run with gRPC on and off, but don't think that's particular to these tests. Will create separate issue. |
commented
May 24, 2017
|
Hey guys, when will this be released in the google-cloud-logging package? |
commented
May 24, 2017
|
@lukesneeringer I can do a release today. WDYT? |
commented
Jun 22, 2017
|
@tseaver I've had an internal request to release this Logging fix ASAP. Since you're planning to do new releases this week, this should be covered, but I just wanted to make sure. |
commented
Jun 23, 2017
|
@bjwatson Still on my radar: at this point I will be making releases over the weekend, to catch up with some unplanned sitting-in-waiting-room time this week. |
commented
Jun 23, 2017
|
Thanks @tseaver! Sorry to hear about excessive waiting room time this week. |
This adds MonitoredResource as an option to higher level interface.
Fixes #3377 and #2673.
I also changed the variable name from
resourcetoentryinmake_entry_resourcebecause its' confusing to call it a resource when resource is overloaded.Tests/docs are TBD, wanted +1 on overall direction then I'll write them.
Some notes:
This is intended to be a non-breaking change to existing users. If you use
log_text,log_structetc the default is still the global resource. However, within aBatchyou could also explicitly set it to None and wait to set it until the finalcommitcall.Copied the Resource class from Monitoring. They are the same proto so we could move it to a common package . We could also use the proto but unclear if that will work with the _gax. This is what @jonparrott suggested and I think is pretty.
cc @liyanhui1228 @duggelz