From 950783e4202bb848ce6f55a4836b6705ad5383b4 Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Thu, 24 Apr 2025 12:10:30 +0800 Subject: [PATCH 1/3] dumpling: return error if init log file failed --- DEPS.bzl | 12 +++++------ dumpling/log/BUILD.bazel | 11 +++++++++- dumpling/log/log_test.go | 45 ++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 dumpling/log/log_test.go diff --git a/DEPS.bzl b/DEPS.bzl index 367cba15ca93c..b0d241e5f30fc 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -5893,13 +5893,13 @@ def go_deps(): name = "com_github_pingcap_log", build_file_proto_mode = "disable_global", importpath = "github.com/pingcap/log", - sha256 = "ecdf624669a639a91f49a368f7090df11e9bff366f404fc8a379035fb4d9fe7f", - strip_prefix = "github.com/pingcap/log@v1.1.1-0.20241212030209-7e3ff8601a2a", + sha256 = "8c5ac751f87626274ace3b615ff7b88552eede51c58eddb6c1f0a7ba5b191c6e", + strip_prefix = "github.com/pingcap/log@v1.1.1-0.20250424032633-85a82d016f84", urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20241212030209-7e3ff8601a2a.zip", - "http://ats.apps.svc/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20241212030209-7e3ff8601a2a.zip", - "https://cache.hawkingrei.com/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20241212030209-7e3ff8601a2a.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20241212030209-7e3ff8601a2a.zip", + "http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250424032633-85a82d016f84.zip", + "http://ats.apps.svc/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250424032633-85a82d016f84.zip", + "https://cache.hawkingrei.com/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250424032633-85a82d016f84.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250424032633-85a82d016f84.zip", ], ) go_repository( diff --git a/dumpling/log/BUILD.bazel b/dumpling/log/BUILD.bazel index 5686f7289667a..fbc2b61268d18 100644 --- a/dumpling/log/BUILD.bazel +++ b/dumpling/log/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "log", @@ -11,3 +11,12 @@ go_library( "@org_uber_go_zap//:zap", ], ) + +go_test( + name = "log_test", + timeout = "short", + srcs = ["log_test.go"], + embed = [":log"], + flaky = True, + deps = ["@com_github_stretchr_testify//require"], +) diff --git a/dumpling/log/log_test.go b/dumpling/log/log_test.go new file mode 100644 index 0000000000000..336ee37e4a7fa --- /dev/null +++ b/dumpling/log/log_test.go @@ -0,0 +1,45 @@ +// Copyright 2025 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package log + +import ( + "os" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestInitLogNoPermission(t *testing.T) { + // create a temp dir without permissions + tmpDir, err := os.MkdirTemp("", "dumpling-test") + require.NoError(t, err) + defer os.RemoveAll(tmpDir) + + conf := &Config{ + Level: "debug", + File: tmpDir + "/test.log", + Format: "text", + } + + logger, _, err := InitAppLogger(conf) + require.NoError(t, err) + require.NotNil(t, logger) + + err = os.Chmod(tmpDir, 0) + require.NoError(t, err) + + _, _, err = InitAppLogger(conf) + require.ErrorContains(t, err, "permission denied") +} diff --git a/go.mod b/go.mod index 236e1bceb0d58..3945a9e550e03 100644 --- a/go.mod +++ b/go.mod @@ -89,7 +89,7 @@ require ( github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 github.com/pingcap/fn v1.0.0 github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d - github.com/pingcap/log v1.1.1-0.20241212030209-7e3ff8601a2a + github.com/pingcap/log v1.1.1-0.20250424032633-85a82d016f84 github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5 github.com/pingcap/tidb/pkg/parser v0.0.0-20211011031125-9b13dc409c5e github.com/pingcap/tipb v0.0.0-20250331100511-d2c561dad347 diff --git a/go.sum b/go.sum index c588d7c643533..9fb64c7d7501e 100644 --- a/go.sum +++ b/go.sum @@ -687,6 +687,8 @@ github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuR github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= github.com/pingcap/log v1.1.1-0.20241212030209-7e3ff8601a2a h1:WIhmJBlNGmnCWH6TLMdZfNEDaiU8cFpZe3iaqDbQ0M8= github.com/pingcap/log v1.1.1-0.20241212030209-7e3ff8601a2a/go.mod h1:ORfBOFp1eteu2odzsyaxI+b8TzJwgjwyQcGhI+9SfEA= +github.com/pingcap/log v1.1.1-0.20250424032633-85a82d016f84 h1:ljnSbUq7LOkUtLtDXjTS5GanSWSAQ8pgVn7ucXMeMK8= +github.com/pingcap/log v1.1.1-0.20250424032633-85a82d016f84/go.mod h1:ORfBOFp1eteu2odzsyaxI+b8TzJwgjwyQcGhI+9SfEA= github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5 h1:T4pXRhBflzDeAhmOQHNPRRogMYxP13V7BkYw3ZsoSfE= github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5/go.mod h1:rlimy0GcTvjiJqvD5mXTRr8O2eNZPBrcUgiWVYp9530= github.com/pingcap/tipb v0.0.0-20250331100511-d2c561dad347 h1:PAeUQaG0EEugM2fVlMPYPzrJPOY5uvvi082VJKMadCQ= From 1b77c6868323f0f56441d967f4fea289afaf4ea9 Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Fri, 25 Apr 2025 11:46:03 +0800 Subject: [PATCH 2/3] dumpling: return error if init log file failed --- dumpling/log/log_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/dumpling/log/log_test.go b/dumpling/log/log_test.go index 336ee37e4a7fa..7713a32104fa5 100644 --- a/dumpling/log/log_test.go +++ b/dumpling/log/log_test.go @@ -22,11 +22,7 @@ import ( ) func TestInitLogNoPermission(t *testing.T) { - // create a temp dir without permissions - tmpDir, err := os.MkdirTemp("", "dumpling-test") - require.NoError(t, err) - defer os.RemoveAll(tmpDir) - + tmpDir := t.TempDir() conf := &Config{ Level: "debug", File: tmpDir + "/test.log", From 74abf909cd4d2aa6c2a4bbd80b383ada80269f22 Mon Sep 17 00:00:00 2001 From: joccau Date: Fri, 25 Apr 2025 13:02:16 +0800 Subject: [PATCH 3/3] make tidy Signed-off-by: joccau --- go.mod | 1 - go.sum | 2 -- 2 files changed, 3 deletions(-) diff --git a/go.mod b/go.mod index 3945a9e550e03..75435b48e8f39 100644 --- a/go.mod +++ b/go.mod @@ -336,4 +336,3 @@ replace ( sourcegraph.com/sourcegraph/appdash => github.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0 sourcegraph.com/sourcegraph/appdash-data => github.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) - diff --git a/go.sum b/go.sum index 9fb64c7d7501e..fa0301c0a6c6b 100644 --- a/go.sum +++ b/go.sum @@ -685,8 +685,6 @@ github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d h1:52qhTQG8G8V/pHo github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8= github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM= github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= -github.com/pingcap/log v1.1.1-0.20241212030209-7e3ff8601a2a h1:WIhmJBlNGmnCWH6TLMdZfNEDaiU8cFpZe3iaqDbQ0M8= -github.com/pingcap/log v1.1.1-0.20241212030209-7e3ff8601a2a/go.mod h1:ORfBOFp1eteu2odzsyaxI+b8TzJwgjwyQcGhI+9SfEA= github.com/pingcap/log v1.1.1-0.20250424032633-85a82d016f84 h1:ljnSbUq7LOkUtLtDXjTS5GanSWSAQ8pgVn7ucXMeMK8= github.com/pingcap/log v1.1.1-0.20250424032633-85a82d016f84/go.mod h1:ORfBOFp1eteu2odzsyaxI+b8TzJwgjwyQcGhI+9SfEA= github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5 h1:T4pXRhBflzDeAhmOQHNPRRogMYxP13V7BkYw3ZsoSfE=