From 3849d8cbfb4031d2625b015fa421d4f44f23a6b4 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 12 Aug 2019 16:30:05 -0400 Subject: Fix container exit code with Journald backend We weren't actually storing this, so we'd lose the exit code for containers run with --rm or force-removed while running if the journald backend for events was in use. Fixes #3795 Signed-off-by: Matthew Heon --- libpod/events/journal_linux.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libpod') diff --git a/libpod/events/journal_linux.go b/libpod/events/journal_linux.go index d5bce4334..94fceccb1 100644 --- a/libpod/events/journal_linux.go +++ b/libpod/events/journal_linux.go @@ -4,6 +4,7 @@ package events import ( "fmt" + "strconv" "time" "github.com/coreos/go-systemd/journal" @@ -42,6 +43,7 @@ func (e EventJournalD) Write(ee Event) error { m["PODMAN_IMAGE"] = ee.Image m["PODMAN_NAME"] = ee.Name m["PODMAN_ID"] = ee.ID + m["PODMAN_EXIT_CODE"] = strconv.Itoa(ee.ContainerExitCode) case Volume: m["PODMAN_NAME"] = ee.Name } @@ -141,6 +143,14 @@ func newEventFromJournalEntry(entry *sdjournal.JournalEntry) (*Event, error) { / case Container, Pod: newEvent.ID = entry.Fields["PODMAN_ID"] newEvent.Image = entry.Fields["PODMAN_IMAGE"] + if code, ok := entry.Fields["PODMAN_EXIT_CODE"]; ok { + intCode, err := strconv.Atoi(code) + if err != nil { + logrus.Errorf("Error parsing event exit code %s", code) + } else { + newEvent.ContainerExitCode = intCode + } + } case Image: newEvent.ID = entry.Fields["PODMAN_ID"] } -- cgit v1.2.3-54-g00ecf From bbb1ba78d4da3df796b845c67ff477e7cd8563dc Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 12 Aug 2019 16:34:49 -0400 Subject: Small optimization - only store exit code when nonzero JSON optimizes it out in that case anyways, so don't waste cycles doing an Itoa (and Atoi on the decode side). Signed-off-by: Matthew Heon --- libpod/events/journal_linux.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libpod') diff --git a/libpod/events/journal_linux.go b/libpod/events/journal_linux.go index 94fceccb1..2854e6548 100644 --- a/libpod/events/journal_linux.go +++ b/libpod/events/journal_linux.go @@ -43,7 +43,9 @@ func (e EventJournalD) Write(ee Event) error { m["PODMAN_IMAGE"] = ee.Image m["PODMAN_NAME"] = ee.Name m["PODMAN_ID"] = ee.ID - m["PODMAN_EXIT_CODE"] = strconv.Itoa(ee.ContainerExitCode) + if ee.ContainerExitCode != 0 { + m["PODMAN_EXIT_CODE"] = strconv.Itoa(ee.ContainerExitCode) + } case Volume: m["PODMAN_NAME"] = ee.Name } -- cgit v1.2.3-54-g00ecf From b49ff958d5dfb01a85fb0d5c394b1ba7d9a74d2d Mon Sep 17 00:00:00 2001 From: baude Date: Tue, 13 Aug 2019 12:22:24 -0500 Subject: performance fix for podman events with large journalds in the case where the host has a large journald, iterating the journal without using a Match is very poor performance. this might be a temporary fix while we figure out why the systemd library does not seem to behave properly. Signed-off-by: baude --- libpod/events/journal_linux.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libpod') diff --git a/libpod/events/journal_linux.go b/libpod/events/journal_linux.go index 2854e6548..e7e919d6d 100644 --- a/libpod/events/journal_linux.go +++ b/libpod/events/journal_linux.go @@ -70,6 +70,11 @@ func (e EventJournalD) Read(options ReadOptions) error { if err := j.SeekTail(); err != nil { return errors.Wrap(err, "failed to seek end of journal") } + } else { + podmanJournal := sdjournal.Match{Field: "SYSLOG_IDENTIFIER", Value: "podman"} //nolint + if err := j.AddMatch(podmanJournal.String()); err != nil { + return errors.Wrap(err, "failed to add filter for event log") + } } // the api requires a next|prev before getting a cursor if _, err := j.Next(); err != nil { -- cgit v1.2.3-54-g00ecf