Skip to content

Commit

Permalink
roachtest: prefix all logs with worker tags
Browse files Browse the repository at this point in the history
Previously, many of the runner logs didn't have the worker tags.
This was inadequate because we couldn't break up the logs by wX
tags to see what each worker is doing.
This PR prefixes the worker tags to logs that were missing them.

Epic: none
Fixes: cockroachdb#114045
Release note: None
  • Loading branch information
vidit-bhat committed May 14, 2024
1 parent 2f739e8 commit cba5427
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,7 @@ func (c *clusterImpl) Get(
return errors.Wrap(roachprod.Get(ctx, l, c.MakeNodes(opts...), src, dest), "cluster.Get")
}

// Put a string into the specified file on the remote(s).
// PutString into the specified file on the remote(s).
func (c *clusterImpl) PutString(
ctx context.Context, content, dest string, mode os.FileMode, nodes ...option.Option,
) error {
Expand Down
18 changes: 12 additions & 6 deletions pkg/cmd/roachtest/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/cockroach/pkg/util/version"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/logtags"
"github.com/petermattis/goid"
)

Expand Down Expand Up @@ -363,21 +362,29 @@ func (r *testRunner) Run(
if err := r.stopper.RunAsyncTask(ctx, "worker", func(ctx context.Context) {
defer wg.Done()

err := r.runWorker(
ctx, fmt.Sprintf("w%d", i) /* name */, r.work, qp,
name := fmt.Sprintf("w%d", i)
formattedPrefix := fmt.Sprintf("[%s] ", name)
childLogger, err := l.ChildLogger(name, logger.LogPrefix(formattedPrefix))
if err != nil {
l.ErrorfCtx(ctx, "unable to create logger %s: %s", name, err)
childLogger = l
}

err = r.runWorker(
ctx, name, r.work, qp,
r.stopper.ShouldQuiesce(),
clusterFactory,
clustersOpt,
lopt,
topt,
l,
childLogger,
n*count,
)

if err != nil {
// A worker returned an error. Let's shut down.
msg := fmt.Sprintf("Worker %d returned with error. Quiescing. Error: %v", i, err)
shout(ctx, l, lopt.stdout, msg)
shout(ctx, childLogger, lopt.stdout, msg)
errs.AddErr(err)
// Stop the stopper. This will cause all workers to not pick up more
// tests after finishing the currently running one. We add one to the
Expand Down Expand Up @@ -557,7 +564,6 @@ func (r *testRunner) runWorker(
) error {
stdout := lopt.stdout

ctx = logtags.AddTag(ctx, name, nil /* value */)
wStatus := r.addWorker(ctx, name)
defer func() {
r.removeWorker(ctx, name)
Expand Down

0 comments on commit cba5427

Please sign in to comment.