Skip to content

Commit

Permalink
Merge pull request #136108 from iskettaneh/backport24.3.0-rc-135846
Browse files Browse the repository at this point in the history
release-24.3.0-rc: kv: print traced query when failing the TestProxyTracing
  • Loading branch information
iskettaneh authored Nov 25, 2024
2 parents ef2ebe9 + c43cf5f commit 330209c
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion pkg/kv/kvclient/kvcoord/dist_sender_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4829,6 +4829,8 @@ func TestProxyTracing(t *testing.T) {
st := cluster.MakeTestingClusterSettings()
switch leaseType {
case roachpb.LeaseExpiration:
skip.UnderRace(t, "too slow")
skip.UnderDeadlock(t, "too slow")
kvserver.ExpirationLeasesOnly.Override(ctx, &st.SV, true)
case roachpb.LeaseEpoch:
// With epoch leases this test doesn't work reliably. It passes
Expand All @@ -4845,6 +4847,9 @@ func TestProxyTracing(t *testing.T) {
}
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 @@ -4914,6 +4919,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 @@ -4923,7 +4944,6 @@ func TestProxyTracing(t *testing.T) {

_, err = conn.Exec("SET TRACING = on; SELECT FROM t where i = 987654321; SET TRACING = off")
require.NoError(t, err)

// Expect the "proxy request complete" message to be in the trace and that it
// comes from the proxy node n2.
var msg, tag, loc string
Expand All @@ -4933,6 +4953,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

0 comments on commit 330209c

Please sign in to comment.