grpc: add PeerInfo to client's ResponseHeaders and Trailers - #2802
grpc: add PeerInfo to client's ResponseHeaders and Trailers#2802dfawley wants to merge 3 commits into
Conversation
…he response stream ends
|
@arjan-bal - I had to merge in the cancellation changes that you recently submitted. I'm a little uncertain about the tonic behavior if we call In these cases, IIUC tonic itself should send a |
ejona86
left a comment
There was a problem hiding this comment.
Didn't have time to look at it deeply.
| TonicRecvStream { | ||
| state: StreamState::AwaitingHeaders(resp_rx), | ||
| cancel_tx: Some(cancel_tx), | ||
| peer_info: Some(self.peer_info.clone()), |
There was a problem hiding this comment.
Do we really want to clone the entire thing? I see we're cloning the entire thing for CallCredentials already. Are we going to Arc things inside Attributes instead, like the client's certificate?
There was a problem hiding this comment.
Attributes is a linked list with Arc'd nodes, so a clone of PeerInfo is fairly small:
- Two
Addresses, each with&'static,ByteStr(containsByteswhose data isArc'd),Attributes(Arc'd) - One
SecurityInfowith&'static,SecurityLevel(3 value enum with no data), andAttributes(Arc'd)
I do want to delete the Attributes from Address, so it would be down to two Arcs: the ByteStr and SecurityInfo.
The tradeoff would be simplicity for performance. If PeerInfo needed to be mutated in the stack somewhere, it might be worse if it was Arc'd. But, I wouldn't expect that to happen, so maybe it's best in its own Arc?
I think we could change this in a hidden/backward compatible way if we wanted to convert it to hold Arc<InnerPeerInfo>. The accessors just hand out references, which could be references to the value inside the Arc, and PeerInfo is immutable.
| /// pair). | ||
| #[derive(Debug, Clone)] | ||
| pub struct PeerInfo { | ||
| local_address: Address, |
There was a problem hiding this comment.
Local address is in the peer's information?
There was a problem hiding this comment.
I did 👀 at this as well. PeerInfo->ConnectionInfo? We call it Peer in Go and have the local address there (just FYI, not as justification; it happened that we added it later there): https://pkg.go.dev/google.golang.org/grpc/peer#Peer
Also: return
PeerInfofromTransport::connectinstead ofSecurityInfo(yes, I know I just changed it to produceSecurityInfo) so that the subchannel can set the fullPeerInfoin Trailers when producing errors locally, since the address of the subchannel may be relevant to those errors.FWIW I wanted to make the subchannel apply an interceptor that could always set
PeerInfoin response streams (eitherResponseHeadersor inTrailers-only responses), but because the field is mandatory inResponseHeaders, the transport would need to set it to some default/empty value, which felt wrong. Anything producing aResponseHeadersorTrailersshould ensure thePeerInfois set correctly.cc @joshuatants as FYI - this is the change that will provide you with the ability to determine the server's address.