Skip to content

Commit

Permalink
kvcoord: print traced query when failing the TestProxyTracing
Browse files Browse the repository at this point in the history
This commit prints the traced query when TestProxyTracing test fails.
This should help with debugging the failures.

References: #135493

Release note: None
  • Loading branch information
iskettaneh committed Nov 22, 2024
1 parent 08fe400 commit ed7b369
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions pkg/kv/kvclient/kvcoord/dist_sender_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4886,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 @@ -4905,11 +4921,15 @@ func TestProxyTracing(t *testing.T) {
// comes from the proxy node n2.
var msg, tag, loc string
if err = conn.QueryRowContext(ctx, `SELECT message, tag, location
FROM [SHOW TRACE FOR SESSION]
WHERE message LIKE '%proxy request complete%'
AND location LIKE '%server/node%'
AND tag LIKE '%n2%'`,
FROM [SHOW TRACE FOR SESSION]
WHERE message LIKE '%proxy request complete%'
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

0 comments on commit ed7b369

Please sign in to comment.