-
Notifications
You must be signed in to change notification settings - Fork 178
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
Add a --debug
flag to the CLI to help retrieve more logs.
#941
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a nice step towards getting debug logs from users without asking them to run weird Docker/Podman commands. I've commented on a few things that we can improve, but overall I like where this is going.
This seems correlated to #442. |
We had a discussion with Alexis. He mentioned that adding the |
I've rebased this branch on top of the latest |
This is currently blocking, because the docker process writes to Our conversion process is currently running in a thread pool, After a discussion with @apyrgio this morning on the matter, there seem to be two different outcomes for this:
I went with the second option for now, but the first one could also make sense. |
bea256d
to
4f4c523
Compare
9e86988
to
a4e34ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the changes. I think we're 🤏 close to merging it. I've left a few comments, but overall I like the new approach.
Oh, let's also have an issue to ask people to use the --debug
flag, once we have a release out.
self.stderr.seek(0) | ||
debug_log = read_debug_text(self.stderr, MAX_CONVERSION_LOG_CHARS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, if the stderr thread is still writing to the BytesIO
buffer (e.g., due to a race), then seeking to 0
risks overwriting the first bytes in the buffer. Also, we may get incomplete logs, without us realizing, which was not the case before (because we use p.poll() is not None
.
I propose we make some minor adjustments to the above logic:
- Check if the thread is alive after waiting for 1 second (
.join(timeout=1)
and.is_alive()
) - Grab the
BytesIO
buffer withBytesIO.getvalue()
, which doesn't require seeking. - Adjust
read_debug_text()
to sanitize thebytes
buffer of (2), instead of reading theBytesIO
object. - In case the thread is still alive, add an
(incomplete)
indication to the----- DOC TO PIXELS LOG START -----
message.
How does that sound, do you have a better idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added this in 3a56f51, let me know if that suits you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks a lot for the change. I have one important comment, and then some nits that you can ignore if you want to:
I think that MAX_CONVERSION_LOG_CHARS
will actually truncate the debug output of gVisor. It amounts to 150 lines of 50 chars roughly, but I think gVisor's debug logs are more than that. Now that we have a non-blocking way to read the stderr, I think we can drop the MAX_CONVERSION_LOG_CHARS
constant altogether, since it no longer serves the original purpose.
Nits:
- I'd maybe rename
read_debug_text()
tosanitize_debug_text()
. - It would be nice to know if the debug log is incomplete, without scrolling to the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About MAX_CONVERSION_LOGS_CHARS
, I felt exactly the same so thanks for the feedback! Dropped now and renamed the function in 8532688
About the "incomplete" log, I feel that having in the end is enough as it's where we would expect to have some more info. I might be missing some practical information you have. Do you have anything specific in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About MAX_CONVERSION_LOGS_CHARS, I felt exactly the same so thanks for the feedback! Dropped now and renamed the function in 8532688
Great, thanks!
About the "incomplete" log, I feel that having in the end is enough as it's where we would expect to have some more info. I might be missing some practical information you have. Do you have anything specific in mind?
Nothing fancy, something like:
DOC_TO_PIXELS_LOG_START = "----- DOC TO PIXELS LOG START -----"
DOC_TO_PIXELS_LOG_START_INCOMPLETE = "----- DOC TO PIXELS LOG START (incomplete) -----"
log_header = DOC_TO_PIXELS_LOG_START
if stderr_thread.is_alive():
log_header = DOC_TO_PIXELS_LOG_START_INCOMPLETE
log.info(
"Conversion output (doc to pixels)\n"
f"{log_header}\n"
f"{debug_log}" # no need for an extra newline here
f"{DOC_TO_PIXELS_LOG_END}"
)
But I'll leave it to you, really. I've approved the PR, so you can resolve this thread and merge it.
When the flag is set, the `RUNSC_DEBUG=1` environment variable is added to the outer container, and stderr is captured in a separate thread, before printing its output.
While adding Github Issue Templates on this repository (#939) we found that the commands we require the user to enter in their terminals can be quite complex. Some of them might require some bash-fu, for instance to define the location of the custom seccomp profile we are using, as it differs depending the OS.
This is a proposal to add a
--debug
flag to thedangerzone-cli
to simplify the process of generating proper logs.When the flag is set:
RUNSC_DEBUG=1
environment variable is added to the outer container ;Info: tests are currently failing and I didn't put too much effort in making them pass, as this is here mainly to see if it could make sense to add this in the first place.