From 9c76148bb0032cef80ced79c9d95e7ed8dece732 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 | 2 -- pkg/cmd/roachtest/run.go | 31 +++++++++++++------------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/pkg/cmd/roachtest/BUILD.bazel b/pkg/cmd/roachtest/BUILD.bazel index b9687d35c0a5..70a89e6396d5 100644 --- a/pkg/cmd/roachtest/BUILD.bazel +++ b/pkg/cmd/roachtest/BUILD.bazel @@ -53,8 +53,6 @@ go_library( "//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 b0b62cc72572..deb565112b8d 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/errors" @@ -112,7 +109,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())) @@ -219,20 +217,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 { @@ -387,6 +371,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