Skip to content

Commit

Permalink
[ci_runner] Add more debug logs (#7379)
Browse files Browse the repository at this point in the history
  • Loading branch information
maggie-lou committed Sep 5, 2024
1 parent 0263bbe commit 3d11101
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions enterprise/server/cmd/ci_runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ func (r *buildEventReporter) startBackgroundProgressFlush() func() {
}

func main() {
if os.Getenv("CI_RUNNER_DEBUG") == "1" {
*backendLog.LogLevel = "debug"
backendLog.Configure()
}
backendLog.Debugf("Top of main")
if err := run(); err != nil {
if result, ok := err.(*actionResult); ok {
os.Exit(result.exitCode)
Expand All @@ -570,10 +575,13 @@ func run() error {
return err
}
}
backendLog.Debugf("Finished parsing flags")
if *credentialHelper {
backendLog.Debugf("Running credential helper")
return runCredentialHelper()
}
if isBazelWrapper {
backendLog.Debugf("Running bazel wrapper")
return runBazelWrapper()
}

Expand Down Expand Up @@ -605,6 +613,7 @@ func run() error {

// Use a context without a timeout for the build event reporter, so that even
// if the `timeout` is reached, any events will finish getting published
backendLog.Debugf("Initializing build event reporter")
buildEventReporter, err := newBuildEventReporter(contextWithoutTimeout, *besBackend, ws.buildbuddyAPIKey, *invocationID, *workflowID != "" /*=isWorkflow*/)
if err != nil {
return err
Expand All @@ -630,6 +639,7 @@ func run() error {
}
// Change the current working directory to respect WORKDIR_OVERRIDE, if set.
if wd := os.Getenv("WORKDIR_OVERRIDE"); wd != "" {
backendLog.Debugf("Initializing working directory %s", wd)
if err := os.MkdirAll(wd, 0755); err != nil {
return status.WrapError(err, "create WORKDIR_OVERRIDE directory")
}
Expand Down Expand Up @@ -663,10 +673,13 @@ func run() error {
return status.WrapError(err, "disable interactivity")
}

backendLog.Debugf("Completed checking configuration requirements")

// Write default bazelrc
if err := writeBazelrc(buildbuddyBazelrcPath, buildEventReporter.invocationID, runID, rootDir); err != nil {
return status.WrapError(err, "write "+buildbuddyBazelrcPath)
}
backendLog.Debugf("Completed writing bazelrc")
// Delete bazelrc before exiting. Use abs path since we might cd after this
// point.
absBazelrcPath, err := filepath.Abs(buildbuddyBazelrcPath)
Expand All @@ -687,18 +700,22 @@ func run() error {
// Make sure we have a bazel / bazelisk binary available.
if *bazelCommand == "" {
bazeliskPath := filepath.Join(rootDir, bazeliskBinaryName)
backendLog.Debugf("Preparing to extract bazelisk")
if err := extractBazelisk(bazeliskPath); err != nil {
return status.WrapError(err, "failed to extract bazelisk")
}
backendLog.Debugf("Finished extracting bazelisk")
*bazelCommand = bazeliskPath

}

// Use the bazel wrapper script, which adds some common flags to all
// Bazel builds.
backendLog.Debugf("Preparing to write bazel wrapper script")
if err := ws.writeBazelWrapperScript(); err != nil {
return status.WrapError(err, "write bazel wrapper script")
}
backendLog.Debugf("Finished write bazel wrapper script")

if *shutdownAndExit {
ws.log.Println("--shutdown_and_exit requested; will run bazel shutdown then exit.")
Expand Down Expand Up @@ -727,6 +744,7 @@ func run() error {
return nil
}

backendLog.Debugf("Starting build event reporter")
if err := buildEventReporter.Start(ws.startTime); err != nil {
return status.WrapError(err, "could not publish started event")
}
Expand Down
7 changes: 7 additions & 0 deletions enterprise/server/remote_execution/commandutil/commandutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var (
)

func constructExecCommand(command *repb.Command, workDir string, stdio *interfaces.Stdio) (*exec.Cmd, *bytes.Buffer, *bytes.Buffer, error) {
log.Debugf("Top of constructExecCommand")
defer log.Debugf("Finished constructExecCommand")
if stdio == nil {
stdio = &interfaces.Stdio{}
}
Expand All @@ -72,6 +74,7 @@ func constructExecCommand(command *repb.Command, workDir string, stdio *interfac
// the process doesn't consume its stdin. See
// https://go.dev/play/p/DpKaVrx8d8G
if stdio.Stdin != nil {
log.Debugf("Get stdin pipe")
inp, err := cmd.StdinPipe()
if err != nil {
return nil, nil, nil, status.InternalErrorf("failed to get stdin pipe: %s", err)
Expand All @@ -86,6 +89,7 @@ func constructExecCommand(command *repb.Command, workDir string, stdio *interfac
cmd.Stdout = io.MultiWriter(cmd.Stdout, logWriter)
cmd.Stderr = io.MultiWriter(cmd.Stderr, logWriter)
}
log.Debugf("Preparing to get default sys proc attr")
cmd.SysProcAttr = getDefaultSysProcAttr()
for _, envVar := range command.GetEnvironmentVariables() {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", envVar.GetName(), envVar.GetValue()))
Expand Down Expand Up @@ -189,9 +193,11 @@ func startNewProcess(ctx context.Context, cmd *exec.Cmd) (*process, error) {
cmd: cmd,
terminated: make(chan struct{}),
}
log.Debugf("Preparing to run process prestart")
if err := p.preStart(); err != nil {
return nil, fmt.Errorf("fail to setup preStart: %w", err)
}
log.Debugf("Preparing to run command start")
if err := p.cmd.Start(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -244,6 +250,7 @@ func RunWithProcessTreeCleanup(ctx context.Context, cmd *exec.Cmd, opts *RunOpts
opts = &RunOpts{}
}

log.CtxDebugf(ctx, "Preparing to start new process")
p, err := startNewProcess(ctx, cmd)
if err != nil {
return nil, err
Expand Down

0 comments on commit 3d11101

Please sign in to comment.