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

fix(dgoss): edgecase where no log is written #997

Merged
merged 4 commits into from
Nov 21, 2024

Conversation

dklimpel
Copy link
Contributor

@dklimpel dklimpel commented Nov 5, 2024

Checklist
  • make test-all (UNIX) passes. CI will also test this
  • unit and/or integration tests are included (if applicable)
  • documentation is changed or added (if applicable)

Description of change

I think this is a bug or a edge case. I used podman and always got an empty log file.
Partly it is discribed: https://docs.podman.io/en/stable/markdown/podman-logs.1.html#follow-f

--follow, -f
Follow log output. Default is false.

Note: When following a container which is removed by podman container rm or removed on exit (podman run --rm ...), there is a chance that the log file is removed before podman logs reads the final content.

I'm not sure if it's related to this or a problem with the flushing of the pipe in the operating system.

If the container is stopped before removal and a second pipe is created, the log is written. The content of the second pipe does not arrive and is therefore presumably swallowed.

If I am set timeout to 0 ($CONTAINER_RUNTIME stop -t 0 "$id" > /dev/null) then the last log entry appears in the log file in the tmp directory, but is apparently written to late and not copied to the target file.

@dklimpel dklimpel changed the title fix(dgoss): edgecase borderline case where no log is written fix(dgoss): edgecase case where no log is written Nov 5, 2024
@dklimpel dklimpel changed the title fix(dgoss): edgecase case where no log is written fix(dgoss): edgecase where no log is written Nov 5, 2024
@dklimpel dklimpel marked this pull request as ready for review November 5, 2024 08:16
Copy link
Member

@aelsabbahy aelsabbahy left a comment

Choose a reason for hiding this comment

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

Small comments, otherwise looks good.

Interesting find!

@@ -66,6 +68,8 @@ run(){
esac

$CONTAINER_RUNTIME logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 &
# There is a chance that the log will not be written, an empty line is added for mitigation.
echo "" >> "$tmp_dir/docker_output.log" 2>&1 &
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps touch makes more sense here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will test and check this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have looked at it. touch does not help. I think I have found an better and more transparent solution.

@@ -20,6 +20,8 @@ cleanup() {
set +e
{ kill "$log_pid" && wait "$log_pid"; } 2> /dev/null
if [ -n "$CONTAINER_LOG_OUTPUT" ]; then
info "Stopping container and copy log"
$CONTAINER_RUNTIME stop -t 1 "$id" > /dev/null
Copy link
Member

Choose a reason for hiding this comment

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

Does the -t flag work consistently with podman or docker?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@aelsabbahy aelsabbahy left a comment

Choose a reason for hiding this comment

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

Nice, this solution is elegant and clear.

@aelsabbahy aelsabbahy merged commit 817cbb6 into goss-org:master Nov 21, 2024
6 checks passed
@dklimpel dklimpel deleted the dgoss_log_output branch November 21, 2024 09:12
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.

2 participants