diff --git a/go/vt/callinfo/plugin_grpc.go b/go/vt/callinfo/plugin_grpc.go
index 3a79a08e815..558609069d1 100644
--- a/go/vt/callinfo/plugin_grpc.go
+++ b/go/vt/callinfo/plugin_grpc.go
@@ -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,
@@ -33,17 +34,25 @@ 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 {
@@ -51,9 +60,9 @@ func (gci *gRPCCallInfoImpl) Username() string {
}
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("Method: " + gci.method)
+ return template.HTML("Method: " + gci.method + " Remote Addr: " + gci.remoteAddr)
}
diff --git a/go/vt/callinfo/plugin_mysql.go b/go/vt/callinfo/plugin_mysql.go
new file mode 100644
index 00000000000..d82f1ce1704
--- /dev/null
+++ b/go/vt/callinfo/plugin_mysql.go
@@ -0,0 +1,57 @@
+/*
+Copyright 2018 The Vitess Authors
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreedto in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package callinfo
+
+// This file implements the CallInfo interface for Mysql contexts.
+
+import (
+ "fmt"
+ "html/template"
+
+ "golang.org/x/net/context"
+ "vitess.io/vitess/go/mysql"
+)
+
+// MysqlCallInfo returns an augmented context with a CallInfo structure,
+// only for Mysql contexts.
+func MysqlCallInfo(ctx context.Context, c *mysql.Conn) context.Context {
+ return NewContext(ctx, &mysqlCallInfoImpl{
+ remoteAddr: c.RemoteAddr().String(),
+ user: c.User,
+ })
+}
+
+type mysqlCallInfoImpl struct {
+ remoteAddr string
+ user string
+}
+
+func (mci *mysqlCallInfoImpl) RemoteAddr() string {
+ return mci.remoteAddr
+}
+
+func (mci *mysqlCallInfoImpl) Username() string {
+ return mci.user
+}
+
+func (mci *mysqlCallInfoImpl) Text() string {
+ return fmt.Sprintf("%s@%s(Mysql)", mci.user, mci.remoteAddr)
+}
+
+func (mci *mysqlCallInfoImpl) HTML() template.HTML {
+ return template.HTML("MySQL User: " + mci.user + " Remote Addr: " + mci.remoteAddr)
+}
diff --git a/go/vt/vtgate/plugin_mysql_server.go b/go/vt/vtgate/plugin_mysql_server.go
index 194f04a428b..37628f9cb3c 100644
--- a/go/vt/vtgate/plugin_mysql_server.go
+++ b/go/vt/vtgate/plugin_mysql_server.go
@@ -30,6 +30,7 @@ import (
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/callerid"
+ "vitess.io/vitess/go/vt/callinfo"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/vttls"
@@ -105,6 +106,8 @@ func (vh *vtgateHandler) ComQuery(c *mysql.Conn, query string, callback func(*sq
ctx = context.Background()
}
+ ctx = callinfo.MysqlCallInfo(ctx, c)
+
// Fill in the ImmediateCallerID with the UserData returned by
// the AuthServer plugin for that user. If nothing was
// returned, use the User. This lets the plugin map a MySQL