Skip to content

Commit d690337

Browse files
noamhofshifilanov
authored andcommitted
chore: reduce journal size by default
Reduce the journal size collection by default to 7 days instead of infinite. And remove the auto collect of all the archives by default Signed-off-by: Noam Hofshi <nhofshi@nvidia.com>
1 parent ea2ad0f commit d690337

5 files changed

Lines changed: 86 additions & 9 deletions

File tree

sos-mlx-cloud-verification.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ skip-plugins = ssh, flatpack, login
3737
# Specify any plugin options and their values here. These options take the form
3838
# plugin_name.option_name = value
3939
#rpm.rpmva = off
40+
# journalctl --since value (systemd.time(7) syntax). Bounds the journal
41+
# capture to the last 7 days here, set to 'all' for an unbounded capture.
42+
logs.journal-since = -7days

sos-nvdebug.conf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
#verify = yes
88
batch = yes
99
log-size = 10
10-
journal_size = 10
10+
journal_size = 50
1111
plugin_timeout = 2000
1212
cmd_timeout = 300
1313
low_priority = True
14-
all_logs = True
1514

1615
[report]
1716
# Options that will apply to any `sos report` run should be listed here.
@@ -39,3 +38,6 @@ only-plugins = openvswitch, rdma, hbn, infiniband, doca, networking, mlx5_core
3938
# Specify any plugin options and their values here. These options take the form
4039
# plugin_name.option_name = value
4140
#rpm.rpmva = off
41+
# journalctl --since value (systemd.time(7) syntax). Bounds the journal
42+
# capture to the last 7 days here, set to 'all' for an unbounded capture.
43+
logs.journal-since = -7days

sos-nvidia.conf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#verify = yes
88
batch = yes
99
log-size = 10
10-
journal_size = 10
10+
# 50 MB per journalctl capture, 7 days of journal text rarely exceeds this
11+
journal_size = 50
1112
plugin_timeout = 2000
1213
cmd_timeout = 300
1314
low_priority = True
14-
all_logs = True
1515

1616
[report]
1717
# Options that will apply to any `sos report` run should be listed here.
@@ -38,3 +38,7 @@ skip-plugins = ssh, flatpack, login
3838
# Specify any plugin options and their values here. These options take the form
3939
# plugin_name.option_name = value
4040
#rpm.rpmva = off
41+
42+
# journalctl --since value (systemd.time(7) syntax). Bounds the journal
43+
# capture to the last 7 days here, set to 'all' for an unbounded capture.
44+
logs.journal-since = -7days

sos/report/plugins/logs.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,31 @@
1010
from sos.report.plugins import Plugin, PluginOpt, IndependentPlugin, CosPlugin
1111

1212

13+
JOURNAL_SINCE_LONG_DESC = (
14+
"Bounds the journalctl text capture by passing the value to "
15+
"`journalctl --since`, which accepts any systemd.time(7) "
16+
"expression (e.g. '-7days', '-24hours', '2 hours ago', "
17+
"'yesterday', '2026-04-19', '2026-04-19 08:00:00'). Use "
18+
"'all' (or leave empty) for no bound. Plugin default 'all', "
19+
"overridden to '-7days' by the bundled conf files. See "
20+
"`man systemd.time` and `man journalctl`."
21+
)
22+
23+
1324
class LogsBase(Plugin):
1425

1526
short_desc = 'System logs'
1627

1728
plugin_name = "logs"
1829
profiles = ('system', 'hardware', 'storage')
1930

31+
option_list = [
32+
PluginOpt(name="journal-since", default="all", val_type=str,
33+
desc=("journalctl --since value, e.g. '-7days', "
34+
"or 'all' for no bound"),
35+
long_desc=JOURNAL_SINCE_LONG_DESC)
36+
]
37+
2038
def setup(self):
2139
rsyslog = 'etc/rsyslog.conf'
2240
confs = ['/etc/syslog.conf', rsyslog]
@@ -56,6 +74,9 @@ def setup(self):
5674
self.add_cmd_output("journalctl --disk-usage")
5775
self.add_dir_listing('/var/log', recursive=True)
5876

