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

New 'MessageToDict' implementation breaks with unknown entry types #2674

Closed
tseaver opened this issue Nov 3, 2016 · 18 comments
Closed

New 'MessageToDict' implementation breaks with unknown entry types #2674

tseaver opened this issue Nov 3, 2016 · 18 comments
Assignees
Labels
api: logging Issues related to the Cloud Logging API. grpc priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@tseaver
Copy link
Contributor

tseaver commented Nov 3, 2016

>>> from google.cloud.logging import Client
>>> client = Client()
>>> def do_something_with(entry): pass
... 
>>> for entry in client.list_entries():
...     do_something_with(entry)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/.tox/docs/lib/python2.7/site-packages/google/cloud/iterator.py", line 211, in _items_iter
    for item in page:
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/.tox/docs/lib/python2.7/site-packages/google/cloud/iterator.py", line 155, in next
    result = self._item_to_value(self._parent, item)
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/.tox/docs/lib/python2.7/site-packages/google/cloud/logging/_gax.py", line 478, in _item_to_entry
    resource = MessageToDict(entry_pb)
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/.tox/docs/lib/python2.7/site-packages/google/protobuf/json_format.py", line 133, in MessageToDict
    return printer._MessageToJsonObject(message)
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/.tox/docs/lib/python2.7/site-packages/google/protobuf/json_format.py", line 164, in _MessageToJsonObject
    return self._RegularMessageToJsonObject(message, js)
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/.tox/docs/lib/python2.7/site-packages/google/protobuf/json_format.py", line 196, in _RegularMessageToJsonObject
    js[name] = self._FieldToJsonObject(field, value)
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/.tox/docs/lib/python2.7/site-packages/google/protobuf/json_format.py", line 230, in _FieldToJsonObject
    return self._MessageToJsonObject(value)
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/.tox/docs/lib/python2.7/site-packages/google/protobuf/json_format.py", line 162, in _MessageToJsonObject
    return methodcaller(_WKTJSONMETHODS[full_name][0], message)(self)
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/.tox/docs/lib/python2.7/site-packages/google/protobuf/json_format.py", line 266, in _AnyMessageToJsonObject
    sub_message = _CreateMessageFromTypeUrl(type_url)
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/.tox/docs/lib/python2.7/site-packages/google/protobuf/json_format.py", line 341, in _CreateMessageFromTypeUrl
    'Can not find message descriptor by type_url: {0}.'.format(type_url))
TypeError: Can not find message descriptor by type_url: type.googleapis.com/google.cloud.audit.AuditLog.
@tseaver tseaver added api: logging Issues related to the Cloud Logging API. grpc labels Nov 3, 2016
@dhermes
Copy link
Contributor

dhermes commented Nov 3, 2016

@tseaver Yup, @bjwatson had reported this earlier and I confirmed with @waprin yesterday. Sorry for not filing. I'd been meaning to resolve this.

@bjwatson
Copy link

bjwatson commented Nov 3, 2016

@tseaver @dhermes We're tracking this in https://github.com/googleapis/googleapis/issues/187.

What's the relative priority? We're focused on landing our beta surfaces this month, and the related issue #2572 took me down a long tangential path for the past week.

@dhermes
Copy link
Contributor

dhermes commented Nov 3, 2016

@bjwatson This is something that's my fault, not your fault. There isn't anything you need to fix, we'll always encounter types we don't know about. The proper behavior is just to leave them as Any instances, and I'll make that fix in google-cloud-python

@tseaver
Copy link
Contributor Author

tseaver commented Nov 3, 2016

@bjwatson I can exercise the new logging snippets with GRPC disabled for now.

@bjwatson
Copy link

bjwatson commented Nov 3, 2016

Ok, thanks @dhermes and @tseaver.

@salrashid123
Copy link
Contributor

ran into this issue as well. Just to document, you can disable gRPC using

os.environ["GOOGLE_CLOUD_DISABLE_GRPC"] = "true" 

@dhermes
Copy link
Contributor

dhermes commented Mar 31, 2017

I may just end up reverting #2600.

@dhermes
Copy link
Contributor

dhermes commented Mar 31, 2017

It's fairly relevant that the only Any in the logging protobufs is LogEntry.proto_payload (which is part of the payload oneof)

Currently digging in to a nice repro provided by @Fkawala, I made it totally distinct of this library here in a gist.

