Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr, handler s
LocalAddr: t.localAddr,
Compression: callHdr.SendCompress,
Header: header,
Authority: callHdr.Host,
})
}
if transportDrainRequired {
Expand Down
3 changes: 3 additions & 0 deletions stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ type OutHeader struct {
Compression string
// Header contains the header metadata sent.
Header metadata.MD
// Authority is the :authority pseudo-header sent for the RPC.
// It is valid only if Client is true.
Authority string

// The following fields are valid only if Client is true.
// FullMethod is the full RPC method string, i.e., /package.service/method.
Expand Down
41 changes: 36 additions & 5 deletions stats/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,11 @@ const (
)

type rpcConfig struct {
count int // Number of requests and responses for streaming RPCs.
success bool // Whether the RPC should succeed or return error.
failfast bool
callType rpcType // Type of RPC.
count int // Number of requests and responses for streaming RPCs.
success bool // Whether the RPC should succeed or return error.
failfast bool
authority string // Authority override for the RPC.
callType rpcType // Type of RPC.
}

func (te *test) doUnaryCall(c *rpcConfig) (*testpb.SimpleRequest, *testpb.SimpleResponse, error) {
Expand All @@ -315,7 +316,11 @@ func (te *test) doUnaryCall(c *rpcConfig) (*testpb.SimpleRequest, *testpb.Simple
req = &testpb.SimpleRequest{Payload: idToPayload(errorID)}
}

resp, err = tc.UnaryCall(metadata.NewOutgoingContext(tCtx, testMetadata), req, grpc.WaitForReady(!c.failfast))
callOpts := []grpc.CallOption{grpc.WaitForReady(!c.failfast)}
if c.authority != "" {
callOpts = append(callOpts, grpc.CallAuthority(c.authority))
}
resp, err = tc.UnaryCall(metadata.NewOutgoingContext(tCtx, testMetadata), req, callOpts...)
return req, resp, err
}

Expand Down Expand Up @@ -427,6 +432,7 @@ type expectedData struct {
isServerStream bool
serverAddr string
compression string
authority string
reqIdx int
requests []proto.Message
respIdx int
Expand Down Expand Up @@ -620,6 +626,13 @@ func checkOutHeader(t *testing.T, d *gotData, e *expectedData) {
if st.RemoteAddr.String() != e.serverAddr {
t.Fatalf("st.RemoteAddr = %v, want %v", st.RemoteAddr, e.serverAddr)
}
wantAuthority := e.authority
if wantAuthority == "" {
wantAuthority = e.serverAddr
}
if st.Authority != wantAuthority {
t.Fatalf("st.Authority = %s, want %s", st.Authority, wantAuthority)
}
// additional headers might be injected so instead of testing equality, test that all the
// expected headers keys have the expected header values.
for key := range testMetadata {
Expand Down Expand Up @@ -1210,6 +1223,7 @@ func testClientStats(t *testing.T, tc *testConfig, cc *rpcConfig, checkFuncs map
err: err,
isClientStream: isClientStream,
isServerStream: isServerStream,
authority: cc.authority,
}

h.mu.Lock()
Expand All @@ -1230,6 +1244,23 @@ func (s) TestClientStatsUnaryRPC(t *testing.T) {
})
}

func (s) TestClientStatsUnaryRPCAuthority(t *testing.T) {
testClientStats(t, &testConfig{compress: ""}, &rpcConfig{
success: true,
failfast: false,
authority: "authority-override.example.com",
callType: unaryRPC,
}, map[int]*checkFuncWithCount{
begin: {checkBegin, 1},
outHeader: {checkOutHeader, 1},
outPayload: {checkOutPayload, 1},
inHeader: {checkInHeader, 1},
inPayload: {checkInPayload, 1},
inTrailer: {checkInTrailer, 1},
end: {checkEnd, 1},
})
}

func (s) TestClientStatsUnaryRPCError(t *testing.T) {
testClientStats(t, &testConfig{compress: ""}, &rpcConfig{success: false, failfast: false, callType: unaryRPC}, map[int]*checkFuncWithCount{
begin: {checkBegin, 1},
Expand Down
Loading