Skip to content

Commit

Permalink
*: additional test for redact log and a fix (#52359)
Browse files Browse the repository at this point in the history
close #52364
  • Loading branch information
xhebox committed Apr 7, 2024
1 parent d2eb902 commit 8f985c7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func initFlagSet() *flag.FlagSet {
func main() {
fset := initFlagSet()
if args := fset.Args(); len(args) != 0 {
if args[0] == "collect-logs" && len(args) > 1 {
if args[0] == "collect-log" && len(args) > 1 {
output := "-"
if len(args) > 2 {
output = args[2]
Expand Down
7 changes: 3 additions & 4 deletions pkg/server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ import (
"github.com/pingcap/tidb/pkg/util/hack"
"github.com/pingcap/tidb/pkg/util/intest"
"github.com/pingcap/tidb/pkg/util/logutil"
"github.com/pingcap/tidb/pkg/util/redact"
"github.com/pingcap/tidb/pkg/util/resourcegrouptag"
tlsutil "github.com/pingcap/tidb/pkg/util/tls"
"github.com/pingcap/tidb/pkg/util/topsql"
Expand Down Expand Up @@ -1164,11 +1163,11 @@ func (cc *clientConn) Run(ctx context.Context) {
}

func errStrForLog(err error, redactMode string) string {
if redactMode == errors.RedactLogEnable {
if redactMode != errors.RedactLogDisable {
// currently, only ErrParse is considered when enableRedactLog because it may contain sensitive information like
// password or accesskey
if parser.ErrParse.Equal(err) {
return "fail to parse SQL and can't redact when enable log redaction"
return "fail to parse SQL, and must redact the whole error when enable log redaction"
}
}
var ret string
Expand All @@ -1178,7 +1177,7 @@ func errStrForLog(err error, redactMode string) string {
} else {
ret = errors.ErrorStack(err)
}
return redact.String(redactMode, ret)
return ret
}

func (cc *clientConn) addMetrics(cmd byte, startTime time.Time, err error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ func (s *session) handleAssertionFailure(ctx context.Context, err error) error {
}
if store, ok := s.store.(helper.Storage); ok {
content := consistency.GetMvccByKey(store, key, decodeFunc)
logutil.Logger(ctx).Error("assertion failed", zap.String("message", redact.String(rmode, newErr.Error())), zap.String("mvcc history", redact.String(rmode, content)))
logutil.Logger(ctx).Error("assertion failed", zap.String("message", newErr.Error()), zap.String("mvcc history", redact.String(rmode, content)))
}
return newErr
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/table/tables/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,14 @@ func TestTxnAssertion(t *testing.T) {
err = tk.ExecToErr("insert into t values (?, 10, 100, 1000, '10000')", id1)
expectAssertionErr(level, err)
})

tk.MustExec("set @@tidb_redact_log=MARKER")
withFailpoint(fpAdd, func() {
err = tk.ExecToErr("insert into t values (?, 10, 100, 1000, '10000')", id1)
require.Contains(t, err.Error(), "‹")
})
tk.MustExec("set @@tidb_redact_log=0")

withFailpoint(fpUpdate, func() {
err = tk.ExecToErr("update t set v = v + 1 where id = ?", id2)
expectAssertionErr(level, err)
Expand Down

0 comments on commit 8f985c7

Please sign in to comment.