@bjwatson bjwatson added the type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. label Apr 1, 2017
dhermes added a commit to dhermes/google-cloud-python that referenced this issue Apr 1, 2017
This is temporary as googleapis#2674 is still being sorted out.
This way we don't block an umbrella release or the release
of error reporting.
dhermes added a commit to dhermes/google-cloud-python that referenced this issue Apr 3, 2017
dhermes added a commit that referenced this issue Apr 6, 2017
…stry. (#3270)

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

Fixes #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.
@mikelambert
Copy link

I just started looking into logging google.appengine.logging.v1.RequestLog, so am happy to see this has been fixed. What's the best way to use this?

I assume that installing google-cloud-logging 1.0.0 won't work if I want to use other google-cloud-* libraries too, due to conflicts on google.cloud.logging package? (Or am I misunderstanding how they interoperate)

So instead, I assume I'm waiting on any version of google-cloud that is post-0.24?

@dhermes
Copy link
Contributor

dhermes commented Apr 21, 2017

Installing google-cloud-logging will work just fine with other packages. For most usage, you can just ignore the google-cloud "uber"-package and focus on the services you actually want to use.

The only place to worry about a version collision is in google-cloud-core, since each package google-cloud-FOO depends on google-cloud-core.

richkadel pushed a commit to richkadel/google-cloud-python that referenced this issue May 6, 2017
This is temporary as googleapis#2674 is still being sorted out.
This way we don't block an umbrella release or the release
of error reporting.
richkadel pushed a commit to richkadel/google-cloud-python that referenced this issue 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.
@eyalev
Copy link

eyalev commented Aug 29, 2017

When I try to run the code here: https://gist.github.com/Fkawala/654093301c47241386b5cd4e02791e56#file-do_log-py

I get an error:

...
...

  File "/usr/local/lib/python2.7/dist-packages/google/cloud/logging/logger.py", line 302, in log_proto
    client.logging_api.write_entries([entry_resource])
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/logging/_gax.py", line 127, in write_entries
    entry_pbs = [_log_entry_mapping_to_pb(entry) for entry in entries]
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/logging/_gax.py", line 499, in _log_entry_mapping_to_pb
    ParseDict(mapping, entry_pb)
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/json_format.py", line 402, in ParseDict
    parser.ConvertMessage(js_dict, message)
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/json_format.py", line 433, in ConvertMessage
    self._ConvertFieldValuePair(value, message)
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/json_format.py", line 539, in _ConvertFieldValuePair
    raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
google.protobuf.json_format.ParseError: Failed to parse protoPayload field: Can not find message descriptor by type_url: type.googleapis.com/google.appengine.logging.v1.RequestLog..

Does it suppose to work? Or is this feature deprecated?
I couldn't fully understand from the conversation..

@yan-hic
Copy link

yan-hic commented May 9, 2018

Unclear if this should be reopened or is a new issue but I get same error when trying to parse a Protobuf payload written by GCP services: json_format.MessageToJson(payload_pb)

It seems the only way to consume GCP logging outside of the UI is to export to bigquery sink and query from there. Or is logging only meant to work with a logger ?

Btw, disabling gRPC has no effect in this case.

@tseaver
Copy link
Contributor Author

tseaver commented May 9, 2018

@yiga2 Looks like you opened #5313 to track the parsing issue for protobuf payloads.

@yan-hic
Copy link

yan-hic commented May 9, 2018

Related but #5313 is to request more documentation whereas here is to report an error with MessageToJson.

If the documentation highlights a different method to use, I agree my present comment is not applicable.

@tseaver
Copy link
Contributor Author

tseaver commented May 10, 2018

@yiga2 json_format.MessageToJson is defined in the protobuf package: please report issues with formatting your particular message type there (I see a couple of open issues related to that function already).

@snarfed
Copy link

snarfed commented Dec 19, 2019

as an example, here's how i generated my own request_log_pb2.py file based on request_log.prototo parse google.appengine.logging.v1.RequestLog serialized protobufs: https://stackoverflow.com/a/59414384/186123. obviously not ideal, i'd rather use an official version maintained by Google instead, but this is an ok workaround in the meantime.

(this also sounds like @mikelambert's use case in #2674 (comment).

@yeruva7
Copy link

yeruva7 commented Mar 3, 2021

When I try to run the code here: https://gist.github.com/Fkawala/654093301c47241386b5cd4e02791e56#file-do_log-py

I get an error:

...
...

  File "/usr/local/lib/python2.7/dist-packages/google/cloud/logging/logger.py", line 302, in log_proto
    client.logging_api.write_entries([entry_resource])
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/logging/_gax.py", line 127, in write_entries
    entry_pbs = [_log_entry_mapping_to_pb(entry) for entry in entries]
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/logging/_gax.py", line 499, in _log_entry_mapping_to_pb
    ParseDict(mapping, entry_pb)
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/json_format.py", line 402, in ParseDict
    parser.ConvertMessage(js_dict, message)
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/json_format.py", line 433, in ConvertMessage
    self._ConvertFieldValuePair(value, message)
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/json_format.py", line 539, in _ConvertFieldValuePair
    raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
google.protobuf.json_format.ParseError: Failed to parse protoPayload field: Can not find message descriptor by type_url: type.googleapis.com/google.appengine.logging.v1.RequestLog..

Does it suppose to work? Or is this feature deprecated?
I couldn't fully understand from the conversation..

@tseaver Are you able to fix this issue?

@yeruva7
Copy link

yeruva7 commented Mar 3, 2021

Need some help for me, I am facing same issue

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. grpc priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
No open projects
Development

No branches or pull requests

9 participants