Skip to content
Merged
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
21 changes: 15 additions & 6 deletions go/vt/callinfo/plugin_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/peer"
)

// GRPCCallInfo returns an augmented context with a CallInfo structure,
Expand All @@ -33,27 +34,35 @@ func GRPCCallInfo(ctx context.Context) context.Context {
if !ok {
return ctx
}
return NewContext(ctx, &gRPCCallInfoImpl{

callinfo := &gRPCCallInfoImpl{
method: method,
})
}
peer, ok := peer.FromContext(ctx)
if ok {
callinfo.remoteAddr = peer.Addr.String()
}

return NewContext(ctx, callinfo)
}

type gRPCCallInfoImpl struct {
method string
method string
remoteAddr string
}

func (gci *gRPCCallInfoImpl) RemoteAddr() string {
return "remote"
return gci.remoteAddr
}

func (gci *gRPCCallInfoImpl) Username() string {
return "gRPC"
}

func (gci *gRPCCallInfoImpl) Text() string {
return fmt.Sprintf("%s(gRPC)", gci.method)
return fmt.Sprintf("%s:%s(gRPC)", gci.remoteAddr, gci.method)
}

func (gci *gRPCCallInfoImpl) HTML() template.HTML {
return template.HTML("<b>Method:</b> " + gci.method)
return template.HTML("<b>Method:</b> " + gci.method + " <b>Remote Addr:</b> " + gci.remoteAddr)
}