Skip to content

Commit

Permalink
add execute timing stats (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
demmer authored May 6, 2024
1 parent eefd8b0 commit 10d4525
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions go/vt/vtgateproxy/vtgateproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import (
"net/url"
"strings"
"sync"
"time"

"google.golang.org/grpc"

"vitess.io/vitess/go/sqlescape"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/stats"
"vitess.io/vitess/go/vt/grpcclient"
"vitess.io/vitess/go/vt/log"
querypb "vitess.io/vitess/go/vt/proto/query"
Expand All @@ -39,6 +41,12 @@ import (
"vitess.io/vitess/go/vt/vtgate/vtgateconn"
)

const (
// timing metric keys
executeTimingKey = "Execute"
streamExecuteTimingKey = "StreamExecute"
)

var (
vtgateHostsFile = flag.String("vtgate_hosts_file", "", "json file describing the host list to use for vtgate:// resolution")
numConnections = flag.Int("num_connections", 4, "number of outbound GPRC connections to maintain")
Expand All @@ -48,6 +56,8 @@ var (
addressField = flag.String("address_field", "address", "field name in the json file containing the address")
portField = flag.String("port_field", "port", "field name in the json file containing the port")

timings = stats.NewTimings("Timings", "proxy timings by operation", "operation")

vtGateProxy *VTGateProxy = &VTGateProxy{
targetConns: map[string]*vtgateconn.VTGateConn{},
mu: sync.RWMutex{},
Expand Down Expand Up @@ -160,10 +170,17 @@ func (proxy *VTGateProxy) Execute(ctx context.Context, session *vtgateconn.VTGat
return &sqltypes.Result{}, nil
}

startTime := time.Now()
defer timings.Record(executeTimingKey, startTime)

return session.Execute(ctx, sql, bindVariables)

}

func (proxy *VTGateProxy) StreamExecute(ctx context.Context, session *vtgateconn.VTGateSession, sql string, bindVariables map[string]*querypb.BindVariable, callback func(*sqltypes.Result) error) error {
startTime := time.Now()
defer timings.Record(streamExecuteTimingKey, startTime)

stream, err := session.StreamExecute(ctx, sql, bindVariables)
if err != nil {
return err
Expand Down

0 comments on commit 10d4525

Please sign in to comment.