50 Commits

Author SHA1 Message Date
6348778348 libpod: log file use Wait() over event API
Using the internal Wait() API over the events API as this is much more
efficient. Reading events will need to read a lot of data otherwise.

For the function here it should work fine and it is even better as it
does not depend on the event logger at all.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-01 18:53:08 +01:00
72f1617fac Bump Go module to v5
Moving from Go module v4 to v5 prepares us for public releases.

Move done using gomove [1] as with the v3 and v4 moves.

[1] https://github.com/KSubedi/gomove

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-02-08 09:35:39 -05:00
2a2d0b0e18 chore: delete obsolete // +build lines
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-04 11:53:38 +02:00
bad25da92e libpod: add !remote tag
This should never be pulled into the remote client.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-10-24 12:11:34 +02:00
29273cda10 lint: fix warnings found by perfsprint
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-10-20 16:27:46 +02:00
a55c2636de file logger: fix podman logs --tail with partial lines
There is a problem where our tail code does not handles correctly
partial log lines. This makes podman logs --tail output possibly
incorrect lines when k8s-file is used.

This manifests as flake in CI because partial lines are only sometimes
written, basically always when the output is flushed before writing a
newline.

For our code we must not count partial lines which was already done but
the important thing we must keep reading backwards until the next full
(F) line. This is because all partial (P) lines still must be added to
the full line. See the added tests for details on how the log file looks
like.

While fixing this, I rework the tail logic a bit, there is absolutely no
reason to read the lines in a separate goroutine just to pass the lines
back via channel. We can do this in the same routine.
The logic is very simple, read the lines backwards, append lines to
result and then at the end invert the result slice as tail must return
the lines in the correct order. This more efficient then having to
allocate two different slices or to prepend the line as this would
require a new allocation for each line.

Lastly the readFromLogFile() function wrote the lines back to the log
line channel in the same routine as the log lines we read, this was bad
and causes a deadlock when the returned lines are bigger than the
channel size. There is no reason to allocate a big channel size we can
just write the log lines in a different goroutine, in this case the main
routine were read the logs anyway.

A new system test and unit tests have been added to check corner cases.

Fixes #19545

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-08-09 14:48:01 +02:00
b5ce0ab2de Fix language, typos and markdown layout
[NO NEW TESTS NEEDED]

Signed-off-by: Erik Sjölund <erik.sjolund@gmail.com>
2023-07-24 11:18:25 +02:00
79a05ca2b4 podman logs passthrough driver support --cgroups=split
When run with --cgroups=split mode (e.g. quadlet) we do not use the a
separate cgroup for the container and just run in the unit cgroup.
When we filter logs we thus must match the unit name.
Added a small test to the quadlet test to make sure it will work.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-02-20 13:58:16 +01:00
1590c7bf42 podman logs: read journald with passthrough
The passthrough driver is designed for use in systemd units. By default
we can expect systemd to log the output on journald unless the unit sets
differen StandardOutput/StandardError settings.

At the moment podman logs just errors out when the passthrough driver is
used. With this change we will read the journald for the unit messages.
The logic is actually very similar to the existing one, we just need to
change the filter. We now filter by SYSTEMD_UNIT wich equals to the
contianer cgroup, this allows us the actually filter on a per contianer
basis even when multiple contianers are started in the same unit, i.e.
via podman-kube@.service.

The only difference a user will see is that journald will merge
stdout/err into one stream so we loose the separation there.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-02-20 13:58:12 +01:00
6038200fe0 k8s-file: podman logs --until --follow exit after time
When you use podman logs with --until and --follow it should exit after
the requested until time and not keep hanging forever.

This fixes the behavior for the k8s-file backend.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-01-06 15:19:23 +01:00
4e72aa5860 fix goroutine leaks in events and logs backend
When running a single podman logs this is not really important since we
will exit when we finish reading the logs. However for the system
service this is very important. Leaking goroutines will cause an
increased memory and CPU ussage over time.

