[sos-devel] [PATCH 1/2] [plugin] allow reverse ordering in add_copy_spec_limit

Sandro Bonazzola sbonazzo at redhat.com
Tue Aug 19 10:56:03 UTC 2014


Il 19/08/2014 12:15, Bryn M. Reeves ha scritto:
> On Tue, Aug 19, 2014 at 11:05:36AM +0200, Sandro Bonazzola wrote:
>> Added parameter to add_copy_spec_limit for allowing
>> to use reverse ordering while collecting files.
>> Without this time-stamped log files will be collected
>> always starting from oldest so most recent logs wasn't
>> in the report.
> 
> I don't really see a need for putting this under the control of the
> caller. The two common methods for marking rotated log files are to
> append a '.' followed by a generation number (e.g. mylog, mylog.1,
> mylog.2 etc.) or to add a '-' followed by a date in ISO 8601 format
> (e.g. alog, alog-20140701, alog-20140707). Both of these formats should
> place the un-rotated (current) log first in normal glob ordering:
> 
>   $ ls a.log* 
>   a.log  a.log-20140816  a.log-20140818
>   $ ls b*
>   b  b.1  b.2  b.3  b.4


A third option is for one-time log file, logging a single execution of a program.
For example, ovirt-hosted-engine-setup (but also ovirt-engine-setup, ovirt-iso-uploader and probably a lot of other commands) generate a log file at
each execution.


> 
> The python interpreter consistently inverts the sort order (on both py2
> & py3 runtimes):
> 
> Python 2.7.5 (default, Jun 25 2014, 10:19:55) 
> [GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import glob
>>>> print glob.glob("a.log*")
> ['a.log-20140816', 'a.log-20140818', 'a.log']
>>>>
> 
> Python 3.3.2 (default, Jun 30 2014, 17:20:03) 
> [GCC 4.8.3 20140624 (Red Hat 4.8.3-1)] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import glob
>>>> print(glob.glob("a.log*"))
> ['a.log-20140816', 'a.log-20140818', 'a.log']
>>>>
> 
> Given that I don't really think the reverse_order kwarg is desirable; I
> don't see a valid use for /not/ setting it. Imho it's better to change
> the default sort ordering for all users (and to be consistent with the
> behaviour of the shell).


Looks like on my system the ordering is not the same you have, not sure how much we can rely on glob ordering.

>> print glob.glob("/var/log/ovirt-hosted-engine-setup/*")
['/var/log/ovirt-hosted-engine-setup/ovirt-hosted-engine-setup-20140819124529-xbjzxo.log',
 '/var/log/ovirt-hosted-engine-setup/ovirt-hosted-engine-setup-20140819124525-rcz7q0.log']

In my case first file included in the archive is the most recent one.
However, in add_copy_spec_limit the result of the glob is sorted by calling sort().

This cause the list created by glob to be reversed:

>>> a = glob.glob("/var/log/ovirt-hosted-engine-setup/*")
>>> a.sort()
>>> print a
['/var/log/ovirt-hosted-engine-setup/ovirt-hosted-engine-setup-20140819124525-rcz7q0.log',
 '/var/log/ovirt-hosted-engine-setup/ovirt-hosted-engine-setup-20140819124529-xbjzxo.log']

In this case, when the size limit is reached collecting the oldest item, the newest one is not added to the archive.

If you don't want to sort by file name, a better way may be sorting by file mtime.


> 
> Regards,
> Bryn.
> 
>> Change-Id: I8dfd0dd3936ae99ea19d975c092a1b275b5e3f4f
>> Signed-off-by: Sandro Bonazzola <sbonazzo at redhat.com>
>> ---
>>  sos/plugins/__init__.py | 7 +++++--
>>  1 file changed, 5 insertions(+), 2 deletions(-)


-- 
Sandro Bonazzola
Better technology. Faster innovation. Powered by community collaboration.
See how it works at redhat.com




More information about the sos-devel mailing list