summaryrefslogtreecommitdiff
path: root/test/system
diff options
context:
space:
mode:
authorNiall Crowe <nicrowe@redhat.com>2022-02-25 09:25:30 +0000
committerNiall Crowe <nicrowe@redhat.com>2022-04-14 09:35:29 +0100
commit3da3afa5764bcec2d50b219446579b5770051f32 (patch)
tree66b2319d84d1eac23169b131ddbb96a6e9c3c4b6 /test/system
parent15712c76fb198cec7509ff0cf401e357401d2d7d (diff)
downloadpodman-3da3afa5764bcec2d50b219446579b5770051f32.tar.gz
podman-3da3afa5764bcec2d50b219446579b5770051f32.tar.bz2
podman-3da3afa5764bcec2d50b219446579b5770051f32.zip
Add log rotation based on log size
Add new functions to logfile.go for rotating and truncating the events log file once the log file and its contents exceed the maximum size limit while keeping 50% of the log file's content Also add tests to verify log rotation and truncation Signed-off-by: Niall Crowe <nicrowe@redhat.com> Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
Diffstat (limited to 'test/system')
-rw-r--r--test/system/090-events.bats65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/system/090-events.bats b/test/system/090-events.bats
index a0b0380a2..cac0a177c 100644
--- a/test/system/090-events.bats
+++ b/test/system/090-events.bats
@@ -129,3 +129,68 @@ EOF
run cat $events_file
is "$output" ".*\"Name\":\"$IMAGE" "test"
}
+
+function _populate_events_file() {
+ # Create 100 duplicate entries to populate the events log file.
+ local events_file=$1
+ truncate --size=0 $events_file
+ for i in {0..99}; do
+ printf '{"Name":"busybox","Status":"pull","Time":"2022-04-06T11:26:42.7236679%02d+02:00","Type":"image","Attributes":null}\n' $i >> $events_file
+ done
+}
+
+@test "events log-file rotation" {
+ skip_if_remote "setting CONTAINERS_CONF logger options does not affect remote client"
+
+ # Make sure that the events log file is (not) rotated depending on the
+ # settings in containers.conf.
+
+ # Config without a limit
+ eventsFile=$PODMAN_TMPDIR/events.txt
+ _populate_events_file $eventsFile
+ containersConf=$PODMAN_TMPDIR/containers.conf
+ cat >$containersConf <<EOF
+[engine]
+events_logger="file"
+events_logfile_path="$eventsFile"
+EOF
+
+ # Create events *without* a limit and make sure that it has not been
+ # rotated/truncated.
+ contentBefore=$(head -n100 $eventsFile)
+ CONTAINERS_CONF=$containersConf run_podman run --rm $IMAGE true
+ contentAfter=$(head -n100 $eventsFile)
+ is "$contentBefore" "$contentAfter" "events file has not been rotated"
+
+ # Repopulate events file
+ rm $eventsFile
+ _populate_events_file $eventsFile
+
+ # Config with a limit
+ rm $containersConf
+ cat >$containersConf <<EOF
+[engine]
+events_logger="file"
+events_logfile_path="$eventsFile"
+# The limit of 4750 is the *exact* half of the inital events file.
+events_logfile_max_size=4750
+EOF
+
+ # Create events *with* a limit and make sure that it has been
+ # rotated/truncated. Once rotated, the events file should only contain the
+ # second half of its previous events plus the new ones.
+ expectedContentAfterTruncation=$PODMAN_TMPDIR/truncated.txt
+
+ run_podman create $IMAGE
+ CONTAINERS_CONF=$containersConf run_podman rm $output
+ tail -n52 $eventsFile >> $expectedContentAfterTruncation
+
+ # Make sure the events file looks as expected.
+ is "$(cat $eventsFile)" "$(cat $expectedContentAfterTruncation)" "events file has been rotated"
+
+ # Make sure that `podman events` can read the file, and that it returns the
+ # same amount of events. We checked the contents before.
+ CONTAINERS_CONF=$containersConf run_podman events --stream=false --since="2022-03-06T11:26:42.723667984+02:00"
+ is "$(wc -l <$eventsFile)" "$(wc -l <<<$output)" "all events are returned"
+ is "${lines[-2]}" ".* log-rotation $eventsFile"
+}