Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.
Merged
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
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)
}
57 changes: 57 additions & 0 deletions go/vt/callinfo/plugin_mysql.go
Original file line number Diff line number Diff line change
@@ -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("<b>MySQL User:</b> " + mci.user + " <b>Remote Addr:<b> " + mci.remoteAddr)
}
3 changes: 3 additions & 0 deletions go/vt/vtgate/plugin_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down