Both the the event and log backend have goroutine leaks with both the
file and journald drivers.

The journald backend has the problem that journal.Wait(IndefiniteWait)
will block until we get a new journald event. So when a client closes
the connection the goroutine would still wait until there is a new
journal entry. To fix this we just wait for a maximum of 5 seconds,
after that we can check if the client connection was closed and exit
correctly in this case.

For the file backend we can fix this by waiting for either the log line
or context cancel at the same time. Currently it would block waiting for
new log lines and only check afterwards if the client closed the
connection and thus hang forever if there are no new log lines.

[NO NEW TESTS NEEDED] I am open to ideas how we can test memory leaks in
CI.
To test manually run a container like this:
`podman run --log-driver $driver  --name test -d alpine sh -c 'i=1; while [ "$i" -ne 1000 ]; do echo "line $i"; i=$((i + 1)); done; sleep inf'`
where `$driver` can be either `journald` or `k8s-file`.
Then start the podman system service and use:
`curl -m 1 --output -  --unix-socket $XDG_RUNTIME_DIR/podman/podman.sock -v 'http://d/containers/test/logs?follow=1&since=0&stderr=1&stdout=1' &>/dev/null`
to get the logs from the API and then it closes the connection after 1 second.
Now run the curl command several times and check the memory usage of the service.

Fixes #14879

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-07-20 12:55:34 +02:00
251d91699d libpod: switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of
the deprecated github.com/pkg/errors package.

[NO NEW TESTS NEEDED]

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-05 16:06:32 +02:00
2414586662 podman logs k8s-file: do not reassemble partial log lines
The backend should not convert partial lines to full log lines. While
this works for most cases it cannot work when the last line is partial
since it will just be lost. The frontend logic can already display
partial lines correctly. The journald driver also works correctly since
it does not such conversion.

Fixes #14458

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-06-03 15:01:23 +02:00
c185d8c0d6 Add option for pod logs to display different colors per container.
Signed-off-by: Krzysztof Baran <krysbaran@gmail.com>
Signed-off-by: gcalin <caling@protonmail.com>
2022-03-29 17:29:13 +02:00
21502987b2 replace hpcloud/tail with nxadm/tail
The hpcloud is not maintained anymore.  nxadm is already part of the
dependency chain, so it won't add work for downstream packages.

While testing upcoming changes to the events-file backend, I noticed
that nxadm is shipping required fixes.

[NO NEW TESTS NEEDED]

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-29 13:35:37 +02:00
bd09b7aa79 bump go module to version 4
Automated for .go files via gomove [1]:
`gomove github.com/containers/podman/v3 github.com/containers/podman/v4`

Remaining files via vgrep [2]:
`vgrep github.com/containers/podman/v3`

[1] https://github.com/KSubedi/gomove
[2] https://github.com/vrothberg/vgrep

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2022-01-18 12:47:07 +01:00
3ce98a5ec2 logging: new mode -l passthrough
it allows to pass the current std streams down to the container.

conmon support: https://github.com/containers/conmon/pull/289

[NO TESTS NEEDED] it needs a new conmon.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-27 12:07:01 +02:00
1c4e6d8624 standardize logrus messages to upper case
Remove ERROR: Error stutter from logrus messages also.

[ NO TESTS NEEDED] This is just code cleanup.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-09-22 15:29:34 -04:00
1eaa449590 logs -f: file: fix dead lock
Fix a dead lock in the file log driver where one goroutine would wait on
the tail to hit EOF but reading is blocked for the function to return.

Fixes: 11461
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-09-07 12:46:56 +02:00
16dfce486b Podman info output plugin information
For docker compat include information about available volume, log and
network drivers which should be listed under the plugins key.

Fixes #11265

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-08-19 17:33:20 +02:00
4624142c2d Implemented Until Query Parameter for Containers/logs
compat containers/logs was missing actual usage of until query param.

