-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Implement grpc-gateway Delimited interface #20983
Conversation
I don't understand the point of this. Can you add a test demonstrating why this is useful? Also, shouldn't this come with an update of the grpc-gateway version? |
Sorry I should elaborate a little to explain why we might want this. In grpc-ecosystem/grpc-gateway@e4b8a93 the grpc-gateway introduced the new So here's the scenario: you use This patch will prevent that, which should help others in the same situation, and adds completeness to the I'm happy to discard this if you disagree with my reasoning, or if we just want to wait for grpc-gateway to cut a new release with the default delimiter instead (I've raised an issue already). |
OK, thanks for explaining. Actually, though we use Lines 50 to 53 in 2e72997
I think the regression you cite is probably not an issue for us because none of our grpc-gateway RPCs are streaming. That said, if we're going to fix this, we need to have tests (similar to the ones upstream added in grpc-ecosystem/grpc-gateway@376e649) so that we can convincingly say streaming RPCs (both JSON and protobuf) work correctly. Seems like this can all be done without bumping the grpc-gateway version, which is good (because it means less work for you). Are you interested in doing that? |
pkg/util/protoutil/jsonpb_marshal.go
Outdated
@@ -133,3 +133,8 @@ func (j *JSONPb) NewEncoder(w io.Writer) gwruntime.Encoder { | |||
return errors.Errorf("unexpected type %T does not implement %s", v, typeProtoMessage) | |||
}) | |||
} | |||
|
|||
// Delimiter for newline encoded JSON streams. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should follow the convention in this file: "Delimiter implements gwruntime.Delimited." (or whatever the name of the interface is. We should also have a static assertion right above this to ensure that the interface is indeed implemented. There's a similar assertion at the top of this file:
var _ gwruntime.Marshaler = (*JSONPb)(nil) |
Please make the same changes to the protobuf marshaler as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The static assertion won't work unless we actually bump the grpc-gateway version, unless you want me to assert interface{ Delimiter() []byte }
. I've updated the comments.
I'll take a stab at adding the tests. |
84ef846
to
7d2b9f8
Compare
Looks like the version of grpc-gateway you have vendored is https://github.com/grpc-ecosystem/grpc-gateway/commit/b0be3cdef0ed27e3c420795e2efbfe9c27e839cc/ which appears to be the very commit that the default |
pkg/util/protoutil/marshaler.go
Outdated
|
||
// Delimiter implements gwruntime.Delimited. | ||
func (*ProtoPb) Delimiter() []byte { | ||
return []byte("\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Encoded protobufs may contain \n
characters. I don't think there is any character (or sequence) that can safely be used as a delimiter here - protobufs are generally used in protocols with length-prefixed frames instead of delimiters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great point. Not sure there's too much we can do here though since it'll default to \n
if we don't use it ourselves. I'll remove this again so at least it's the grpc-gateway that's wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed it.
Right, looks like we'd have to bump to at least grpc-ecosystem/grpc-gateway@e4b8a93 for any of this to work, and at that point we may as well bump all the way and get grpc-ecosystem/grpc-gateway@1d56520. Either way, the test would certainly not be a direct test of the function |
Just to clarify; something like the commit you're pointing to should be sufficient, where we basically just run Also I'm not familiar with the process of updating your dependencies, is there some way we can do it atomically with this PR? |
7d2b9f8
to
c6c21c5
Compare
Sorry, I updated my comment after submitting it. Yes, no need to have a server running; Updating the dependencies is described in https://github.com/cockroachdb/cockroach/blob/master/build/README.md#dependencies. |
Thanks for the clarification, I'll take a stab at it, with the added test of unmarshalling as well. However, the unmarshaller itself doesn't automatically decode the stream, we'll have to split on whatever the delimiter is in the test, unless you want that kind of functionality built into the unmarshaller as well? I'd consider it a bit out of scope for this PR. |
I wouldn't add that into the unmarshaler. Thinking about this a bit more, I'm no longer sure adding a test provides any value; I didn't realize that the unmarshaler doesn't actually handle streaming splitting. I think the right thing to do here is to bump grpc-gateway and add implementations and static assertions - |
Well, that certainly makes my job easier, thanks I'll get it in tomorrow I hope. |
I've created cockroachdb/vendored#13 to bump the grpc-gateway version. |
c6c21c5
to
8ed9eaa
Compare
Made the suggested changes, will update the submodule ref pending cockroachdb/vendored#13 being merged. |
We actually hold off on merging |
Thanks, @benesch. Isn't it possible to point to non-cockroachdb owned branches anyway, though? e.g. cockroachdb/vendored@b36bdd4 Edit: that doesn't prove anything, since you pushed the crdb owned branch. Need more coffee. |
Oh, quite possibly. I don't know how GH decides what refs are available for
a given remote.
…On Fri, Dec 22, 2017 at 11:27 AM, Tamir Duberstein ***@***.*** > wrote:
Thanks, @benesch <https://github.com/benesch>. Isn't it possible to point
to non-cockroachdb owned branches anyway, though? e.g.
***@***.***
<cockroachdb/vendored@b36bdd4>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#20983 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA15IHfKMazgVv_uXwlpWL9Jpy9JAcEJks5tC9hhgaJpZM4RJvx5>
.
|
8ed9eaa
to
e61ea0b
Compare
Ok I think I've got the vendor update done correctly now as well. Please let me know if there was anything else to do. |
Gopkg.toml
Outdated
name = "github.com/grpc-ecosystem/grpc-gateway" | ||
branch = "master" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand if you consider this to be a break with your established methods, but I didn't want to go in and mess with the Gopkg.lock file itself to achieve the desired update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why not leave this as is and run dep ensure -update github.com/grpc-ecosystem/grpc-gateway
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated this explicitly because this was the revision your specified in your comment, I misunderstood you if you meant I should just update to tip. I'll get that done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I need https://github.com/cockroachdb/vendored/tree/johanbrandhorst/bump-grpc-gateway updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might not. Let's see what CI says.
7430b65
to
295270c
Compare
Still need to update the vendor submodule pending |
Try updating the submodule ref anyway, I think it'll work. |
@tamird I don't have a ref I can update to in |
Yes, I think you can - try it. Sorry, I think you can just reference your commit in johanbrandhorst/bump-grpc-gateway. |
To be clear, there are commits that I have updated that is in the fork I have tried pushing directly to |
I understand, and what I'm saying is that Github does some special magic sauce to make your commits in your fork reachable from the upstream repository. Witness: cockroachdb/vendored@fc3aa43 So what I'm saying is - update the submodule ref in this PR and see what happens. |
Gopkg.toml
Outdated
@@ -47,7 +47,7 @@ ignored = [ | |||
name = "github.com/go-sql-driver/mysql" | |||
branch = "master" | |||
|
|||
# https://github.com/grpc-ecosystem/grpc-gateway/commit/893772d | |||
# https://github.com/grpc-ecosystem/grpc-gateway/pull/497 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly nicer if this comment references the commit (https://github.com/grpc-ecosystem/grpc-gateway/commit/8db8c1a
) because it's easier to see from the github commit view when the commit has been included in a release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok will do
@tamird how do I update the submodule ref to another origin? Do I literally go in a add a new remote and check that out? |
Yup, that should work. You can also use Github's magic without adding a remote:
this will fetch and check out your PR. More: https://help.github.com/articles/checking-out-pull-requests-locally/ |
295270c
to
9f8c8dc
Compare
Well what do you know! Sorry for my pig-headedness, I was perhaps misled by the original branch created in the vendored repo. I think I've done everything now, but I'm guessing we'll let CI decide my fate ;) |
No worries! As it turns out, reading more of the documentation I think git won't fetch that ref by default, so CI is likely going to fail and we'll need to summon @benesch to do the manual thing again. |
Seems like CI worked after all? |
Heh, what do you know, it worked. @benesch, should we just push @johanbrandhorst's rev to vendored/master and merge this? |
pkg/util/protoutil/jsonpb_marshal.go
Outdated
@@ -133,3 +133,8 @@ func (j *JSONPb) NewEncoder(w io.Writer) gwruntime.Encoder { | |||
return errors.Errorf("unexpected type %T does not implement %s", v, typeProtoMessage) | |||
}) | |||
} | |||
|
|||
// Delimiter implements gwruntime.Delimited. | |||
func (*JSONPb) Delimiter() []byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we can add the static assertions now, right?
Let's squash these commits while we're at it - no need to do it in two steps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, of course. Will do :).
Implement the Delimited interface for the gogo/protobuf JSONPb marshaller. Fixes cockroachdb#20925
9f8c8dc
to
d1a8109
Compare
Adjustments made, thanks for your patience in what I expected to be a very simple change. Happy holidays :). |
Thanks @johanbrandhorst! @benesch is going to finish this up tonight - you're all good. Happy holidays! |
Thanks for all your hard work, @johanbrandhorst! |
Implement the Delimited interface for the gogo/protobuf JSONPb marshaller. This was added in grpc-ecosystem/grpc-gateway@e4b8a93.
Fixes #20925
@tamird