Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RB] Fix duplicate logs when the console does not support ANSI escape sequences #6163

Merged
merged 3 commits into from
Mar 18, 2024

Conversation

maggie-lou
Copy link
Contributor

We run the ci_runner in interactive mode so that it prints real-time updates for git and bazel commands.
However the Github Actions shell does not support ANSI escape sequences (actions/runner#241). When running remote bazel or the ExecuteWorkflow API in a Github Action runner, this causes output lines to be printed several times (because the real-time printing tries to delete and over-write a previous line with an updated progress message, but deletion isn't supported).

Add a configurable option to disable interactive mode

Related issues: Fixes https://github.com/buildbuddy-io/buildbuddy-internal/issues/3143

@maggie-lou
Copy link
Contributor Author

maggie-lou commented Mar 15, 2024

Copy link
Member

@bduffany bduffany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a heads up, I don't think this will fully fix the linked issue, because we're still using ANSI escape sequences to erase and redraw the live log tail. I think we will need some server-side changes to allow configuring an invocation in "non-streaming" mode, which might be a bit more involved. But this PR is needed either way so it's a good starting point 👍

@@ -67,6 +67,7 @@ var (
remoteRunner = remoteFlagset.String("remote_runner", defaultRemoteExecutionURL, "The Buildbuddy grpc target the remote runner should run on.")
timeout = remoteFlagset.Duration("timeout", 0, "If set, requests that have exceeded this timeout will be canceled automatically. (Ex. --timeout=15m; --timeout=2h)")
execPropsFlag = bbflag.New(remoteFlagset, "runner_exec_properties", []string{}, "Exec properties that will apply to the *ci runner execution*. Key-value pairs should be separated by '=' (Ex. --runner_exec_properties=NAME=VALUE). Can be specified more than once. NOTE: If you want to apply an exec property to the bazel command that's run on the runner, just pass at the end of the command (Ex. bb remote build //... --remote_default_exec_properties=OSFamily=linux).")
interactive = remoteFlagset.Bool("interactive", true, "Whether to run the script in interactive mode (will print real-time progress updates using ANSI escape sequences). This may cause duplicate logs to be printed if the console does not support ANSI escape sequences.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making this an explicit flag, I think it would be better to check whether the command's output is a terminal or not. You can use terminal.IsTTY(os.Stderr) && terminal.IsTTY(os.Stdout) to check (from the cli/terminal package). When running locally in a terminal, this should return true. If you send the output to a pipe, like bb remote ... | cat, it'll return false. On GH actions, I think it will return false, since the actions runner is not running actions inside an interactive terminal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

enterprise/server/cmd/ci_runner/main.go Outdated Show resolved Hide resolved
@maggie-lou
Copy link
Contributor Author

Just as a heads up, I don't think this will fully fix the linked issue, because we're still using ANSI escape sequences to erase and redraw the live log tail. I think we will need some server-side changes to allow configuring an invocation in "non-streaming" mode, which might be a bit more involved. But this PR is needed either way so it's a good starting point 👍

Simplified the PR by only checking for interactive support in cli/remotebazel

time.Sleep(1 * time.Second)
continue
}
drawChunk(l)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be

os.Stdout.Write(chunkGetBuffer())

and then we could get rid of drawChunk

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@maggie-lou maggie-lou merged commit c70d70c into master Mar 18, 2024
11 of 19 checks passed
@maggie-lou maggie-lou deleted the rb_dup_logging branch March 18, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants