Skip to content

Commit ea8aa62

Browse files
TurboTurtlepmoravec
authored andcommitted
[collect] Do not compress top-level collector archive
Previously, when running `sos collect`, the resulting archive that contained sos report archives, would itself be compressed. This "top level" compression did not actually gain us much, but did have a time penalty to overall collect execution times. This commit solves this by allowing a `None` value to be used for the compression method when calling `Archive.finalize()`, which will skip compressing that archive. The actual sos reports that a collect execution captures are still compressed. Note: this "none" option is not currently exposed on the CLI, and all sos reports will still be compressed. Resolves: sosreport#3992 Signed-off-by: Jake Hunsaker <jacob.r.hunsaker@gmail.com>
1 parent 8b7a333 commit ea8aa62

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

sos/archive.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -726,18 +726,24 @@ def name(self):
726726
return f"{self._archive_root}.{self._suffix}"
727727

728728
def _build_archive(self, method):
729+
_mode = 'w'
729730
if method == 'auto':
730731
method = 'xz' if find_spec('lzma') is not None else 'gzip'
731-
_comp_mode = method.strip('ip')
732-
self._archive_name = f"{self._archive_name}.{_comp_mode}"
732+
if method is not None:
733+
_comp_mode = method.strip('ip')
734+
self._archive_name = f"{self._archive_name}.{_comp_mode}"
735+
self._suffix += f".{_comp_mode}"
736+
_mode = f"w:{_comp_mode}"
733737
# tarfile does not currently have a consistent way to define comnpress
734738
# level for both xz and gzip ('preset' for xz, 'compresslevel' for gz)
735-
if method == 'gzip':
736-
kwargs = {'compresslevel': 6}
737-
else:
738-
kwargs = {'preset': 3}
739-
with tarfile.open(self._archive_name, mode=f"w:{_comp_mode}",
740-
**kwargs) as tar:
739+
kwargs = {
740+
None: {},
741+
'gzip': {'compresslevel': 6},
742+
'xz': {'preset': 3}
743+
}
744+
with tarfile.open(self._archive_name,
745+
mode=_mode,
746+
**kwargs[method]) as tar:
741747
# Add commonly reviewed files first, so that they can be more
742748
# easily read from memory without needing to extract
743749
# the whole archive
@@ -751,7 +757,6 @@ def _build_archive(self, method):
751757
# want the names used in the archive to be relative.
752758
tar.add(self._archive_root, arcname=self._name,
753759
filter=self.copy_permissions_filter)
754-
self._suffix += f".{_comp_mode}"
755760
return self.name()
756761

757762

sos/collector/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ def create_cluster_archive(self):
14171417
short_name='manifest.json'
14181418
)
14191419

1420-
arc_name = self.archive.finalize(self.opts.compression_type)
1420+
arc_name = self.archive.finalize(method=None)
14211421
final_name = os.path.join(self.sys_tmp, os.path.basename(arc_name))
14221422
if do_clean:
14231423
final_name = cleaner.obfuscate_string(

0 commit comments

Comments
 (0)