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

rpc: install custom proto codec #61333

Merged
merged 1 commit into from Mar 23, 2021
Merged

Conversation

stevendanna
Copy link
Collaborator

This change enables future upgrades of google.golang.org/grpc.

Recent changes to google.golang.org/grpc have changed the default
proto codec such that it is incompatible with gogoproto:

grpc/grpc-go#3958

While proto.Marshal does do a check for the Marshal/Unmarshal it
appears to do this through reflection methods that will panic on
fields using gogoproto.nullable.

To avoid this, we install a proto codec that does an interface check
before dispatching to proto.Marshal/proto.Unmarshal.

Note that I haven't replicated the protobuffer caching that previously
existed in google.golang.org/grpc. The referenced change claims
removing the caching may be a small performance win; however, they
also removed the typecheck that we need to do, so it is unclear.

Fixes #60531

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@stevendanna
Copy link
Collaborator Author

I've left out a release justification as I imagine this can wait until we've cut the release branch.

@stevendanna
Copy link
Collaborator Author

@pbardea I believe you also need something like this. Perhaps now that master is reopen we can merge the codec separately from the dep updates so that those can be considered in isolation.

I believe @knz and @tbg said the codec changes looked good in #60709; however, I had to make a couple changes to account for some cases that our tests didn't seem to hit.

Copy link
Contributor

@pbardea pbardea left a comment

Choose a reason for hiding this comment

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

LGTM with nits given the comments in 60709

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @stevendanna)


pkg/rpc/codec.go, line 1 at r1 (raw file):

// Copyright 2020 The Cockroach Authors.

Should this be 2021? (And the test)


pkg/rpc/codec_test.go, line 37 at r1 (raw file):

		{"roachpb.GetRequest", func() interface{} { return &roachpb.GetRequest{} }},
	} {
		t.Run(fmt.Sprintf("can call marshal and unmarhsal on %s", test.name), func(t *testing.T) {

nit: typo in unmarhsal, i also have a slight preference for test names without spaces to avoid needing to manually convert when debugging. Maybe something like marshal-unmarshal-%s or TestCodedMarshalUnmarshal and just test.name here? Don't feel strongly here, take it or leave it :)


pkg/testutils/lint/lint_test.go, line 1654 at r1 (raw file):

				// Using deprecated WireLength call.
				stream.GrepNot(`pkg/rpc/stats_handler.go:.*v.WireLength is deprecated: This field is never set.*`),
				// rpc/codec.go imports the same proto package that grpc-go imports (as of crdb@dd87d1145 and grpc-go@7b167fd6)

super-nit: . at end of line

@stevendanna stevendanna force-pushed the grpc-proto-codec branch 2 times, most recently from 96830e6 to ba99f93 Compare March 18, 2021 14:26
@knz
Copy link
Contributor

knz commented Mar 18, 2021

@erikgrinaker can you review this too please?

@knz knz added this to In progress in DB Server & Security via automation Mar 18, 2021
Copy link
Contributor

@erikgrinaker erikgrinaker left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 5 files at r1, 2 of 3 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @stevendanna)


pkg/rpc/codec_test.go, line 40 at r2 (raw file):

err = testCodec.Unmarshal(marshaled, test.msgBuilder())
			require.NoError(t, err, "unmarshal failed")

Maybe we should check that the unmarshaled message equals the marshaled one (using proto.Equal) and put some contents in the messages too?

This change enables future upgrades of google.golang.org/grpc.

Recent changes to google.golang.org/grpc have changed the default
proto codec such that it is incompatible with gogoproto:

grpc/grpc-go#3958

While `proto.Marshal` does do a check for the Marshal/Unmarshal it
appears to do this through reflection methods that will panic on
fields using gogoproto.nullable.

To avoid this, we install a proto codec that does an interface check
before dispatching to proto.Marshal/proto.Unmarshal.

Note that I haven't replicated the protobuffer caching that previously
existed in google.golang.org/grpc. The referenced change claims
removing the caching may be a small performance win; however, they
also removed the typecheck that we need to do, so it is unclear.

Fixes cockroachdb#60531

Release note: None
@stevendanna
Copy link
Collaborator Author

Maybe we should check that the unmarshaled message equals the marshaled one (using proto.Equal) and put some contents in the messages too?

I've added a basic version of this but didn't add too many populated fields. Unfortunately, most methods of comparing the Go representation of the proto are broken for cases where you might be passing in different types of protos. For now, I've done some ugly things with reflect to make DeepEqual work for the proto's used in this test.

@erikgrinaker
Copy link
Contributor

Yeah, comparing the Go structs using e.g. DeepEqual is a hassle because there's lots of Protobuf internals. You can just use proto.Equal() to compare the fields we care about and ignore the internals.

@stevendanna
Copy link
Collaborator Author

You can just use proto.Equal() to compare the fields we care about and ignore the internals.

Unfortunately, I don't think we can. Google's proto.Equal() does not work correctly for gogoproto generated types and Gogoproto's proto.Equal doesn't work correctly because of some bugs.

@erikgrinaker
Copy link
Contributor

Groan, you're right. Thanks for going the extra mile here!

@stevendanna
Copy link
Collaborator Author

bors r=[erikgrinaker,pbardea]

@craig
Copy link
Contributor

craig bot commented Mar 23, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Mar 23, 2021

Build succeeded:

@craig craig bot merged commit 6dba216 into cockroachdb:master Mar 23, 2021
DB Server & Security automation moved this from In progress to Done 21.1 Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vendor: can't upgrade to grpc-go v1.34
5 participants