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

Gracefully continue if LogEntry.proto_payload type URL is not in registry. #3270

Merged
merged 5 commits into from
Apr 6, 2017

Conversation

dhermes
Copy link
Contributor

@dhermes dhermes commented Apr 3, 2017

Fixes #2674.

@lukesneeringer @tseaver I am unfortunately "out of time" until Wednesday so if either of you want to take this over the finish line (e.g. unit tests and maybe a system test with an unregistered type URL?) I would not protest.

@dhermes dhermes added the api: logging Issues related to the Cloud Logging API. label Apr 3, 2017
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 3, 2017
"""
try:
return MessageToDict(entry_pb)
except TypeError:

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@@ -270,11 +272,13 @@ def sink_update(self, project, sink_name, filter_, destination):
path = 'projects/%s/sinks/%s' % (project, sink_name)
sink_pb = LogSink(name=path, filter=filter_, destination=destination)
try:
self._gax_api.update_sink(path, sink_pb, options=options)
sink_pb = self._gax_api.update_sink(path, sink_pb, options=options)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@@ -418,11 +424,14 @@ def metric_update(self, project, metric_name, filter_, description):
metric_pb = LogMetric(name=path, filter=filter_,
description=description)
try:
self._gax_api.update_log_metric(path, metric_pb, options=options)
metric_pb = self._gax_api.update_log_metric(

This comment was marked as spam.

This comment was marked as spam.

@@ -293,7 +293,7 @@ def sink_update(self, project, sink_name, filter_, destination):
'filter': filter_,
'destination': destination,
}
self.api_request(method='PUT', path=target, data=data)
return self.api_request(method='PUT', path=target, data=data)

This comment was marked as spam.

This comment was marked as spam.

@@ -428,7 +428,7 @@ def metric_update(self, project, metric_name, filter_, description):
'filter': filter_,
'description': description,
}
self.api_request(method='PUT', path=target, data=data)
return self.api_request(method='PUT', path=target, data=data)

This comment was marked as spam.

This comment was marked as spam.

@@ -74,7 +77,13 @@ class _BaseEntry(object):
"""
def __init__(self, payload, logger, insert_id=None, timestamp=None,
labels=None, severity=None, http_request=None):
self.payload = payload
if isinstance(payload, any_pb2.Any):

This comment was marked as spam.

@lukesneeringer
Copy link
Contributor

I will try to get this over the line today if I can.

Copy link
Contributor Author

@dhermes dhermes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL @lukesneeringer (and @tseaver and anyone else interested in this PR)

@@ -270,11 +272,13 @@ def sink_update(self, project, sink_name, filter_, destination):
path = 'projects/%s/sinks/%s' % (project, sink_name)
sink_pb = LogSink(name=path, filter=filter_, destination=destination)
try:
self._gax_api.update_sink(path, sink_pb, options=options)
sink_pb = self._gax_api.update_sink(path, sink_pb, options=options)

This comment was marked as spam.

self.payload_pb = self.payload
self.payload = None
else:
self.payload_pb = None

This comment was marked as spam.

This comment was marked as spam.

self.assertIsNone(protobuf_entry.payload)
self.assertIsInstance(protobuf_entry.payload_pb, any_pb2.Any)
self.assertEqual(protobuf_entry.payload_pb.type_url, type_url)
else:

This comment was marked as spam.

This comment was marked as spam.

@@ -108,6 +108,7 @@ class TestLogging(unittest.TestCase):
'precipitation': False,
},
}
TYPE_FILTER = 'protoPayload.@type = "{}"'

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

filter_ = self.TYPE_FILTER.format(type_url)
entry_iter = iter(
Config.CLIENT.list_entries(page_size=1, filter_=filter_))
protobuf_entry = next(entry_iter)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

},
'requestTime': {
'seconds': 1491000125,
}

This comment was marked as spam.

'requestTime': {
'seconds': 1491000125,
}
}

This comment was marked as spam.

@dhermes dhermes mentioned this pull request Apr 6, 2017
@dhermes
Copy link
Contributor Author

dhermes commented Apr 6, 2017

@tseaver @lukesneeringer Do you have any issues?

@waprin Can you vet my newly added system test?

@lukesneeringer
Copy link
Contributor

No issues. Approved.

@waprin
Copy link
Contributor

waprin commented Apr 6, 2017

@dhermes tied up today but can review your tests and try to make mine less flaky (and loop back to any other pending issues for me in this repo) tomorrow.

@dhermes
Copy link
Contributor Author

dhermes commented Apr 6, 2017

Thanks @waprin. AFAIK the other ones aren't very flaky any more (or not at all?).

Let's get this merged and then @waprin you can "verify" the new system test after the fact?

@dhermes dhermes merged commit ff3063e into googleapis:master Apr 6, 2017
@dhermes dhermes deleted the fix-2674 branch April 6, 2017 18:42
@waprin
Copy link
Contributor

waprin commented Apr 14, 2017

@dhermes sorry for delay, nice PR. One quick note about the system test - I think it's fine but in general the gotcha to be aware of with Logging is that you can get an empty page followed by a page with results. The nextPageToken is used as a sort of "pending" sign (not a fan of this but that's how it works). So in theory entry = next(iter) could fail if the query is too slow, really you always want to wrap it it in a loop (not sure if there is an elegant way to have client library do this for you). Now usually you only get slow queries when looking through huge amounts of logs like all of the ones for a project but it's something to be aware of. Again not really an issue just giving you a heads up on something that's burned me and others.

@dhermes
Copy link
Contributor Author

dhermes commented Apr 14, 2017

@waprin I'll be on the lookout for that if there is a flaky failure.

richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
…stry. (googleapis#3270)

* Gracefully continue if LogEntry.proto_payload type URL is not in registry.

Fixes googleapis#2674.

* Adding unit / system tests for "graceful" continuation on LogEntry parsing.

* Docs fix for PR 3270.

* Adding rtype/returns to metric_update and sink_update in logging _http module.

* Add trailing commas.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the Cloud Logging API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants