From f23dbbaf368ce69d1b6ff024a22d9e6da596ac65 Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Wed, 19 Jun 2024 15:58:28 +0200 Subject: [PATCH] [container_log] Add rotated logs support 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 extending the `container_log` plugin to make it also capable of retrieving rotated logs from `var/log/pods` using a plugin boolean option called `rotated`. Closes #3677 Signed-off-by: Gorka Eguileor --- sos/report/plugins/container_log.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sos/report/plugins/container_log.py b/sos/report/plugins/container_log.py index 98d9637ace..1373e2aa87 100644 --- a/sos/report/plugins/container_log.py +++ b/sos/report/plugins/container_log.py @@ -9,7 +9,7 @@ # See the LICENSE file in the source distribution for further information. import os -from sos.report.plugins import Plugin, IndependentPlugin +from sos.report.plugins import Plugin, IndependentPlugin, PluginOpt class ContainerLog(Plugin, IndependentPlugin): @@ -17,18 +17,27 @@ class ContainerLog(Plugin, IndependentPlugin): short_desc = 'All logs under /var/log/containers' plugin_name = 'container_log' logdir = '/var/log/containers/' + poddir = '/var/log/pods/' + rotated_dirs = [poddir + '*/*.log.*', poddir + '*/*/*.log.*'] files = (logdir, ) + option_list = [ + PluginOpt('rotated', default=False, val_type=bool, + desc='also get rotated logs from /var/log/pods'), + ] + def setup(self): if self.get_option('all_logs'): self.add_copy_spec(self.logdir) + self.add_copy_spec(self.rotated_dirs) else: - self.collect_subdirs() + self.collect_subdirs(self.logdir, '*.log') + self.collect_subdirs(self.poddir, '*.log.*') - def collect_subdirs(self, root=logdir): + def collect_subdirs(self, root, glob): """Collect *.log files from subdirs of passed root path """ for dir_name, _, _ in os.walk(root): - self.add_copy_spec(self.path_join(dir_name, '*.log')) + self.add_copy_spec(self.path_join(dir_name, glob)) # vim: set et ts=4 sw=4 :