From 2c182bc041c60d10fccb0862eff7021d9cfe7f48 Mon Sep 17 00:00:00 2001 From: Yusuke Okada Date: Wed, 2 Nov 2022 10:44:37 -0400 Subject: [PATCH] Drop container logs collected from bind-mounted dirs Tripleo implementation mounts /var/log/containers/ directories to /var/log/ in containers. Such paths should be dropped, otherwise such logs are collected multiple times for each containers. When debug is enabled, logs (especially libvirt related logs) become too large to be collected in INFO_DIR. This patch drops paths mounted from the host. Change-Id: Ic6cd058671a5cedf8e94200937ea2bc852caf79c --- roles/collect_logs/files/collect-container-logs.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/roles/collect_logs/files/collect-container-logs.sh b/roles/collect_logs/files/collect-container-logs.sh index 600ffe2..93e1047 100755 --- a/roles/collect_logs/files/collect-container-logs.sh +++ b/roles/collect_logs/files/collect-container-logs.sh @@ -88,7 +88,12 @@ for cont in $(${engine} ps | awk '{print $NF}' | grep -v NAMES); do # using a `logs` volume # NOTE(mandre) Do not copy logs if the containers is bind mounting /var/log directory if ! ${engine} inspect "$cont" | jq .[0].Mounts[].Source | grep -x '"/var/log[/]*"' >/dev/null 2>&1; then - container_cp "$cont" /var/log "$INFO_DIR/log"; + container_cp "$cont" /var/log "$INFO_DIR/log"; + BIND_DESTS=$(${engine} inspect "$cont" | jq .[0].Mounts[].Destination -r) + for path in $(echo "$BIND_DESTS" | grep "^/var/log" | sed -e "s#^/var/log/##g"); do + rm -rf "$INFO_DIR/log/$path" + echo "Omitting $INFO_DIR/log/$path in $cont because it is mounted from the host" + done fi; # Delete symlinks because they break log collection and are generally