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

Added calloption to retrieve peer information #1066

Merged
merged 5 commits into from
Feb 8, 2017

Conversation

MakMukhi
Copy link
Contributor

@MakMukhi MakMukhi commented Feb 7, 2017

No description provided.

rpc_util.go Outdated
@@ -141,6 +142,7 @@ type callInfo struct {
headerMD metadata.MD
trailerMD metadata.MD
traceInfo traceInfo // in trace.go
peer peer.Peer
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this above traceInfo?

rpc_util.go Outdated
@@ -183,6 +185,13 @@ func Trailer(md *metadata.MD) CallOption {
})
}

// Peer returns a CallOption that retrieves peer information.
Copy link
Contributor

Choose a reason for hiding this comment

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

Add "for a unary RPC" at the end so it's consistent with Header and Trailer?

if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}, grpc.Peer(peer)); err != nil {
t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, <nil>", err)
}
pa := extractPort(peer.Addr.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

defer te.tearDown()
tc := testpb.NewTestServiceClient(te.clientConn())
peer := new(peer.Peer)
if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}, grpc.Peer(peer)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add grpc.FailFast(false)?

rpc_util.go Outdated
@@ -140,6 +141,7 @@ type callInfo struct {
failFast bool
headerMD metadata.MD
trailerMD metadata.MD
peer peer.Peer
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better to use a *peer.Peer here?
So that we don't need to copy peer in recvResponse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. In such a case the function Peer(peer *peer.Peer) would now need to take a double pointer argument: Peer(peer *peer.Peer).
  2. Providing a pointer to the original object doesn't have much use since there's no use case that requires the user to update the object.
  3. All these changes only enable one less copy of the object which seems like over-optimization.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can still make a copy and return the copy of Peer to the user, so we can avoid the double pointer.

I was thinking that we should avoid copying Peer inside gRPC.
Assume most users don't care about peer, so they won't use this new CallOption. In that case, we don't need to copy Peer and return it. But the copy in recvResponse will still happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point. Yes, it makes sense to remove this copy from the codepath of the users that don't care about this value.

@menghanl menghanl merged commit 9b791e0 into grpc:master Feb 8, 2017
@MakMukhi MakMukhi deleted the peer_calloption branch May 4, 2018 02:08
@lock lock bot locked as resolved and limited conversation to collaborators Oct 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants