Skip to content

logger/journald: fix tailing logs with systemd 255#47019

Merged
cpuguy83 merged 5 commits intomoby:masterfrom
corhere:fix-journald-logs-systemd-255
Jan 28, 2024
Merged

logger/journald: fix tailing logs with systemd 255#47019
cpuguy83 merged 5 commits intomoby:masterfrom
corhere:fix-journald-logs-systemd-255

Conversation

@corhere
Copy link
Contributor

@corhere corhere commented Jan 3, 2024

- What I did

  • Made journald read tests compatible with systemd version 255
  • Made journald reader compatible with systemd version 255

- How I did it
By fixing the journald reader to no longer rely upon an invalid assumption about the sd-journal reader API. See the individual commit messages for more details.

- How to verify it
The journald reader tests pass in the dev container / CI (systemd 253) and in an archlinux container with systemd 255 installed.

- Description for the changelog

  • Fixed an issue with the journald log driver which prevented container logs from being followed correctly in certain circumstances when used with systemd version 255.

- A picture of a cute animal (not mandatory but encouraged)

@corhere corhere force-pushed the fix-journald-logs-systemd-255 branch 2 times, most recently from 016cceb to 54b151c Compare January 3, 2024 21:09
Following logs with a non-negative tail when the container log is empty
is broken on the journald driver when used with systemd 255. Add tests
which cover this edge case to our loggertest suite.

Signed-off-by: Cory Snider <csnider@mirantis.com>
Synthesize a boot ID for journal entries fed into
systemd-journal-remote, as required by systemd 255.

Signed-off-by: Cory Snider <csnider@mirantis.com>
The journald reader uses a timer to set an upper bound on how long to
wait for the final log message of a stopped container. However, the
timer channel is only received from in non-blocking select statements!
There isn't enough benefit of using a timer to offset the cost of having
to manage the timer resource. Setting a deadline and comparing the
current time is just as effective, without having to manage the
lifecycle of any runtime resources.

Signed-off-by: Cory Snider <csnider@mirantis.com>
@corhere corhere force-pushed the fix-journald-logs-systemd-255 branch 2 times, most recently from 9a4f699 to 4ecfaee Compare January 26, 2024 17:00
@vvoland
Copy link
Contributor

vvoland commented Jan 26, 2024

LGTM; the linter has some very arguable complaint though 😭

 daemon/logger/journald/read.go:198:10: S1024: should use time.Until instead of t.Sub(time.Now()) (gosimple)
			dur = r.drainDeadline.Sub(time.Now())
			      ^

While it doesn't really matter if the reader waits for an extra
arbitrary period beyond an arbitrary hardcoded timeout, it's also
trivial and cheap to implement, and nice to have.

Signed-off-by: Cory Snider <csnider@mirantis.com>
errDrainDone is a sentinel error which is never supposed to escape the
package. Consequently, it needs to be filtered out of returns all over
the place, adding boilerplate. Forgetting to filter out these errors
would be a logic bug which the compiler would not help us catch. Replace
it with boolean multi-valued returns as they can't be accidentally
ignored or propagated.

Signed-off-by: Cory Snider <csnider@mirantis.com>
@corhere corhere force-pushed the fix-journald-logs-systemd-255 branch from 4ecfaee to 905477c Compare January 26, 2024 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logs are not followed when using journald log-driver with systemd 255

4 participants