Bug 1771798

Summary: sosreport collects files which are under /var/log/sa/ without 25MB limitation despite no all_sar option
Product: Red Hat Enterprise Linux 8 Reporter: Ryo Hayakawa <rhayakaw>
Component: sosAssignee: Pavel Moravec <pmoravec>
Status: CLOSED ERRATA QA Contact: Miroslav HradĂ­lek <mhradile>
Severity: low Docs Contact:
Priority: unspecified    
Version: 8.0CC: agk, bmr, cww, mhradile, plambri, sbradley
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: 8.0   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: sos-3.9.1-1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-11-04 01:57:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1825061    

Description Ryo Hayakawa 2019-11-13 02:05:41 UTC
Description of problem:

Although there are files with total size of more than 25MB which are under /var/log/sa/ directory, sosreport command collects all the files.
That did not occur on sos-3.6-10.el8.

Version-Release number of selected component (if applicable):
sos-3.7-6.el8_1

Steps to Reproduce:

1. check the existence of files with total size of over 25MB under /var/log/sa/.
    [root@localhost ~]# ls -lh /var/log/sa
    total 33M
    -rw-r--r--. 1 root root 2.6M Nov 12 20:01 sa01
    -rw-r--r--. 1 root root 2.6M Nov 12 20:01 sa02
    -rw-r--r--. 1 root root 2.6M Nov 12 20:01 sa03
    -rw-r--r--. 1 root root 2.6M Nov 12 20:01 sa04
    -rw-r--r--. 1 root root 2.6M Nov 12 20:01 sa05
    -rw-r--r--. 1 root root 2.6M Nov 12 20:01 sa06
    -rw-r--r--. 1 root root 2.6M Nov 12 20:01 sa07
    -rw-r--r--. 1 root root 2.6M Nov 12 20:01 sa08
    -rw-r--r--. 1 root root 2.6M Nov 12 20:01 sa09
    -rw-r--r--. 1 root root 2.6M Nov 12 20:01 sa10
    -rw-r--r--. 1 root root 2.6M Nov 12 20:18 sa11
    -rw-r--r--. 1 root root 2.6M Nov 12 20:31 sa13
    -rw-r--r--. 1 root root 2.6M Nov 12 20:31 sa14
    [root@localhost ~]# 


2. run the sosreport command with --only-plugins=sar
    [root@localhost ~]# sosreport --only-plugins=sar
    
    sosreport (version 3.7)
    
    This command will collect diagnostic and configuration information from
       :(snip)
    Your sosreport has been generated and saved in:
      /var/tmp/sosreport-localhost-2019-11-12-onrresf.tar.xz
       :(snip)

3. check files in the sosreport- archive file.
    [root@localhost ~]# tar tvJf /var/tmp/sosreport-localhost-2019-11-12-onrresf.tar.xz
       :(snip)
    drwxr-xr-x root/root         0 2019-11-12 20:31 sosreport-localhost-2019-11-12-onrresf/var/log/sa/
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa01
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa02
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa03
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa04
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa05
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa06
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa07
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa08
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa09
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa10
    -rw-r--r-- root/root   2636200 2019-11-12 20:18 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa11
    -rw-r--r-- root/root   2636200 2019-11-12 20:31 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa13
    -rw-r--r-- root/root   2636200 2019-11-12 20:31 sosreport-localhost-2019-11-12-onrresf/var/log/sa/sa14
    -rw-r--r-- root/root        31 2019-11-12 20:33 sosreport-localhost-2019-11-12-onrresf/version.txt


Actual results:

As above, the archive file contains the files with total size of over 25MB under /var/log/sa/.


Expected results:

The sosreport command should not include files with total size of over 25MB under /var/log/sa/ like sos-3.6-10.el8.
FYI, the following is result in the case of sos-3.6-10.el8.

    [root@localhost ~]# tar tvJf /var/tmp/sosreport-localhost-2019-11-12-ytxhrol.tar.xz
    drwxr-xr-x root/root         0 2019-11-12 20:40 sosreport-localhost-2019-11-12-ytxhrol/var/log/sa/
    -rw-r--r-- root/root   2636200 2019-11-12 20:31 sosreport-localhost-2019-11-12-ytxhrol/var/log/sa/sa14
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-ytxhrol/var/log/sa/sa10
    -rw-r--r-- root/root      4272 2019-11-12 20:50 sosreport-localhost-2019-11-12-ytxhrol/var/log/sa/sa12
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-ytxhrol/var/log/sa/sa08
    -rw-r--r-- root/root   2636200 2019-11-12 20:18 sosreport-localhost-2019-11-12-ytxhrol/var/log/sa/sa11
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-ytxhrol/var/log/sa/sa09
    -rw-r--r-- root/root   2636200 2019-11-12 20:01 sosreport-localhost-2019-11-12-ytxhrol/var/log/sa/sa07
    -rw-r--r-- root/root   2636200 2019-11-12 20:31 sosreport-localhost-2019-11-12-ytxhrol/var/log/sa/sa13
    -rw-r--r-- root/root        31 2019-11-12 20:53 sosreport-localhost-2019-11-12-ytxhrol/version.txt


Additional info:

I think that the sos-bz1714243-sar-collect-older-data.patch unintentionally causes this issue.
According to the following source code, when the "all_sar" option is not specified, the sizelimit option is passed as None and the the copyspecs is passed as "/var/log/sa" directory to the add_copy_spec().

- sos/plugins/sar.py (sos-3.7-6.el8_1) :
     20     packages = ('sysstat',)
     21     sa_path = '/var/log/sa'
     22     option_list = [("all_sar", "gather all system activity records",
     23                     "", False)]
     24
     25     def setup(self):
     26         self.add_copy_spec(self.sa_path,
     27                            sizelimit=0 if self.get_option("all_sar") else None)
     28
     29         try:
     30             dir_list = os.listdir(self.sa_path)

Then, the copyspecs(="/var/log/sa") is passed to the "_file" variable in the sos/plugins/__init__.py:add_copy_spec() and os.stat() calculates the size of "/var/log/sa" as directory (the 815 line of the sos/plugins/__init__.py).

- sos/plugins/__init__.py:
    810             for _file in files:
    811                 if self._is_forbidden_path(_file):
    812                     self._log_debug("skipping forbidden path '%s'" % _file)
    813                     continue
    814                 try:
    815                     current_size += os.stat(_file)[stat.ST_SIZE]

The size is small because the _file's value is not file but directory (54 bytes in my environment). It causes unlimited collection of files of /var/log/sa/* despite no "all_sar" option.

Our customer would like to have this problem fixed.
I kindly ask for your confirmation

Regards,

Comment 1 Pavel Moravec 2019-11-13 06:56:50 UTC
A known (upstream) issue: https://github.com/sosreport/sos/issues/1750

Specifically for sar, one can code-workaround it via 

        self.add_copy_spec(self.sa_path+"/*",

is sar.py (not a clean fix, though).

Comment 2 Pavel Moravec 2020-04-13 13:40:19 UTC
Will appear in RHEL8.3 as:
- the fix in https://github.com/sosreport/sos/issues/1863 is in sos-3.9.1
- 8.3 should rebase sos to 3.9-1 or future 4.0

Comment 9 errata-xmlrpc 2020-11-04 01:57:52 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (sos bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2020:4534