Skip to content

Commit 23ef6c8

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 23ef6c8

3 files changed

Lines changed: 71 additions & 25 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: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ export OMC=${OMC:-true}
88
export OSP_NS="${OSP_NS-openstack}"
99
export OSP_OPERATORS_NS="${OSP_OPERATORS_NS-openstack-operators}"
1010

11-
# This option is used for CI purposes and
12-
# is enabled by default
13-
export SOS_DECOMPRESS=${SOS_DECOMPRESS:-1}
11+
# This option is used for CI purposes and is disabled by default
12+
export SOS_DECOMPRESS=${SOS_DECOMPRESS:-0}
1413
export BASE_COLLECTION_PATH="${BASE_COLLECTION_PATH:-/must-gather}"
1514
export SOS_PATH="${BASE_COLLECTION_PATH}/sos-reports"
1615
export SOS_PATH_NODES="${SOS_PATH}/_all_nodes"
@@ -98,6 +97,66 @@ declare -a OSP_SERVICES=(
9897
export OSP_SERVICES
9998

10099

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

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)