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

[Issue #96] this is a PoC to solve Issue #96. #97

Merged
merged 5 commits into from
Jun 30, 2020

Conversation

marcellanz
Copy link
Contributor

@marcellanz marcellanz commented May 1, 2020

This should fix issue #96.

Getting messages resolved using proto.MessageTypeand get then registered by proto.RegisterType is probably a bad idea and should only used by generated Go types by protoc.
After some debugging and tests I got with a solution where dumpInterceptor wraps a messages event into a type that implements json.Marshal interface and configures an AnyResolver for the jsonpb.Marshaler knowing all FileDescriptors the proto_descriptor.LoadProtoDirectories function ever sees during the load of the protofiles provided by the -proto_roots argument.

This is implemented in this PR and works for the use case mentioned at the beginning of this issue.

dump_001.json is a successful run of grpc-dump with this PR applied.

@bradleyjkemp I openend this as a Draft PR as my implementation is probably not clean in the general way grpc-tools is designed. I also do not know the protoreflect library well enough. Please let me know of any other way the issue described can be fixed or how you would integrate the functionality into grpc-dump properly.

@marcellanz
Copy link
Contributor Author

hi @bradleyjkemp, how would you like to go forward with this issue and the PR?

@bradleyjkemp
Copy link
Owner

@marcellanz I'm so sorry this has been left unanswered for so long. It's been a while since I worked with gRPC day to day but your analysis + writeup in #96 is excellent.

I've left a couple of comments (in particular I'm curious if this can be solved once during grpc-proxy startup) but this change looks good to me. It seems like it will only improve message dumping, I can't see it will worsen anything.

grpc-dump/dump/dump_interceptor.go Outdated Show resolved Hide resolved
grpc-dump/dump/dump_interceptor.go Show resolved Hide resolved
grpc-dump/dump/dump_interceptor.go Outdated Show resolved Hide resolved

func (p *pbm) MarshalJSON() ([]byte, error) {
fd := make([]*desc.FileDescriptor, 0)
proto_descriptor.MsgDesc.Lock()
Copy link
Owner

Choose a reason for hiding this comment

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

As proto_descriptor.MsgDesc is only going to be mutated during startup (i.e. when loading proto files), I wonder if this step of converting to creating a new dynamic.AnyResolver needs to be done every time?

Should (/could) this just be done once during proto file loading?

Copy link
Contributor Author

@marcellanz marcellanz Jun 22, 2020

Choose a reason for hiding this comment

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

Good point. Beside that, and as I mentioned in #96,

is probably not clean in the general way grpc-tools is designed

proto_descriptor.MsgDesc is a global variable and I'm not sure if this is the right way to bring these message describtors into the dump interceptor. It was the fastest way to have them be available, but should be probably done in a cleaner way. Wdyt?

Co-authored-by: Bradley Kemp <bradleyjkemp@users.noreply.github.com>
@marcellanz
Copy link
Contributor Author

thanks @bradleyjkemp for getting back on this.

@marcellanz I'm so sorry this has been left unanswered for so long. It's been a while since I worked with gRPC day to day but your analysis + writeup in #96 is excellent.

I've left a couple of comments (in particular I'm curious if this can be solved once during grpc-proxy startup) but this change looks good to me. It seems like it will only improve message dumping, I can't see it will worsen anything.

thanks @bradleyjkemp on getting back on this issue. grpc-tools have been very valuable for my work recently and I just ran a local binary for the time being. I'm looking forward to get the fix/feature into the repository so we can use it through a released version.

I've left one comment above about how to share the message descriptors between the internal startup code and grpc-dump we might get cleaned up or not before merging the PR.

Co-authored-by: Bradley Kemp <bradleyjkemp@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Jun 29, 2020

Codecov Report

Merging #97 into master will increase coverage by 0.74%.
The diff coverage is 87.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #97      +/-   ##
==========================================
+ Coverage   56.49%   57.24%   +0.74%     
==========================================
  Files          31       31              
  Lines        1177     1207      +30     
==========================================
+ Hits          665      691      +26     
- Misses        408      410       +2     
- Partials      104      106       +2     
Flag Coverage Δ
#integration 56.66% <87.87%> (+0.76%) ⬆️
#unit 18.67% <ø> (ø)
Impacted Files Coverage Δ
internal/proto_decoder/unknown_message.go 45.74% <0.00%> (-1.00%) ⬇️
grpc-dump/dump/dump_interceptor.go 80.43% <90.47%> (+5.43%) ⬆️
internal/proto_descriptor/protos.go 62.96% <100.00%> (+8.41%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 200d055...e57bb78. Read the comment docs.

@bradleyjkemp bradleyjkemp merged commit e8dcb5d into bradleyjkemp:master Jun 30, 2020
@bradleyjkemp
Copy link
Owner

Thanks for improving this! I'll release it now along with #106

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants