Skip to content

Commit 8b550fa

Browse files
craig[bot]miraradevakyle-a-wong
committed
154265: kvserver: more logging for TestReplicaCircuitBreaker_Partial_Retry r=tbg a=miraradeva This test verifies the value of the `InLeaseTransferBackoffs` metric, but without more verbose `DistSender` logging, it's hard to investigate failures where the metric has unexpected values. Fixes: #154179 Release note: None 154267: sql,unsafesql,sessiondata: do not log unsafe access logs for internal app names r=kyle-a-wong a=kyle-a-wong If the app name of a session is an internal app name, we won't do any checks on internals access. An app name is considered to be an internal app name if it begins with "$ internal" Resolves: #153803 Epic: None Release note: None Co-authored-by: Mira Radeva <[email protected]> Co-authored-by: Kyle Wong <[email protected]>
3 parents a49ffd8 + 635a56f + 8e1e6f2 commit 8b550fa

File tree

6 files changed

+27
-5
lines changed

6 files changed

+27
-5
lines changed

pkg/kv/kvserver/client_replica_circuit_breaker_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,11 @@ func TestReplicaCircuitBreaker_Partial_Retry(t *testing.T) {
793793
skip.UnderRace(t)
794794
skip.UnderDeadlock(t)
795795

796+
// To help debug issues like #154179.
797+
prevVModule := log.GetVModule()
798+
defer func() { _ = log.SetVModule(prevVModule) }()
799+
require.NoError(t, log.SetVModule("dist_sender=3"))
800+
796801
testutils.RunValues(t, "lease-type", roachpb.ExpirationAndLeaderLeaseType(),
797802
func(t *testing.T, leaseType roachpb.LeaseType) {
798803
// Use a context timeout, to prevent test hangs on failures.

pkg/sql/conn_executor.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ func (s *Server) SetupConn(
920920
// to use the InternalMetrics. However, some external connections use the prefix as well, for example
921921
// the debug zip cli tool.
922922
metrics := &s.Metrics
923-
if strings.HasPrefix(sd.ApplicationName, catconstants.InternalAppNamePrefix) {
923+
if sd.IsInternalAppName() {
924924
metrics = &s.InternalMetrics
925925
}
926926

@@ -1255,7 +1255,6 @@ func (s *Server) newConnExecutor(
12551255
}
12561256

12571257
ex.applicationName.Store(ex.sessionData().ApplicationName)
1258-
12591258
ex.applicationStats = applicationStats
12601259
// We ignore statements and transactions run by the internal executor by
12611260
// passing a nil writer.

pkg/sql/sessiondata/session_data.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
"net"
1010
"reflect"
1111
"strconv"
12+
"strings"
1213
"time"
1314

1415
"github.com/cockroachdb/cockroach/pkg/security/username"
16+
"github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants"
1517
"github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb"
1618
"github.com/cockroachdb/cockroach/pkg/util/duration"
1719
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
@@ -154,6 +156,10 @@ func (s *SessionData) SessionUser() username.SQLUsername {
154156
return s.SessionUserProto.Decode()
155157
}
156158

159+
func (s *SessionData) IsInternalAppName() bool {
160+
return strings.HasPrefix(s.ApplicationName, catconstants.InternalAppNamePrefix)
161+
}
162+
157163
// LocalUnmigratableSessionData contains session parameters that cannot
158164
// be propagated to remote nodes and cannot be migrated to another
159165
// session.

pkg/sql/unsafesql/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ go_test(
2929
"//pkg/sql/isql",
3030
"//pkg/sql/sqlerrors",
3131
"//pkg/testutils/serverutils",
32+
"//pkg/testutils/sqlutils",
3233
"//pkg/util/leaktest",
3334
"//pkg/util/log",
3435
"//pkg/util/log/eventpb",

pkg/sql/unsafesql/unsafesql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func CheckInternalsAccess(
4949
sv *settings.Values,
5050
) error {
5151
// If the querier is internal, we should allow it.
52-
if sd.Internal {
52+
if sd.Internal || sd.IsInternalAppName() {
5353
return nil
5454
}
5555

pkg/sql/unsafesql/unsafesql_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/cockroachdb/cockroach/pkg/sql/sqlerrors"
2121
"github.com/cockroachdb/cockroach/pkg/sql/unsafesql"
2222
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
23+
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
2324
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
2425
"github.com/cockroachdb/cockroach/pkg/util/log"
2526
"github.com/cockroachdb/cockroach/pkg/util/log/eventpb"
@@ -67,12 +68,12 @@ func TestAccessCheckServer(t *testing.T) {
6768
pool := s.SQLConn(t)
6869
defer pool.Close()
6970

71+
runner := sqlutils.MakeSQLRunner(pool)
7072
// override the log limiter so that the tests can run without pauses.
7173
defer unsafesql.TestRemoveLimiters()()
7274

7375
// create a user table to test user table access.
74-
_, err := pool.Exec("CREATE TABLE foo (id INT PRIMARY KEY)")
75-
require.NoError(t, err)
76+
runner.Exec(t, "CREATE TABLE foo (id INT PRIMARY KEY)")
7677

7778
// create and register a log accessedSpy to see the unsafe access logs
7879
accessedSpy := logtestutils.NewStructuredLogSpy[eventpb.UnsafeInternalsAccessed](
@@ -119,6 +120,7 @@ func TestAccessCheckServer(t *testing.T) {
119120

120121
for _, test := range []struct {
121122
Query string
123+
AppName string
122124
Internal bool
123125
AllowUnsafeInternals bool
124126
Passes bool
@@ -157,6 +159,14 @@ func TestAccessCheckServer(t *testing.T) {
157159
Passes: true,
158160
LogsAccessed: true,
159161
},
162+
{
163+
Query: "SELECT * FROM system.namespace",
164+
AppName: "$ internal app",
165+
Internal: false,
166+
AllowUnsafeInternals: false,
167+
Passes: true,
168+
LogsAccessed: false,
169+
},
160170
// Tests on unsupported crdb_internal objects.
161171
{
162172
Query: "SELECT * FROM crdb_internal.gossip_alerts",
@@ -223,6 +233,7 @@ func TestAccessCheckServer(t *testing.T) {
223233
t.Run(fmt.Sprintf("query=%s,internal=%t,allowUnsafe=%t", test.Query, test.Internal, test.AllowUnsafeInternals), func(t *testing.T) {
224234
accessedSpy.Reset()
225235
deniedSpy.Reset()
236+
runner.Exec(t, "SET application_name = $1", test.AppName)
226237
err := sendQuery(test.AllowUnsafeInternals, test.Internal, test.Query)
227238
if test.Passes {
228239
require.NoError(t, err)

0 commit comments

Comments
 (0)