From 666a9cdb589cd4334e21ea20ee7e6cdfb1b8510a Mon Sep 17 00:00:00 2001 From: Herko Lategan Date: Mon, 30 Sep 2024 11:01:19 +0100 Subject: [PATCH] roachtest: replace CRDB file sink log This replaces the initiation of the file sink based CRDB log with the new interceptor log redirect. It will log to a file in the artifacts directory. Epic: None Release note: None --- pkg/cmd/roachtest/BUILD.bazel | 3 --- pkg/cmd/roachtest/run.go | 31 +++++++++++++------------------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/pkg/cmd/roachtest/BUILD.bazel b/pkg/cmd/roachtest/BUILD.bazel index f532bbc04084..1742dedbb5a2 100644 --- a/pkg/cmd/roachtest/BUILD.bazel +++ b/pkg/cmd/roachtest/BUILD.bazel @@ -52,9 +52,6 @@ go_library( "//pkg/util/ctxgroup", "//pkg/util/httputil", "//pkg/util/leaktest", - "//pkg/util/log", - "//pkg/util/log/logconfig", - "//pkg/util/log/logpb", "//pkg/util/quotapool", "//pkg/util/randutil", "//pkg/util/stop", diff --git a/pkg/cmd/roachtest/run.go b/pkg/cmd/roachtest/run.go index aaa1bfb840c5..7537e5ee9991 100644 --- a/pkg/cmd/roachtest/run.go +++ b/pkg/cmd/roachtest/run.go @@ -31,9 +31,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/roachprod/logger" "github.com/cockroachdb/cockroach/pkg/util/allstacks" "github.com/cockroachdb/cockroach/pkg/util/leaktest" - "github.com/cockroachdb/cockroach/pkg/util/log" - "github.com/cockroachdb/cockroach/pkg/util/log/logconfig" - "github.com/cockroachdb/cockroach/pkg/util/log/logpb" "github.com/cockroachdb/cockroach/pkg/util/stop" "github.com/cockroachdb/cockroach/pkg/util/timeutil" "github.com/cockroachdb/cockroach/pkg/util/version" @@ -113,7 +110,8 @@ func runTests(register func(registry.Registry), filter *registry.TestFilter) err if literalArtifactsDir == "" { literalArtifactsDir = artifactsDir } - setLogConfig(artifactsDir) + redirectLogger := redirectCRDBLogger(context.Background(), filepath.Join(artifactsDir, "roachtest.crdb.log")) + logger.InitCRDBLogConfig(redirectLogger) runnerDir := filepath.Join(artifactsDir, runnerLogsDir) runnerLogPath := filepath.Join( runnerDir, fmt.Sprintf("test_runner-%d.log", timeutil.Now().Unix())) @@ -221,20 +219,6 @@ func runTests(register func(registry.Registry), filter *registry.TestFilter) err return err } -// This diverts all the default non-fatal logging to a file in `baseDir`. This is particularly -// useful in CI, where without this, stderr/stdout are cluttered with logs from various -// packages used in roachtest like sarama and testutils. -func setLogConfig(baseDir string) { - logConf := logconfig.DefaultStderrConfig() - logConf.Sinks.Stderr.Filter = logpb.Severity_FATAL - if err := logConf.Validate(&baseDir); err != nil { - panic(err) - } - if _, err := log.ApplyConfig(logConf, nil /* fileSinkMetricsForDir */, nil /* fatalOnLogStall */); err != nil { - panic(err) - } -} - // getUser takes the value passed on the command line and comes up with the // username to use. func getUser(userFlag string) string { @@ -395,6 +379,17 @@ func testRunnerLogger( return l, teeOpt } +func redirectCRDBLogger(ctx context.Context, path string) *logger.Logger { + verboseCfg := logger.Config{} + var err error + l, err := verboseCfg.NewLogger(path) + if err != nil { + panic(err) + } + shout(ctx, l, os.Stdout, "fallback runner logs in: %s", path) + return l +} + func maybeDumpSummaryMarkdown(r *testRunner) error { if !roachtestflags.GitHubActions { return nil