From 555ce0235229dc370cc8e63574437cf9ee60bdd0 Mon Sep 17 00:00:00 2001 From: kennytm Date: Wed, 3 Apr 2024 22:09:18 +0800 Subject: [PATCH] lightning: Don't log "received task config" in server mode (#52336) close pingcap/tidb#36374 --- lightning/pkg/server/lightning.go | 3 +-- pkg/lightning/common/BUILD.bazel | 2 +- pkg/lightning/common/util.go | 9 --------- pkg/lightning/common/util_test.go | 32 ------------------------------- 4 files changed, 2 insertions(+), 44 deletions(-) diff --git a/lightning/pkg/server/lightning.go b/lightning/pkg/server/lightning.go index 6396da7387a86..6520e849fb6c8 100644 --- a/lightning/pkg/server/lightning.go +++ b/lightning/pkg/server/lightning.go @@ -757,8 +757,7 @@ func (l *Lightning) handlePostTask(w http.ResponseWriter, req *http.Request) { writeJSONError(w, http.StatusBadRequest, "cannot read request", err) return } - filteredData := common.HideSensitive(string(data)) - log.L().Info("received task config", zap.String("content", filteredData)) + log.L().Info("received task config") cfg := config.NewConfig() if err = cfg.LoadFromGlobal(l.globalCfg); err != nil { diff --git a/pkg/lightning/common/BUILD.bazel b/pkg/lightning/common/BUILD.bazel index 4268e078c5365..9d1a023b5a589 100644 --- a/pkg/lightning/common/BUILD.bazel +++ b/pkg/lightning/common/BUILD.bazel @@ -112,7 +112,7 @@ go_test( ], embed = [":common"], flaky = True, - shard_count = 30, + shard_count = 29, deps = [ "//br/pkg/errors", "//pkg/ddl", diff --git a/pkg/lightning/common/util.go b/pkg/lightning/common/util.go index 66f6d720a16ea..6361ce45189d0 100644 --- a/pkg/lightning/common/util.go +++ b/pkg/lightning/common/util.go @@ -26,7 +26,6 @@ import ( "net" "net/http" "os" - "regexp" "strconv" "strings" "syscall" @@ -697,11 +696,3 @@ func IsRaftKV2(ctx context.Context, db *sql.DB) (bool, error) { } return false, rows.Err() } - -var passwordRegexp = regexp.MustCompile(`(password[\s]*=[\s]*(\\")?)(.*?)((\\")?\\n)`) - -// HideSensitive replace password with ******. -func HideSensitive(input string) string { - output := passwordRegexp.ReplaceAllString(input, "$1******$4") - return output -} diff --git a/pkg/lightning/common/util_test.go b/pkg/lightning/common/util_test.go index 7e5224de32f52..d8852bed1c358 100644 --- a/pkg/lightning/common/util_test.go +++ b/pkg/lightning/common/util_test.go @@ -302,35 +302,3 @@ CREATE TABLE multi_indexes ( require.Equal(t, tt.multiSQLs, multiSQLs) } } - -func TestHideSensitive(t *testing.T) { - strs := []struct { - old string - new string - }{ - { - `host = "127.0.0.1"\n user = "root"\n password = "/Q7B9DizNLLTTfiZHv9WoEAKamfpIUs="\n port = 3306\n`, - `host = "127.0.0.1"\n user = "root"\n password = ******\n port = 3306\n`, - }, - { - `host = "127.0.0.1"\n user = "root"\n password = ""\n port = 3306\n`, - `host = "127.0.0.1"\n user = "root"\n password = ******\n port = 3306\n`, - }, - { - `host = "127.0.0.1"\n user = "root"\n password= "/Q7B9DizNLLTTfiZHv9WoEAKamfpIUs="\n port = 3306\n`, - `host = "127.0.0.1"\n user = "root"\n password= ******\n port = 3306\n`, - }, - { - `host = "127.0.0.1"\n user = "root"\n password =""\n port = 3306\n`, - `host = "127.0.0.1"\n user = "root"\n password =******\n port = 3306\n`, - }, - { - `host = "127.0.0.1"\n user = "root"\n password=""\n port = 3306\n`, - `host = "127.0.0.1"\n user = "root"\n password=******\n port = 3306\n`, - }, - } - for i, str := range strs { - t.Logf("case #%d\n", i) - require.Equal(t, str.new, common.HideSensitive(str.old)) - } -}