Skip to content

Commit

Permalink
Merge pull request #84861 from THardy98/backport21.2-84452
Browse files Browse the repository at this point in the history
release-21.2: sql: add troubleshooting mode session variable
  • Loading branch information
Thomas Hardy authored Jul 22, 2022
2 parents 0009dbf + 0845ca6 commit d35bf4d
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 68 deletions.
12 changes: 12 additions & 0 deletions pkg/cli/clisqlcfg/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 6 additions & 0 deletions pkg/cli/interactive_tests/test_client_side_checking.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/exec_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
174 changes: 107 additions & 67 deletions pkg/sql/sessiondatapb/session_data.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/sql/sessiondatapb/session_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit d35bf4d

Please sign in to comment.