fixes #10859

Signed-off-by: cdoern <cdoern@redhat.com>
2021-07-09 12:21:46 -04:00
ee4cab0e09 logs: k8s-file: restore poll sleep
Commit 84b55eec2796 attempted to fix a race waiting for the container
died event.  Previously, Podman slept for duration of the polling
frequence which I considerred to be a mistake.  As it turns out, I was
mistaken since the file logger will, in fact, NOT read until EOF and
then stop logging but stop logging immediately _after_ it woke up.

[NO TESTS NEEDED] as the race condition cannot be hit reliably.

Fixes: #10675
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-21 15:44:13 +02:00
f4ba433b18 logs: k8s-file: fix spurious error logs
Fix the suprious "Error: nil" messages.  Also add some more context to
logged error messages which makes error sources more obvious.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-21 14:11:27 +02:00
84b55eec27 logs: k8s-file: fix race
Fix a race in the k8s-file logs driver.  When "following" the logs,
Podman will print the container's logs until the end.  Previously,
Podman logged until the state transitioned into something non-running
which opened up a race with the container still running, possibly in
the "stopping" state.

To fix the race, log until we've seen the wait event for the specific
container.  In that case, conmon will have finished writing all logs to
the file, and Podman will read it until EOF.

Further tweak the integration tests for testing `logs -f` on a  running
container.  Previously, the test only checked for one of two lines
stating that there was a race.  Indeed the race was in using `run --rm`
where a log file may be removed before we could fully read it.

Fixes: #10596
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-08 16:14:13 +02:00
b19791c0b6 Tidy duplicate log tests
Some log tests were duplicated, and some didn't need to be repeated for
every driver. Also, added some comments

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-03-02 14:28:16 -05:00
5dded6fae7 bump go module to v3
We missed bumping the go module, so let's do it now :)

* Automated go code with github.com/sirkon/go-imports-rename
* Manually via `vgrep podman/v2` the rest

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-22 09:03:51 +01:00
b7f699c199 Fix podman logs read partial log lines
If a partial log line has the length 1 it was ignored by podman logs.

Fixes #8879

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-01-07 00:04:38 +01:00
4fa1fce930 Spelling
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-12-22 13:34:31 -05:00
a5e37ad280 Switch all references to github.com/containers/libpod -> podman
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-28 08:23:45 -04:00
09dc77aedf log API: add context to allow for cancelling
Add a `context.Context` to the log APIs to allow for cancelling
streaming (e.g., via `podman logs -f`).  This fixes issues for
the remote API where some go routines of the server will continue
writing and produce nothing but heat and waste CPU cycles.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-09 15:13:07 +02:00
8489dc4345 move go module to v2
With the advent of Podman 2.0.0 we crossed the magical barrier of go
modules.  While we were able to continue importing all packages inside
of the project, the project could not be vendored anymore from the
outside.

Move the go module to new major version and change all imports to
`github.com/containers/libpod/v2`.  The renaming of the imports
was done via `gomove` [1].

[1] https://github.com/KSubedi/gomove

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-06 15:50:12 +02:00
8926e1f03b Use POLL_DURATION for timer
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-21 09:31:22 -07:00
78dd4f2ecb Stop following logs using timers
This incorporates code from PR #6591 and #6614 but does not use
event channels to detect container state and rather uses timers
with a defined wait duration before calling t.StopAtEOF() to
ensure the last log entry is output before a container exits.

The polling interval is set to 250 milliseconds based on polling
interval defined in hpcloud/tail here:
https://github.com/hpcloud/tail/blob/v1.0.0/watch/polling.go#L117

