Skip to content

Commit

Permalink
[pod_log] Add new pod_log plugin
Browse files Browse the repository at this point in the history
In Kubernetes/OpenShift rotated logs have no symbolic link in
/var/log/containers and they cannot be retrieved using `oc logs` either,
so there is no way to get these rotated logs in a SOS report.

This patch proposes a new plugin called `pod_log`, similar to the
xisting `container_log`, that can retrieve rotated logs for the
containers.

The plugin will not only download the `/var/log/pods` files but also the
`/var/log/container` symlinks.

The plugin doesn't use the `all_logs` flag, since the usage of the
plugin assumes the intent of getting rotated logs, otherwise the
`container_log` plugin can be used.

An alternative would be to extend the existing `container_log` plugin to
also retrieve rotated container logs.  This approach has been discarded
because we would either have to modify existing behavior for the
`all_logs` flag (breaking backward compatibility) or add a new parser
arguments just to tell it to also gather rotated logs (not reasonable).

Closes #3677
Signed-off-by: Gorka Eguileor <[email protected]>
  • Loading branch information
Akrog committed Jun 17, 2024
1 parent 606bd81 commit e4671de
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions sos/report/plugins/pod_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (C) 2024 Red Hat, Inc.
#
# This file is part of the sos project: https://github.com/sosreport/sos
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# version 2 of the GNU General Public License.
#
# See the LICENSE file in the source distribution for further information.

from sos.report.plugins import IndependentPlugin, Plugin, PluginOpt


class PodLog(Plugin, IndependentPlugin):

short_desc = 'All logs under /var/log/pods'
long_desc = ('Get all the logs from /var/log/pods and also recreate the '
'/var/log/containers symlinks to them. This will get rotated '
'logs in Kubernetes/OpenShift')
plugin_name = 'pod_log'
logdirs = ('/var/log/pods/', '/var/log/containers/')
files = (logdirs[0], )
option_list = [
PluginOpt('anysize', default=False, val_type=bool,
desc='gather all pod logs ignoring size limits'),
PluginOpt('maxage', default=None, val_type=int,
desc='gather only pod logs with `mtime` not older than this '
'many hours')
]

def setup(self):
self.add_copy_spec(
self.logdirs,
sizelimit=0 if self.get_option('anysize') else None,
maxage=self.get_option('maxage'),
)

# vim: set et ts=4 sw=4 :

0 comments on commit e4671de

Please sign in to comment.