Skip to content

Commit

Permalink
roachtest: log expanded command
Browse files Browse the repository at this point in the history
This change now logs expanded commands if they differ from
the original command. This should ease debugging as we can
know what command was actually run on the node.
  • Loading branch information
DarrylWong committed Jan 30, 2025
1 parent 9bf4557 commit fc1ec93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/roachtest/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2508,7 +2508,7 @@ func (c *clusterImpl) RunE(ctx context.Context, options install.RunOptions, args
}
if err := roachprod.Run(
ctx, l, c.MakeNodes(nodes), "", "", c.IsSecure(),
l.Stdout, l.Stderr, args, options.WithExpanderConfig(expanderCfg),
l.Stdout, l.Stderr, args, options.WithExpanderConfig(expanderCfg).WithLogExpandedCommand(),
); err != nil {
if err := ctx.Err(); err != nil {
l.Printf("(note: incoming context was canceled: %s)", err)
Expand Down Expand Up @@ -2578,7 +2578,7 @@ func (c *clusterImpl) RunWithDetails(
}
results, err := roachprod.RunWithDetails(
ctx, l, c.MakeNodes(nodes), "" /* SSHOptions */, "", /* processTag */
c.IsSecure(), args, options.WithExpanderConfig(expanderCfg),
c.IsSecure(), args, options.WithExpanderConfig(expanderCfg).WithLogExpandedCommand(),
)

var logFileFull string
Expand Down
6 changes: 6 additions & 0 deletions pkg/roachprod/install/cluster_synced.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ func (r *RunResultDetails) Output(decorate bool) string {
type RunCmdOptions struct {
combinedOut bool
includeRoachprodEnvVars bool
logExpandedCmd bool // log expanded result if it differs from the original command
stdin io.Reader
stdout, stderr io.Writer
remoteOptions []remoteSessionOption
Expand Down Expand Up @@ -826,6 +827,9 @@ func (c *SyncedCluster) runCmdOnSingleNode(
if err != nil {
return &noResult, errors.WithDetailf(err, "error expanding command: %s", cmd)
}
if opts.logExpandedCmd && expandedCmd != cmd {
l.Printf("Node %d expanded cmd > %s", e.node, expandedCmd)
}

nodeCmd := expandedCmd
// Be careful about changing these command strings. In particular, we need
Expand Down Expand Up @@ -931,6 +935,7 @@ func (c *SyncedCluster) Run(
stdout: stdout,
stderr: stderr,
expanderConfig: options.ExpanderConfig,
logExpandedCmd: options.LogExpandedCmd,
}
result, err := c.runCmdOnSingleNode(ctx, l, node, cmd, opts)
return result, err
Expand Down Expand Up @@ -1015,6 +1020,7 @@ func (c *SyncedCluster) RunWithDetails(
stdout: l.Stdout,
stderr: l.Stderr,
expanderConfig: options.ExpanderConfig,
logExpandedCmd: options.LogExpandedCmd,
}
result, err := c.runCmdOnSingleNode(ctx, l, node, cmd, opts)
return result, err
Expand Down
7 changes: 7 additions & 0 deletions pkg/roachprod/install/run_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type RunOptions struct {
// ExpanderConfig configures the behaviour of the roachprod expander
// during a run.
ExpanderConfig ExpanderConfig
// LogExpandedCmd will log the expanded command if it differs from the original.
LogExpandedCmd bool

// These are private to roachprod
Nodes Nodes
Expand Down Expand Up @@ -106,3 +108,8 @@ func (r RunOptions) WithExpanderConfig(cfg ExpanderConfig) RunOptions {
r.ExpanderConfig = cfg
return r
}

func (r RunOptions) WithLogExpandedCommand() RunOptions {
r.LogExpandedCmd = true
return r
}

0 comments on commit fc1ec93

Please sign in to comment.