Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query_executor: Record WaitingForConnection stat in all cases #15073

Merged
merged 6 commits into from
Jan 31, 2024
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
11 changes: 7 additions & 4 deletions go/vt/vttablet/tabletserver/query_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,13 @@ func (qre *QueryExecutor) getConn() (*connpool.PooledConn, error) {
span, ctx := trace.NewSpan(qre.ctx, "QueryExecutor.getConn")
defer span.Finish()

start := time.Now()
defer func(start time.Time) {
qre.logStats.WaitingForConnection += time.Since(start)
}(time.Now())
conn, err := qre.tsv.qe.conns.Get(ctx, qre.setting)

switch err {
case nil:
qre.logStats.WaitingForConnection += time.Since(start)
return conn, nil
case connpool.ErrConnPoolClosed:
return nil, err
Expand All @@ -792,11 +793,13 @@ func (qre *QueryExecutor) getStreamConn() (*connpool.PooledConn, error) {
span, ctx := trace.NewSpan(qre.ctx, "QueryExecutor.getStreamConn")
defer span.Finish()

start := time.Now()
defer func(start time.Time) {
qre.logStats.WaitingForConnection += time.Since(start)
}(time.Now())
conn, err := qre.tsv.qe.streamConns.Get(ctx, qre.setting)

switch err {
case nil:
qre.logStats.WaitingForConnection += time.Since(start)
return conn, nil
case connpool.ErrConnPoolClosed:
return nil, err
Expand Down
38 changes: 38 additions & 0 deletions go/vt/vttablet/tabletserver/query_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,44 @@ func TestQueryExecutorShouldConsolidate(t *testing.T) {
}
}

func TestGetConnectionLogStats(t *testing.T) {
db := setUpQueryExecutorTest(t)
defer db.Close()

ctx := context.Background()
tsv := newTestTabletServer(ctx, noFlags, db)
input := "select * from test_table limit 1"

// getConn() happy path
qre := newTestQueryExecutor(ctx, tsv, input, 0)
conn, err := qre.getConn()
assert.NoError(t, err)
assert.NotNil(t, conn)
assert.True(t, qre.logStats.WaitingForConnection > 0)

// getStreamConn() happy path
qre = newTestQueryExecutor(ctx, tsv, input, 0)
conn, err = qre.getStreamConn()
assert.NoError(t, err)
assert.NotNil(t, conn)
assert.True(t, qre.logStats.WaitingForConnection > 0)

// Close the db connection to induce connection errors
db.Close()

// getConn() error path
qre = newTestQueryExecutor(ctx, tsv, input, 0)
_, err = qre.getConn()
assert.Error(t, err)
assert.True(t, qre.logStats.WaitingForConnection > 0)

// getStreamConn() error path
qre = newTestQueryExecutor(ctx, tsv, input, 0)
_, err = qre.getStreamConn()
assert.Error(t, err)
assert.True(t, qre.logStats.WaitingForConnection > 0)
}

type executorFlags int64

const (
Expand Down
Loading