Co-authored-by: Qi Wang <qiwan@redhat.com>
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-20 09:48:55 -07:00
7b00e49f65 Merge pull request #6560 from mheon/fix_exec_logdriver
Do not share container log driver for exec
2020-06-17 17:17:27 -04:00
03e99c9b40 Revert #6591 to fix issue with failed tests
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-17 08:31:09 -07:00
0e171b7b33 Do not share container log driver for exec
When the container uses journald logging, we don't want to
automatically use the same driver for its exec sessions. If we do
we will pollute the journal (particularly in the case of
healthchecks) with large amounts of undesired logs. Instead,
force exec sessions logs to file for now; we can add a log-driver
flag later (we'll probably want to add a `podman logs` command
that reads exec session logs at the same time).

As part of this, add support for the new 'none' logs driver in
Conmon. It will be the default log driver for exec sessions, and
can be optionally selected for containers.

Great thanks to Joe Gooch (mrwizard@dok.org) for adding support
to Conmon for a null log driver, and wiring it in here.

Fixes #6555

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-17 11:11:46 -04:00
6d9863e773 Remove redundant break in for loop.
Remove redundant `break` call in for loop.

Co-authored-by: Qi Wang <qiwan@redhat.com>
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-15 07:42:05 -07:00
d514e3c097 Do not print error message when container does not exist
This fixes a condition when a container is removed while
following the logs and prints an error when the container
is removed forcefully.

Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-12 12:59:58 -07:00
e714352501 Changed from t.StopAtEOF() to t.Stop() and added error check
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-12 11:10:08 -07:00
9ac115e691 Fix -f logs to stop when a container exits
Fixes an issue with the previous PR where a container would exit while following logs and the log tail continued to follow. This creates a subroutine which checks the state of the container and instructs the tailLog to stop when it reaches EOF.

Tested the following conditions:
* Tail and follow logs of running container
* Tail and follow logs of stopped container
* Tail and follow logs of running container which exits after some time

Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-12 10:14:35 -07:00
033743cbee Fix -f logs follow with stopped container
Fix -f logs follow with stopped container. Close #6531

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-06-11 17:55:26 -04:00
86ffa552d2 Fixed bug where 'podman log <container>' would truncate some lines.
Signed-off-by: Will Haines <william.haines@colorado.edu>
2020-06-10 15:08:48 -06:00
ba430bfe5e podman v2 remove bloat v2
rid ourseleves of libpod references in v2 client

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-04-16 12:04:46 -05:00
8561b99644 libpod removal from main (phase 2)
this is phase 2 for the removal of libpod from main.

Signed-off-by: baude <bbaude@redhat.com>
2019-06-27 07:56:24 -05:00
88429242dd Add --follow to journald ctr logging
Signed-off-by: Peter Hunt <pehunt@redhat.com>
2019-05-28 11:14:08 -04:00
51bdf29f04 Address comments
Signed-off-by: Peter Hunt <pehunt@redhat.com>
2019-05-28 11:10:57 -04:00
02f971131a Implement podman logs with log-driver journald
Add a journald reader that translates the journald entry to a k8s-file formatted line, to be added as a log line

Note: --follow with journald hasn't been implemented. It's going to be a larger undertaking that can wait.

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2019-05-28 11:10:57 -04:00
f61fa28d39 Added --log-driver and journald logging
Signed-off-by: Peter Hunt <pehunt@redhat.com>
2019-05-28 11:10:57 -04:00
46f18764f2 podman logs on created container should exit
when running podman logs on a created container (which has no logs),
podman should return gracefully (like docker) with a 0 return code. if
multiple containers are provided and one is only in the created state
(and no follow is used), we still display the logs for the other ids.

fixes issue #2677

Signed-off-by: baude <bbaude@redhat.com>
2019-03-18 08:58:48 -05:00
5e86acd591 display logs for multiple containers at the same time
add the ability for users to specify more than one container at a time
while using podman logs.  If more than one container is being displayed,
podman will also prepend a shortened container id of the container on
the log line.

also, enabled the podman-remote logs command during the refactoring of
the above ability.

fixes issue #2219

Signed-off-by: baude <bbaude@redhat.com>
2019-03-15 13:41:01 -05:00