Skip to content

Commit 15947c1

Browse files
authored
logutil: adapt new redact functions (#51642)
close #51310, close #51641
1 parent ccbab5e commit 15947c1

File tree

18 files changed

+117
-98
lines changed

18 files changed

+117
-98
lines changed

DEPS.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5806,13 +5806,13 @@ def go_deps():
58065806
name = "com_github_pingcap_errors",
58075807
build_file_proto_mode = "disable_global",
58085808
importpath = "github.com/pingcap/errors",
5809-
sha256 = "b4db3d3c222d9039c84baacbbd9c46aa0346f3f04d2577a77475a64ecfefebf9",
5810-
strip_prefix = "github.com/pingcap/[email protected].20231212100244-799fae176cfb",
5809+
sha256 = "0edb07dbd73a90f97e06e11e54b270d64d5cabe6142025682d840fe302087b23",
5810+
strip_prefix = "github.com/pingcap/[email protected].20240311024730-e056997136bb",
58115811
urls = [
5812-
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20231212100244-799fae176cfb.zip",
5813-
"http://ats.apps.svc/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20231212100244-799fae176cfb.zip",
5814-
"https://cache.hawkingrei.com/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20231212100244-799fae176cfb.zip",
5815-
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20231212100244-799fae176cfb.zip",
5812+
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20240311024730-e056997136bb.zip",
5813+
"http://ats.apps.svc/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20240311024730-e056997136bb.zip",
5814+
"https://cache.hawkingrei.com/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20240311024730-e056997136bb.zip",
5815+
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20240311024730-e056997136bb.zip",
58165816
],
58175817
)
58185818
go_repository(

br/pkg/redact/redact.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ import (
1111

1212
// InitRedact inits the enableRedactLog
1313
func InitRedact(redactLog bool) {
14-
errors.RedactLogEnabled.Store(redactLog)
14+
mode := errors.RedactLogDisable
15+
if redactLog {
16+
mode = errors.RedactLogEnable
17+
}
18+
errors.RedactLogEnabled.Store(mode)
1519
}
1620

1721
// NeedRedact returns whether to redact log
1822
func NeedRedact() bool {
19-
return errors.RedactLogEnabled.Load()
23+
mode := errors.RedactLogEnabled.Load()
24+
return mode != errors.RedactLogDisable && mode != ""
2025
}
2126

2227
// String receives string argument and return omitted information if redact log enabled

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ require (
8181
github.com/otiai10/copy v1.2.0
8282
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
8383
github.com/pingcap/badger v1.5.1-0.20230103063557-828f39b09b6d
84-
github.com/pingcap/errors v0.11.5-0.20231212100244-799fae176cfb
84+
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb
8585
github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c
8686
github.com/pingcap/fn v1.0.0
8787
github.com/pingcap/kvproto v0.0.0-20240208102409-a554af8ee11f

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,8 @@ github.com/pingcap/badger v1.5.1-0.20230103063557-828f39b09b6d/go.mod h1:p8QnkZn
706706
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
707707
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
708708
github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
709-
github.com/pingcap/errors v0.11.5-0.20231212100244-799fae176cfb h1:yqyP+k0mgRPpXJQDOCrtaG2YZym0ZDD+vt5JzlBUkrw=
710-
github.com/pingcap/errors v0.11.5-0.20231212100244-799fae176cfb/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
709+
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb h1:3pSi4EDG6hg0orE1ndHkXvX6Qdq2cZn8gAPir8ymKZk=
710+
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
711711
github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c h1:CgbKAHto5CQgWM9fSBIvaxsJHuGP0uM74HXtv3MyyGQ=
712712
github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c/go.mod h1:4qGtCB0QK0wBzKtFEGDhxXnSnbQApw1gc9siScUl8ew=
713713
github.com/pingcap/fn v1.0.0 h1:CyA6AxcOZkQh52wIqYlAmaVmF6EvrcqFywP463pjA8g=

pkg/executor/set_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,10 @@ func TestSetVar(t *testing.T) {
464464
tk.MustQuery(`select @@session.tidb_redact_log;`).Check(testkit.Rows("ON"))
465465
tk.MustExec("set session tidb_redact_log = oFf")
466466
tk.MustQuery(`select @@session.tidb_redact_log;`).Check(testkit.Rows("OFF"))
467-
tk.MustExec("set session tidb_redact_log = On")
468-
tk.MustQuery(`select @@session.tidb_redact_log;`).Check(testkit.Rows("ON"))
469467
tk.MustExec("set session tidb_redact_log = marker")
470468
tk.MustQuery(`select @@session.tidb_redact_log;`).Check(testkit.Rows("MARKER"))
469+
tk.MustExec("set session tidb_redact_log = On")
470+
tk.MustQuery(`select @@session.tidb_redact_log;`).Check(testkit.Rows("ON"))
471471

472472
tk.MustQuery("select @@tidb_dml_batch_size;").Check(testkit.Rows("0"))
473473
tk.MustExec("set @@session.tidb_dml_batch_size = 120")

pkg/executor/test/admintest/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ go_test(
3030
"//pkg/util/logutil",
3131
"//pkg/util/logutil/consistency",
3232
"//pkg/util/mock",
33+
"//pkg/util/redact",
3334
"@com_github_pingcap_errors//:errors",
3435
"@com_github_stretchr_testify//require",
3536
"@com_github_tikv_client_go_v2//tikv",

pkg/executor/test/admintest/admin_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"github.com/pingcap/tidb/pkg/util/logutil"
4242
"github.com/pingcap/tidb/pkg/util/logutil/consistency"
4343
"github.com/pingcap/tidb/pkg/util/mock"
44+
"github.com/pingcap/tidb/pkg/util/redact"
4445
"github.com/stretchr/testify/require"
4546
"go.uber.org/zap"
4647
)
@@ -1055,6 +1056,8 @@ func TestCheckFailReport(t *testing.T) {
10551056
store := testkit.CreateMockStore(t)
10561057
tk := newInconsistencyKit(t, testkit.NewAsyncTestKit(t, store), newDefaultOpt())
10571058

1059+
rmode := tk.sctx.GetSessionVars().EnableRedactNew
1060+
10581061
// row more than unique index
10591062
func() {
10601063
defer tk.rebuild()
@@ -1072,7 +1075,7 @@ func TestCheckFailReport(t *testing.T) {
10721075
hook.Logs[0].CheckField(t,
10731076
zap.String("table_name", "admin_test"),
10741077
zap.String("index_name", "uk1"),
1075-
zap.Stringer("row_id", kv.IntHandle(1)),
1078+
zap.Stringer("row_id", redact.Stringer(rmode, kv.IntHandle(1))),
10761079
)
10771080
hook.Logs[0].CheckFieldNotEmpty(t, "row_mvcc")
10781081
}()
@@ -1094,7 +1097,7 @@ func TestCheckFailReport(t *testing.T) {
10941097
hook.Logs[0].CheckField(t,
10951098
zap.String("table_name", "admin_test"),
10961099
zap.String("index_name", "k2"),
1097-
zap.Stringer("row_id", kv.IntHandle(1)),
1100+
zap.Stringer("row_id", redact.Stringer(rmode, kv.IntHandle(1))),
10981101
)
10991102
hook.Logs[0].CheckFieldNotEmpty(t, "row_mvcc")
11001103
}()
@@ -1118,7 +1121,7 @@ func TestCheckFailReport(t *testing.T) {
11181121
logEntry.CheckField(t,
11191122
zap.String("table_name", "admin_test"),
11201123
zap.String("index_name", "k2"),
1121-
zap.Stringer("row_id", kv.IntHandle(1)),
1124+
zap.Stringer("row_id", redact.Stringer(rmode, kv.IntHandle(1))),
11221125
)
11231126
logEntry.CheckFieldNotEmpty(t, "row_mvcc")
11241127
logEntry.CheckFieldNotEmpty(t, "index_mvcc")
@@ -1162,7 +1165,7 @@ func TestCheckFailReport(t *testing.T) {
11621165
logEntry.CheckField(t,
11631166
zap.String("table_name", "admin_test"),
11641167
zap.String("index_name", "uk1"),
1165-
zap.Stringer("row_id", kv.IntHandle(1)),
1168+
zap.Stringer("row_id", redact.Stringer(rmode, kv.IntHandle(1))),
11661169
)
11671170
logEntry.CheckFieldNotEmpty(t, "row_mvcc")
11681171
logEntry.CheckFieldNotEmpty(t, "index_mvcc")
@@ -1205,7 +1208,7 @@ func TestCheckFailReport(t *testing.T) {
12051208
logEntry.CheckField(t,
12061209
zap.String("table_name", "admin_test"),
12071210
zap.String("index_name", "uk1"),
1208-
zap.Stringer("row_id", kv.IntHandle(1)),
1211+
zap.Stringer("row_id", redact.Stringer(rmode, kv.IntHandle(1))),
12091212
)
12101213
logEntry.CheckFieldNotEmpty(t, "row_mvcc")
12111214
logEntry.CheckFieldNotEmpty(t, "index_mvcc")
@@ -1231,7 +1234,7 @@ func TestCheckFailReport(t *testing.T) {
12311234
logEntry.CheckField(t,
12321235
zap.String("table_name", "admin_test"),
12331236
zap.String("index_name", "k2"),
1234-
zap.Stringer("row_id", kv.IntHandle(1)),
1237+
zap.Stringer("row_id", redact.Stringer(rmode, kv.IntHandle(1))),
12351238
)
12361239
logEntry.CheckFieldNotEmpty(t, "row_mvcc")
12371240
logEntry.CheckFieldNotEmpty(t, "index_mvcc")
@@ -1271,7 +1274,7 @@ func TestCheckFailReport(t *testing.T) {
12711274
logEntry.CheckField(t,
12721275
zap.String("table_name", "admin_test"),
12731276
zap.String("index_name", "uk1"),
1274-
zap.Stringer("row_id", kv.IntHandle(282574488403969)),
1277+
zap.Stringer("row_id", redact.Stringer(rmode, kv.IntHandle(282574488403969))),
12751278
)
12761279
logEntry.CheckFieldNotEmpty(t, "row_mvcc")
12771280
logEntry.CheckFieldNotEmpty(t, "index_mvcc")

pkg/server/conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ func errStrForLog(err error, redactMode string) string {
11871187
} else {
11881188
ret = errors.ErrorStack(err)
11891189
}
1190-
return redact.Redact(redactMode, ret)
1190+
return redact.String(redactMode, ret)
11911191
}
11921192

11931193
func (cc *clientConn) addMetrics(cmd byte, startTime time.Time, err error) {

pkg/server/conn_stmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ func (cc *clientConn) preparedStmt2String(stmtID uint32) string {
583583
}
584584
sql := parser.Normalize(cc.preparedStmt2StringNoArgs(stmtID), sv.EnableRedactNew)
585585
if m := sv.EnableRedactNew; m != "ON" {
586-
sql += redact.Redact(sv.EnableRedactNew, sv.PlanCacheParams.String())
586+
sql += redact.String(sv.EnableRedactNew, sv.PlanCacheParams.String())
587587
}
588588
return sql
589589
}

pkg/session/nontransactional.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type statementBuildInfo struct {
6969
}
7070

7171
func (j job) String(redacted string) string {
72-
return fmt.Sprintf("job id: %d, estimated size: %d, sql: %s", j.jobID, j.jobSize, redact.Redact(redacted, j.sql))
72+
return fmt.Sprintf("job id: %d, estimated size: %d, sql: %s", j.jobID, j.jobSize, redact.String(redacted, j.sql))
7373
}
7474

7575
// HandleNonTransactionalDML is the entry point for a non-transactional DML statement

0 commit comments

Comments
 (0)