77+
since_raw = (self.get_option("journal-since") or "").strip()
78+
since_arg = (None if since_raw.lower() in ("", "all") else since_raw)
79+
5980
# collect journal logs if:
6081
# - there is some data present, either persistent or runtime only
6182
# - systemd-journald service exists
@@ -64,9 +85,11 @@ def setup(self):
6485
for p in ["/var", "/run"])
6586
if journal and self.is_service("systemd-journald"):
6687
self.add_journal(tags=['journal_full', 'journal_all'],
67-
priority=100)
68-
self.add_journal(boot="this", tags='journal_since_boot')
69-
self.add_journal(boot="last", tags='journal_last_boot')
88+
priority=100, since=since_arg)
89+
self.add_journal(boot="this", tags='journal_since_boot',
90+
since=since_arg)
91+
self.add_journal(boot="last", tags='journal_last_boot',
92+
since=since_arg)
7093
if self.get_option("all_logs"):
7194
self.add_copy_spec([
7295
"/var/log/journal/*",
@@ -104,7 +127,7 @@ class IndependentLogs(LogsBase, IndependentPlugin):
104127

105128

106129
class CosLogs(LogsBase, CosPlugin):
107-
option_list = [
130+
option_list = LogsBase.option_list + [
108131
PluginOpt(name="log-days", default=3,
109132
desc="the number of days logs to collect")
110133
]

tests/report_tests/plugin_tests/logs.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LogsPluginTest(StageOneReportTest):
2020
:avocado: tags=stageone
2121
"""
2222

23-
sos_cmd = '-o logs --all-logs'
23+
sos_cmd = '-o logs --all-logs -k logs.journal-since=all'
2424

2525
def test_journalctl_collections(self):
2626
self.assertFileCollected('sos_commands/logs/journalctl_--disk-usage')
@@ -31,6 +31,51 @@ def test_journal_runtime_collected(self):
3131
self.assertFileGlobInArchive('/var/log/journal/*')
3232

3333

34+
class JournalSinceFiniteTest(StageOneReportTest):
35+
"""Ensure a finite `journal-since` value reaches the journalctl
36+
invocation and shows up in the captured filename.
37+
38+
:avocado: tags=stageone
39+
"""
40+
41+
sos_cmd = '-o logs -k logs.journal-since=-24hours'
42+
43+
def test_since_arg_in_journalctl_filename(self):
44+
self.assertFileGlobInArchive(
45+
'sos_commands/logs/journalctl_--no-pager_*--since_-24hours*'
46+
)
47+
48+
49+
class JournalSinceAllTest(StageOneReportTest):
50+
"""Ensure `journal-since=all` disables the time bound, no --since
51+
argument should appear in any journalctl capture filename.
52+
53+
Subclasses re-exercise this assertion against other inputs that
54+
should produce the same outcome (default value, empty string, etc.)
55+
by overriding sos_cmd, see JournalSinceDefaultTest below.
56+
57+
:avocado: tags=stageone
58+
"""
59+
60+
sos_cmd = '-o logs -k logs.journal-since=all'
61+
62+
def test_no_plugin_since_in_journalctl_filename(self):
63+
self.assertFileGlobNotInArchive(
64+
'sos_commands/logs/journalctl_*--since*'
65+
)
66+
67+
68+
class JournalSinceDefaultTest(JournalSinceAllTest):
69+
"""Same expectation as JournalSinceAllTest, exercised via the
70+
plugin default ('all') instead of an explicit -k flag, locks in
71+
the default so a future change to it can't slip through silently.
72+
73+
:avocado: tags=stageone
74+
"""
75+
76+
sos_cmd = '-o logs'
77+
78+
3479
class JournalSizeLimitTest(StageTwoReportTest):
3580
"""Test that journal size limiting is working and is independent of
3681
--log-size

0 commit comments

Comments
 (0)