Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[container_log] Get rotated logs #3678

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions sos/report/plugins/container_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,37 @@
# 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):

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'),
]
Comment on lines +24 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed this on a second pass, but I'm assuming this should be dropped with the intent being that the rotated logs are collected by -k container_log.all-logs=true once #3681 is merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm stupid, you are right.
This PR is changing existing behavior and it's adding a plugin option that is not being used.
I'll make the rotated log gathering conditional to the rotated plugin option.


def setup(self):
if self.get_option('all_logs'):
self.add_copy_spec(self.logdir)
if self.get_option('rotated'):
self.add_copy_spec(self.rotated_dirs)
else:
self.collect_subdirs()
self.collect_subdirs(self.logdir, '*.log')
if self.get_option('rotated'):
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 :
Loading