diff --git a/pkg/cli/clisqlcfg/context.go b/pkg/cli/clisqlcfg/context.go index 76a640b0ddc7..eb60e2bc5f16 100644 --- a/pkg/cli/clisqlcfg/context.go +++ b/pkg/cli/clisqlcfg/context.go @@ -204,6 +204,18 @@ func (c *Context) Run(conn clisqlclient.Conn) error { } } + if err := c.maybeSetTroubleshootingMode(conn); err != nil { + return err + } + shell := clisqlshell.NewShell(c.CliCtx, c.ConnCtx, c.ExecCtx, &c.ShellCtx, conn) return shell.RunInteractive(c.cmdIn, c.CmdOut, c.CmdErr) } + +func (c *Context) maybeSetTroubleshootingMode(conn clisqlclient.Conn) error { + if !c.ConnCtx.DebugMode { + return nil + } + // If we are in debug mode, enable "troubleshooting mode". + return conn.Exec("SET troubleshooting_mode = on", nil) +} diff --git a/pkg/cli/interactive_tests/test_client_side_checking.tcl b/pkg/cli/interactive_tests/test_client_side_checking.tcl index 3f1e58b0483a..9df64c66086c 100644 --- a/pkg/cli/interactive_tests/test_client_side_checking.tcl +++ b/pkg/cli/interactive_tests/test_client_side_checking.tcl @@ -80,6 +80,12 @@ end_test start_test "Check that --debug-sql-cli sets suitable simplified client-side options." send "$argv sql --debug-sql-cli\r" eexpect "Welcome" + +# Check that troubleshooting mode is enabled in debug mode. +eexpect "root@" +send "show troubleshooting_mode;\r" +eexpect "on" + eexpect "root@" send "\\set display_format csv\r\\set\r" eexpect "check_syntax,false" diff --git a/pkg/sql/exec_log.go b/pkg/sql/exec_log.go index 570e7a617fdf..28c69aa638da 100644 --- a/pkg/sql/exec_log.go +++ b/pkg/sql/exec_log.go @@ -368,7 +368,7 @@ func (p *planner) maybeLogStatementInternal( p.logEventsOnlyExternally(ctx, eventLogEntry{event: &eventpb.AdminQuery{CommonSQLExecDetails: execDetails}}) } - if telemetryLoggingEnabled { + if telemetryLoggingEnabled && !p.SessionData().TroubleshootingMode { // We only log to the telemetry channel if enough time has elapsed from // the last event emission. requiredTimeElapsed := 1.0 / float64(maxEventFrequency) diff --git a/pkg/sql/exec_util.go b/pkg/sql/exec_util.go index 59a88cbaa384..c919b0e15520 100644 --- a/pkg/sql/exec_util.go +++ b/pkg/sql/exec_util.go @@ -2984,6 +2984,10 @@ func (m *sessionDataMutator) SetMultipleModificationsOfTable(val bool) { m.data.MultipleModificationsOfTable = val } +func (m *sessionDataMutator) SetTroubleshootingModeEnabled(val bool) { + m.data.TroubleshootingMode = val +} + // Utility functions related to scrubbing sensitive information on SQL Stats. // quantizeCounts ensures that the Count field in the diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index d869dba245d7..f569d36e1455 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -4690,6 +4690,7 @@ transaction_rows_read_log 0 transaction_rows_written_err 0 transaction_rows_written_log 0 transaction_status NoTxn +troubleshooting_mode off # information_schema can be used with the anonymous database. # It should show information across all databases. diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 545fb69e6a77..2bf54bbf4562 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -4117,6 +4117,7 @@ transaction_rows_read_log 0 NULL transaction_rows_written_err 0 NULL NULL NULL string transaction_rows_written_log 0 NULL NULL NULL string transaction_status NoTxn NULL NULL NULL string +troubleshooting_mode off NULL NULL NULL string vectorize on NULL NULL NULL string query TTTTTTT colnames @@ -4220,6 +4221,7 @@ transaction_rows_read_log 0 NULL transaction_rows_written_err 0 NULL user NULL 0 0 transaction_rows_written_log 0 NULL user NULL 0 0 transaction_status NoTxn NULL user NULL NoTxn NoTxn +troubleshooting_mode off NULL user NULL off off vectorize on NULL user NULL on on query TTTTTT colnames @@ -4321,6 +4323,7 @@ transaction_rows_read_log NULL NULL NULL transaction_rows_written_err NULL NULL NULL NULL NULL transaction_rows_written_log NULL NULL NULL NULL NULL transaction_status NULL NULL NULL NULL NULL +troubleshooting_mode NULL NULL NULL NULL NULL vectorize NULL NULL NULL NULL NULL # pg_catalog.pg_sequence diff --git a/pkg/sql/logictest/testdata/logic_test/show_source b/pkg/sql/logictest/testdata/logic_test/show_source index 7cdcb903e0fa..563453caeff1 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_source +++ b/pkg/sql/logictest/testdata/logic_test/show_source @@ -118,6 +118,7 @@ transaction_rows_read_log 0 transaction_rows_written_err 0 transaction_rows_written_log 0 transaction_status NoTxn +troubleshooting_mode off vectorize on query T colnames diff --git a/pkg/sql/sessiondatapb/session_data.pb.go b/pkg/sql/sessiondatapb/session_data.pb.go index dad8ba30c405..d418101ad768 100644 --- a/pkg/sql/sessiondatapb/session_data.pb.go +++ b/pkg/sql/sessiondatapb/session_data.pb.go @@ -157,6 +157,10 @@ type SessionData struct { // OnUpdateRehomeRowEnabled controls whether the ON UPDATE rehome_row() // will actually trigger on row updates. OnUpdateRehomeRowEnabled bool `protobuf:"varint,17,opt,name=on_update_rehome_row_enabled,json=onUpdateRehomeRowEnabled,proto3" json:"on_update_rehome_row_enabled,omitempty"` + // Troubleshooting mode determines whether we refuse to do additional work with + // the query (i.e. collect & emit telemetry data). Troubleshooting mode is + // disabled by default. + TroubleshootingMode bool `protobuf:"varint,21,opt,name=troubleshooting_mode,json=troubleshootingMode,proto3" json:"troubleshooting_mode,omitempty"` } func (m *SessionData) Reset() { *m = SessionData{} } @@ -319,73 +323,74 @@ func init() { } var fileDescriptor_9fa1c5a4e61eec38 = []byte{ - // 1041 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x54, 0x4f, 0x6f, 0x1b, 0x45, - 0x14, 0xf7, 0xc6, 0x49, 0x6a, 0x8f, 0x63, 0x67, 0x33, 0x4d, 0xab, 0x25, 0x0d, 0x6b, 0x13, 0x21, - 0xe4, 0x46, 0x68, 0x0d, 0xa1, 0xe2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33, 0xa0, 0x03, 0x83, 0xc1, 0x4d, 0x64, 0x87, 0xd0, 0xa3, 0xa3, 0x48, 0x11, 0xc6, - 0x15, 0x91, 0xec, 0x1c, 0x9c, 0x7b, 0x0d, 0xab, 0xb9, 0xe0, 0xd7, 0x32, 0xff, 0x1e, 0x57, 0x1d, - 0x76, 0x0e, 0x5a, 0xe0, 0x48, 0x8c, 0x95, 0x72, 0x4a, 0x63, 0x81, 0x27, 0x36, 0xae, 0xa3, 0x8a, - 0x04, 0x9a, 0x06, 0x03, 0x92, 0x50, 0x35, 0x70, 0xca, 0x8d, 0x62, 0xb3, 0xec, 0xa3, 0xb1, 0xeb, - 0x80, 0xaa, 0x01, 0xde, 0x42, 0x0f, 0x14, 0xc4, 0x89, 0x48, 0x69, 0x7a, 0x46, 0x64, 0x30, 0x80, - 0x98, 0x8e, 0x9f, 0x01, 0x32, 0x99, 0xee, 0xe7, 0xc1, 0x8e, 0x89, 0x99, 0xa7, 0xb0, 0x8f, 0xca, - 0x12, 0x86, 0x44, 0x2a, 0xaa, 0xc0, 0xa9, 0x18, 0x69, 0x36, 0xef, 0xec, 0x59, 0x07, 0x86, 0x23, - 0xe0, 0x01, 0x74, 0x34, 0x23, 0xd3, 0xa4, 0x24, 0x61, 0x68, 0x6c, 0xbc, 0x81, 0x96, 0xbe, 0x15, - 0xe9, 0xd1, 0x3e, 0xc4, 0xcf, 0x59, 0xcc, 0x94, 0xb3, 0xd4, 0xb0, 0x9a, 0x45, 0x7f, 0xc6, 0x87, - 0x9f, 0xa0, 0x87, 0x8c, 0x2b, 0x48, 0x8f, 0x69, 0x44, 0xa4, 0x3a, 0x8b, 0x80, 0x00, 0xa7, 0xdd, - 0x08, 0x42, 0xa7, 0x6a, 0x7a, 0xb9, 0x3a, 0x89, 0x76, 0x74, 0x70, 0x67, 0x1c, 0xc3, 0x1f, 0x23, - 0xac, 0xc7, 0xe9, 0x16, 0xa3, 0x66, 0x18, 0xb6, 0x8e, 0xcc, 0xa0, 0x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6e, 0xcf, 0xe1, 0x3a, 0x7a, 0x74, 0x83, 0x99, 0x40, 0xca, - 0xf4, 0xbf, 0xd3, 0xe8, 0x8b, 0xe8, 0x84, 0x9e, 0x49, 0xbb, 0x88, 0x6d, 0xb4, 0x34, 0x65, 0xf4, - 0x7a, 0xf6, 0xfc, 0xf4, 0xda, 0x8d, 0xf9, 0x92, 0x65, 0x5b, 0xed, 0xd6, 0xc5, 0xbf, 0x6e, 0xe1, - 0xe2, 0xca, 0xb5, 0x5e, 0x5d, 0xb9, 0xd6, 0xeb, 0x2b, 0xd7, 0xfa, 0xe7, 0xca, 0xb5, 0x7e, 0xbe, - 0x76, 0x0b, 0xaf, 0xae, 0xdd, 0xc2, 0xeb, 0x6b, 0xb7, 0xf0, 0x5d, 0x75, 0x46, 0xa0, 0xee, 0xa2, - 0x19, 0xd5, 0xcf, 0xfe, 0x0f, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x22, 0x3c, 0x01, 0xc4, 0x07, 0x00, - 0x00, + // 1063 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x54, 0x4f, 0x6f, 0xe3, 0x44, + 0x14, 0x8f, 0x9b, 0xb6, 0x24, 0x93, 0x26, 0x75, 0xa7, 0xe9, 0xca, 0x74, 0x8b, 0x13, 0x2a, 0x84, + 0xb2, 0x15, 0x72, 0xd8, 0xb2, 0xe2, 0xb8, 0x12, 0xd9, 0xb6, 0xa2, 0xd2, 0x76, 0x29, 0x0e, 0x5d, + 0x24, 0x0e, 0x8c, 0x26, 0xf6, 0x4b, 0x32, 0xd4, 0xf6, 0x38, 0x9e, 0x71, 0xff, 0xf1, 0x05, 0xb8, + 0x20, 0x71, 0xe4, 0x0e, 0x07, 0xbe, 0x07, 0x97, 0x5e, 0x90, 0xf6, 0xb8, 0xa7, 0x02, 0xed, 0xb7, + 0xe0, 0x84, 0x66, 0x92, 0x38, 0x7f, 0x76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, 0xd9, 0xb7, 0x8a, 0xf5, 0x7c, 0xa3, 0xe8, 0xa2, 0xa1, 0xea, 0x98, + 0xca, 0x3e, 0xde, 0x45, 0x1b, 0x12, 0xc2, 0x98, 0x27, 0x34, 0xb9, 0x24, 0xc2, 0xeb, 0x43, 0x48, + 0x87, 0x63, 0x80, 0xb4, 0xa7, 0xf5, 0xcc, 0xd8, 0xd6, 0x36, 0x3d, 0x0a, 0x47, 0xa8, 0x28, 0x60, + 0x40, 0x84, 0xa4, 0x12, 0xac, 0x92, 0x6e, 0xcd, 0xce, 0xbd, 0x35, 0x6b, 0xc3, 0x20, 0x85, 0xc8, + 0x83, 0xb6, 0x62, 0x8c, 0x7a, 0x52, 0x10, 0x30, 0xd0, 0x32, 0xde, 0x46, 0x2b, 0xdf, 0xf2, 0xe4, + 0xf4, 0x08, 0xc2, 0xe7, 0x2c, 0x64, 0xd2, 0x5a, 0xa9, 0x1b, 0x8d, 0xbc, 0x3b, 0xa3, 0xc3, 0x4f, + 0xd0, 0x03, 0x16, 0x49, 0x48, 0xce, 0x68, 0x40, 0x84, 0xbc, 0x0c, 0x80, 0x40, 0x44, 0x3b, 0x01, + 0xf8, 0x56, 0x59, 0xd7, 0xb2, 0x3a, 0xb6, 0xb6, 0x95, 0x71, 0x7f, 0x68, 0xc3, 0x9f, 0x20, 0xac, + 0xd6, 0x69, 0x8e, 0x51, 0xd1, 0x0c, 0x53, 0x59, 0x66, 0xd0, 0x07, 0x68, 0x25, 0xe0, 0xde, 0x29, + 0x51, 0x3b, 0xc9, 0x53, 0x69, 0xad, 0xea, 0x3f, 0x7b, 0xdf, 0x19, 0xee, 0x9b, 0x33, 0xde, 0x37, + 0x67, 0x6f, 0xb4, 0x6f, 0xad, 0x82, 0xfa, 0x91, 0x5f, 0xff, 0xae, 0x19, 0x6e, 0x49, 0x11, 0xbf, + 0x19, 0xf2, 0x54, 0x3f, 0x74, 0x36, 0x11, 0x0d, 0x2c, 0x53, 0xc7, 0xca, 0x64, 0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x38, 0x09, 0xbb, 0xbd, 0x58, 0x30, 0x4c, 0xa3, + 0xd5, 0xbc, 0xfe, 0xd7, 0xce, 0x5d, 0xdf, 0xda, 0xc6, 0xab, 0x5b, 0xdb, 0x78, 0x7d, 0x6b, 0x1b, + 0xff, 0xdc, 0xda, 0xc6, 0x2f, 0x77, 0x76, 0xee, 0xd5, 0x9d, 0x9d, 0x7b, 0x7d, 0x67, 0xe7, 0xbe, + 0x2b, 0xcf, 0x34, 0xa8, 0xb3, 0xac, 0xb7, 0xfb, 0xb3, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0x37, + 0x73, 0x75, 0xd6, 0xf7, 0x07, 0x00, 0x00, } func (m *SessionData) Marshal() (dAtA []byte, err error) { @@ -408,6 +413,18 @@ func (m *SessionData) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.TroubleshootingMode { + i-- + if m.TroubleshootingMode { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa8 + } if m.OnUpdateRehomeRowEnabled { i-- if m.OnUpdateRehomeRowEnabled { @@ -748,6 +765,9 @@ func (m *SessionData) Size() (n int) { if m.OnUpdateRehomeRowEnabled { n += 3 } + if m.TroubleshootingMode { + n += 3 + } return n } @@ -1287,6 +1307,26 @@ func (m *SessionData) Unmarshal(dAtA []byte) error { } } m.OnUpdateRehomeRowEnabled = bool(v != 0) + case 21: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TroubleshootingMode", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSessionData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.TroubleshootingMode = bool(v != 0) default: iNdEx = preIndex skippy, err := skipSessionData(dAtA[iNdEx:]) diff --git a/pkg/sql/sessiondatapb/session_data.proto b/pkg/sql/sessiondatapb/session_data.proto index 342b9b368bf9..6665b12b78e4 100644 --- a/pkg/sql/sessiondatapb/session_data.proto +++ b/pkg/sql/sessiondatapb/session_data.proto @@ -79,6 +79,11 @@ message SessionData { // OnUpdateRehomeRowEnabled controls whether the ON UPDATE rehome_row() // will actually trigger on row updates. bool on_update_rehome_row_enabled = 17; + + // Troubleshooting mode determines whether we refuse to do additional work with + // the query (i.e. collect & emit telemetry data). Troubleshooting mode is + // disabled by default. + bool troubleshooting_mode = 21; } // DataConversionConfig contains the parameters that influence the output diff --git a/pkg/sql/telemetry_logging_test.go b/pkg/sql/telemetry_logging_test.go index 481f890fe449..bfcb930689a1 100644 --- a/pkg/sql/telemetry_logging_test.go +++ b/pkg/sql/telemetry_logging_test.go @@ -279,3 +279,112 @@ func TestTelemetryLogging(t *testing.T) { } } } + +func TestNoTelemetryLogOnTroubleshootMode(t *testing.T) { + defer leaktest.AfterTest(t)() + sc := log.ScopeWithoutShowLogs(t) + defer sc.Close(t) + + cleanup := installTelemetryLogFileSink(sc, t) + defer cleanup() + + st := stubTime{} + + s, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{ + Knobs: base.TestingKnobs{ + TelemetryLoggingKnobs: &TelemetryLoggingTestingKnobs{ + getTimeNow: st.TimeNow, + }, + }, + }) + db := sqlutils.MakeSQLRunner(sqlDB) + defer s.Stopper().Stop(context.Background()) + + db.Exec(t, `SET CLUSTER SETTING sql.telemetry.query_sampling.enabled = true;`) + db.Exec(t, "CREATE TABLE t();") + + stubMaxEventFrequency := int64(1) + telemetryMaxEventFrequency.Override(context.Background(), &s.ClusterSettings().SV, stubMaxEventFrequency) + + /* + Testing Cases: + - run query when troubleshoot mode is enabled + - ensure no log appears + - run another query when troubleshoot mode is disabled + - ensure log appears + */ + testData := []struct { + name string + query string + expectedLogStatement string + enableTroubleshootingMode bool + expectedNumLogs int + }{ + { + "select-troubleshooting-enabled", + "SELECT * FROM t LIMIT 1;", + `SELECT * FROM \"\".\"\".t LIMIT ‹1›`, + true, + 0, + }, + { + "select-troubleshooting-disabled", + "SELECT * FROM t LIMIT 2;", + `SELECT * FROM \"\".\"\".t LIMIT ‹2›`, + false, + 1, + }, + } + + for idx, tc := range testData { + // Set the time for when we issue a query to enable/disable + // troubleshooting mode. + setTroubleshootModeTime := timeutil.FromUnixMicros(int64(idx * 1e6)) + st.setTime(setTroubleshootModeTime) + if tc.enableTroubleshootingMode { + db.Exec(t, `SET troubleshooting_mode = true;`) + } else { + db.Exec(t, `SET troubleshooting_mode = false;`) + } + // Advance time 1 second from previous query. Ensure enough time has passed + // from when we set troubleshooting mode for this query to be sampled. + setQueryTime := timeutil.FromUnixMicros(int64((idx + 1) * 1e6)) + st.setTime(setQueryTime) + db.Exec(t, tc.query) + } + + log.Flush() + + entries, err := log.FetchEntriesFromFiles( + 0, + math.MaxInt64, + 10000, + regexp.MustCompile(`"EventType":"sampled_query"`), + log.WithMarkedSensitiveData, + ) + + if err != nil { + t.Fatal(err) + } + + if len(entries) == 0 { + t.Fatal(errors.Newf("no entries found")) + } + + for _, tc := range testData { + numLogsFound := 0 + for i := len(entries) - 1; i >= 0; i-- { + e := entries[i] + if strings.Contains(e.Message, tc.expectedLogStatement) { + if tc.enableTroubleshootingMode { + t.Errorf("%s: unexpected log entry when troubleshooting mode enabled:\n%s", tc.name, entries[0].Message) + } else { + numLogsFound++ + } + } + } + if numLogsFound != tc.expectedNumLogs { + t.Errorf("%s: expected %d log entries, found %d", tc.name, tc.expectedNumLogs, numLogsFound) + } + } +} diff --git a/pkg/sql/vars.go b/pkg/sql/vars.go index ff3a00645577..6ec6a8f31755 100644 --- a/pkg/sql/vars.go +++ b/pkg/sql/vars.go @@ -1130,6 +1130,23 @@ var varGen = map[string]sessionVar{ // See https://www.postgresql.org/docs/10/static/runtime-config-preset.html#GUC-SERVER-VERSION-NUM `server_version_num`: makeReadOnlyVar(PgServerVersionNum), + // CockroachDB extension. + `troubleshooting_mode`: { + GetStringVal: makePostgresBoolGetStringValFn(`troubleshooting_mode`), + Set: func(_ context.Context, m sessionDataMutator, s string) error { + b, err := paramparse.ParseBoolVar("troubleshooting_mode", s) + if err != nil { + return err + } + m.SetTroubleshootingModeEnabled(b) + return nil + }, + Get: func(evalCtx *extendedEvalContext) string { + return formatBoolAsPostgresSetting(evalCtx.SessionData().TroubleshootingMode) + }, + GlobalDefault: globalFalse, + }, + // This is read-only in Postgres also. // See https://www.postgresql.org/docs/14/sql-show.html and // https://www.postgresql.org/docs/14/locale.html