From 92acb3676c53d26cbad71e079f96c32a29a148da Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Wed, 20 May 2020 09:48:16 -0400 Subject: oci conmon: tell conmon to log container name specifying `-n=ctr-name` tells conmon to log CONTAINER_NAME=name if the log driver is journald add this, and a test! also, refactor the args slice creation to not append() unnecessarily. Signed-off-by: Peter Hunt --- libpod/oci_conmon_linux.go | 20 ++++++++++++-------- test/e2e/logs_test.go | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go index 895a67747..7ba36fe7c 100644 --- a/libpod/oci_conmon_linux.go +++ b/libpod/oci_conmon_linux.go @@ -1347,15 +1347,21 @@ func (r *ConmonOCIRuntime) configureConmonEnv(runtimeDir string) ([]string, []*o // sharedConmonArgs takes common arguments for exec and create/restore and formats them for the conmon CLI func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, pidPath, logPath, exitDir, ociLogPath, logTag string) []string { // set the conmon API version to be able to use the correct sync struct keys - args := []string{"--api-version", "1"} + args := []string{ + "--api-version", "1", + "-c", ctr.ID(), + "-u", cuuid, + "-r", r.path, + "-b", bundlePath, + "-p", pidPath, + "-n", ctr.Name(), + "--exit-dir", exitDir, + "--socket-dir-path", r.socketsDir, + } + if r.cgroupManager == config.SystemdCgroupsManager && !ctr.config.NoCgroups { args = append(args, "-s") } - args = append(args, "-c", ctr.ID()) - args = append(args, "-u", cuuid) - args = append(args, "-r", r.path) - args = append(args, "-b", bundlePath) - args = append(args, "-p", pidPath) var logDriver string switch ctr.LogDriver() { @@ -1376,8 +1382,6 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p } args = append(args, "-l", logDriver) - args = append(args, "--exit-dir", exitDir) - args = append(args, "--socket-dir-path", r.socketsDir) if r.logSizeMax >= 0 { args = append(args, "--log-size-max", fmt.Sprintf("%v", r.logSizeMax)) } diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go index 8417051f0..1ff53300a 100644 --- a/test/e2e/logs_test.go +++ b/test/e2e/logs_test.go @@ -173,6 +173,24 @@ var _ = Describe("Podman logs", func() { Expect(string(out)).To(ContainSubstring("alpine")) }) + It("podman journald logs for container name", func() { + Skip("need to verify images have correct packages for journald") + containerName := "inside-journal" + logc := podmanTest.Podman([]string{"run", "--log-driver", "journald", "-d", "--name", containerName, ALPINE, "sh", "-c", "echo podman; sleep 0.1; echo podman; sleep 0.1; echo podman"}) + logc.WaitWithDefaultTimeout() + Expect(logc.ExitCode()).To(Equal(0)) + cid := logc.OutputToString() + + wait := podmanTest.Podman([]string{"wait", "-l"}) + wait.WaitWithDefaultTimeout() + Expect(wait.ExitCode()).To(BeZero()) + + cmd := exec.Command("journalctl", "--no-pager", "-o", "json", "--output-fields=CONTAINER_NAME", "-u", fmt.Sprintf("libpod-conmon-%s.scope", cid)) + out, err := cmd.CombinedOutput() + Expect(err).To(BeNil()) + Expect(string(out)).To(ContainSubstring(containerName)) + }) + It("podman journald logs for container", func() { Skip("need to verify images have correct packages for journald") logc := podmanTest.Podman([]string{"run", "--log-driver", "journald", "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"}) -- cgit v1.2.3-54-g00ecf From d2d338b7ec5148e349b94d8ba606f69e6408910b Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Wed, 20 May 2020 10:42:12 -0400 Subject: don't skip log tests unless remote Signed-off-by: Peter Hunt --- test/e2e/logs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go index 1ff53300a..8924db670 100644 --- a/test/e2e/logs_test.go +++ b/test/e2e/logs_test.go @@ -19,7 +19,7 @@ var _ = Describe("Podman logs", func() { ) BeforeEach(func() { - Skip(v2remotefail) + SkipIfRemote() // v2remotefail tempdir, err = CreateTempDirInTempDir() if err != nil { os.Exit(1) -- cgit v1.2.3-54-g00ecf