Skip to content

Commit

Permalink
roachtest: replace CRDB file sink log
Browse files Browse the repository at this point in the history
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
  • Loading branch information
herkolategan committed Oct 22, 2024
1 parent 5abff46 commit d18d184
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
2 changes: 0 additions & 2 deletions pkg/cmd/roachtest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 13 additions & 18 deletions pkg/cmd/roachtest/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d18d184

Please sign in to comment.