Skip to content

Commit 7b0f28f

Browse files
fmountclaude
andcommitted
Avoid recompressing already-compressed SOS archives
When SOS_DECOMPRESS=0, SOS reports are kept as .tar.xz files. The previous archiving step ran a single XZ pass over everything, redundantly recompressing them with no size benefit and significant time cost. This patch extracts the archiving logic into a compress() function that is the very last step of the gathering process. When SOS_DECOMPRESS=0 (and SOS data is present), it only compresses non-SOS data into an intermediate XZ archive, then it bundles it with the SOS tarballs into a plain tar. Default SOS_DECOMPRESS to 0 to better match this workflow and to save time: for large environments decompress a big amount of sos reports might take a lot of time and resources. Jira: https://redhat.atlassian.net/browse/OSPRH-32765 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Francesco Pantano <fpantano@redhat.com>
1 parent a8a9ff2 commit 7b0f28f

3 files changed

Lines changed: 70 additions & 23 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,14 @@ This is the list of available environmental variables:
9393
default (and preserves the default behavior required in a production environment).
9494
However, if set to 1, it dumps secrets and services config files without masking
9595
sensitive data.
96+
- `SOS_DECOMPRESS`: 0 or 1. When set to 1, SOS reports are extracted after
97+
download. When set to 0 (default), they are kept as `.tar.xz` archives and
98+
the final archiving step avoids recompressing them: non-SOS data is compressed
99+
separately and bundled with the SOS archives into a plain `must-gather.tar`.
100+
When set to 1 or when no SOS reports are collected, the final archive is a
101+
single `must-gather.tar.xz` as before.
96102
- `COMPRESSED_PATH`: defines the path to store the compressed form of the
97-
gathered data
103+
gathered data.
98104
- `DELETE_AFTER_COMPRESSION`: 0 or 1. When set to 1 the uncompressed data is
99105
deleted after the archive is created. Defaulted to 0.
100106
- `SUPPORT_TOOLS`: The OpenShift support-tools container image. It allows to

collection-scripts/common.sh

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export OSP_OPERATORS_NS="${OSP_OPERATORS_NS-openstack-operators}"
1010

1111
# This option is used for CI purposes and
1212
# is enabled by default
13-
export SOS_DECOMPRESS=${SOS_DECOMPRESS:-1}
13+
export SOS_DECOMPRESS=${SOS_DECOMPRESS:-0}
1414
export BASE_COLLECTION_PATH="${BASE_COLLECTION_PATH:-/must-gather}"
1515
export SOS_PATH="${BASE_COLLECTION_PATH}/sos-reports"
1616
export SOS_PATH_NODES="${SOS_PATH}/_all_nodes"
@@ -98,6 +98,66 @@ declare -a OSP_SERVICES=(
9898
export OSP_SERVICES
9999

100100

101+
# Archive the collected data into a single downloadable file.
102+
# When SOS_DECOMPRESS=0, SOS reports are kept as .tar.xz archives and
103+
# recompressing them with XZ produces no size reduction while adding
104+
# significant time. In that case, non-SOS data is compressed separately
105+
# into an intermediate XZ archive, then bundled with the already-compressed
106+
# SOS files into a plain tar.
107+
# Otherwise (SOS_DECOMPRESS=1 or no SOS reports), a single XZ pass over
108+
# everything is used.
109+
function compress {
110+
# The path to store the compressed result
111+
local compressed_path=${COMPRESSED_PATH:-"${BASE_COLLECTION_PATH}"}
112+
# whether to delete or keep the uncompressed files.
113+
# Defaults to keep them.
114+
local delete_after=${DELETE_AFTER_COMPRESSION:-0}
115+
local archive
116+
117+
if [[ ${SOS_DECOMPRESS} -eq 0 ]] && \
118+
[[ -n "$(find "${SOS_PATH}" -type f 2>/dev/null | head -1)" ]]; then
119+
archive="${compressed_path}/must-gather.tar"
120+
local rhoso_archive="${compressed_path}/rhoso-data.tar.xz"
121+
122+
# Compress only non-SOS data (CRDs, CMs, logs, DB dumps) into an
123+
# intermediate XZ archive, excluding the SOS directory entirely.
124+
tar \
125+
--exclude='must-gather.tar' \
126+
--exclude='rhoso-data.tar.xz' \
127+
--exclude='sos-reports' \
128+
--warning=no-file-changed --ignore-failed \
129+
-cJf \
130+
"${rhoso_archive}" "${BASE_COLLECTION_PATH}" || true
131+
132+
# Bundle the intermediate archive with the SOS reports into a plain
133+
# tar (no compression) so already-compressed SOS data is not re-processed.
134+
tar \
135+
--exclude='must-gather.tar' \
136+
--warning=no-file-changed --ignore-failed \
137+
-cf \
138+
"${archive}" "${rhoso_archive}" "${SOS_PATH}" || true
139+
140+
rm -f "${rhoso_archive}"
141+
else
142+
archive="${compressed_path}/must-gather.tar.xz"
143+
144+
tar \
145+
--exclude='must-gather.tar.xz' \
146+
--warning=no-file-changed --ignore-failed \
147+
-cJf \
148+
"${archive}" "${BASE_COLLECTION_PATH}" || true
149+
fi
150+
151+
echo "The ${archive} now can be attached to the support case."
152+
153+
if [[ ${delete_after} -eq 1 ]]; then
154+
find "${BASE_COLLECTION_PATH}" \
155+
-mindepth 1 \
156+
-not -path "*must-gather.tar*" \
157+
-delete
158+
fi
159+
}
160+
101161
WEBHOOKS_COLLECTION_PATH=${BASE_COLLECTION_PATH}/webhooks
102162
export WEBHOOKS_COLLECTION_PATH
103163

collection-scripts/gather_run

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,5 @@ wait_bg
7474
source "${DIR_NAME}/gather_version"
7575
log_version
7676

77-
# The path to store the compressed result
78-
export COMPRESSED_PATH=${COMPRESSED_PATH:-"${BASE_COLLECTION_PATH}"}
79-
# whether to delete or keep the uncompressed files.
80-
# Defaults to keep them.
81-
export DELETE_AFTER_COMPRESSION=${DELETE_AFTER_COMPRESSION:-0}
82-
83-
# create an easy to download tar.xz from the whole content
84-
archive="${COMPRESSED_PATH}/must-gather.tar.xz"
85-
86-
tar \
87-
--exclude='must-gather.tar.xz' \
88-
--warning=no-file-changed --ignore-failed \
89-
-cJf \
90-
"${archive}" "${BASE_COLLECTION_PATH}" || true
91-
92-
echo "The ${archive} now can be attached to the support case."
93-
94-
if [[ ${DELETE_AFTER_COMPRESSION} -eq 1 ]]; then
95-
find "${BASE_COLLECTION_PATH}" \
96-
-mindepth 1 -not -path "*must-gather.tar.xz*" -delete
97-
fi
77+
# Compress and archive the collected data
78+
compress

0 commit comments

Comments
 (0)