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

kvcoord: print traced query when failing the TestProxyTracing #136001

Closed
Closed
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
23 changes: 23 additions & 0 deletions pkg/kv/kvclient/kvcoord/dist_sender_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4814,6 +4814,9 @@ func TestProxyTracing(t *testing.T) {
kvserver.ExpirationLeasesOnly.Override(ctx, &st.SV, true)
kvserver.RangefeedEnabled.Override(ctx, &st.SV, true)
kvserver.RangeFeedRefreshInterval.Override(ctx, &st.SV, 10*time.Millisecond)
// Disable follower reads to ensure that the request is proxied, and not
// answered locally due to follower reads.
kvserver.FollowerReadsEnabled.Override(ctx, &st.SV, false)
closedts.TargetDuration.Override(ctx, &st.SV, 10*time.Millisecond)
closedts.SideTransportCloseInterval.Override(ctx, &st.SV, 10*time.Millisecond)

Expand Down Expand Up @@ -4883,6 +4886,22 @@ func TestProxyTracing(t *testing.T) {
return nil
}

printTrace := func() {
t.Log("started printing a trace")
rows, err := conn.QueryContext(ctx, "SELECT message, tag, location FROM [SHOW TRACE FOR SESSION]")
require.NoError(t, err)
defer rows.Close()

// Iterate over the results and print them
for rows.Next() {
var msg, tag, loc string
err := rows.Scan(&msg, &tag, &loc)
require.NoError(t, err)
t.Logf("msg: %s, tag: %s, loc: %s", msg, tag, loc)
}
require.NoError(t, rows.Err())
}

// Wait until the leaseholder for the test table ranges are on n3.
testutils.SucceedsSoon(t, func() error {
return checkLeaseCount(3, numRanges)
Expand All @@ -4907,6 +4926,10 @@ func TestProxyTracing(t *testing.T) {
AND location LIKE '%server/node%'
AND tag LIKE '%n2%'`,
).Scan(&msg, &tag, &loc); err != nil {
// If we fail for any reason, print the trace to help debugging.
printTrace()
// Make sure that node 3 still holds the leases.
require.NoError(t, checkLeaseCount(3, numRanges))
if errors.Is(err, gosql.ErrNoRows) {
t.Fatalf("request succeeded without proxying")
}
Expand Down