Merge ~xavpaice/charm-logrotated:lp1955751 into charm-logrotated:master

Proposed by Xav Paice
Status: Rejected
Rejected by: Haw Loeung
Proposed branch: ~xavpaice/charm-logrotated:lp1955751
Merge into: charm-logrotated:master
Diff against target: 77 lines (+50/-1)
2 files modified
src/config.yaml (+10/-0)
src/reactive/logrotate.py (+40/-1)
Reviewer Review Type Date Requested Status
Xav Paice (community) Needs Fixing
🤖 prod-jenkaas-bootstack (community) continuous-integration Needs Fixing
BootStack Reviewers mr tracking; do not claim Pending
BootStack Reviewers Pending
BootStack Reviewers Pending
Canonical IS Reviewers Pending
Review via email: mp+416447@code.launchpad.net

This proposal supersedes a proposal from 2021-12-30.

Commit message

Added optional rotation of Juju unit/machine files

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : Posted in a previous version of this proposal

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : Posted in a previous version of this proposal

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
Xav Paice (xavpaice) wrote :

resubmitted after a rebase, in order to retrigger CI

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Paul Goins (vultaire) wrote :

To consider: https://bugs.launchpad.net/juju/+bug/1078213
(Juju *does* have *some* rotation... but it seems unclear that there's any cut-off...)

Revision history for this message
Xav Paice (xavpaice) wrote :

Needs lint fixes to pass CI

review: Needs Fixing

Unmerged commits

c34b224... by Paul Goins

Added optional rotation of Juju unit/machine files

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/config.yaml b/src/config.yaml
2index 813c7ce..0a65312 100644
3--- a/src/config.yaml
4+++ b/src/config.yaml
5@@ -35,3 +35,13 @@ options:
6 Mind the quotes for JSON properties/values!
7 Valid options for rotate: any integer value
8 Valid options for interval: 'daily', 'weekly', 'monthly', 'yearly'
9+ enable-juju-unit-rotation:
10+ type: boolean
11+ default: False
12+ description: |
13+ Enable rotation of /var/log/juju/unit-*.log files.
14+ enable-juju-machine-rotation:
15+ type: boolean
16+ default: False
17+ description: |
18+ Enable rotation of /var/log/juju/machine-*.log files.
19diff --git a/src/reactive/logrotate.py b/src/reactive/logrotate.py
20index 119ac96..adb301e 100644
21--- a/src/reactive/logrotate.py
22+++ b/src/reactive/logrotate.py
23@@ -1,7 +1,9 @@
24 """Reactive charm hooks."""
25+import os
26+
27 from charmhelpers.core import hookenv
28
29-from charms.reactive import set_flag, when, when_not
30+from charms.reactive import set_flag, when, when_any, when_not
31
32 from lib_cron import CronHelper
33
34@@ -27,6 +29,43 @@ def install_logrotate():
35 hookenv.status_set("active", "Unit is ready.")
36 set_flag("logrotate.installed")
37
38+@when_any("config.changed.enable-juju-unit-rotation", "config.changed.enable-juju-machine-rotation")
39+def install_juju_rotation_files():
40+ """Install log rotation files for Juju."""
41+
42+ # Rather than just rotating on /var/log/juju/* (as audit.log can be very useful on
43+ # Juju controllers with longer history), I think we should break this apart into different
44+ # groups:
45+ #
46+ # * unit logs (probably highest benefit in rotating)
47+ # * machine and machine lock logs (lower benefit)
48+ # * audit log (could be beneficial, but probably preferable not to rotate at the same cadence
49+ # as everything else)
50+
51+ for log_type, enabled in (
52+ ("unit", hookenv.config("enable-juju-unit-rotation")),
53+ ("machine", hookenv.config("enable-juju-machine-rotation")),
54+ # Note: intentionally skipping audit log rotation in favor of keeping longer audit logs
55+ # for investigating issues.
56+ ):
57+ filename = "/etc/logrotate.d/juju_{}s".format(log_type)
58+ if enabled:
59+ with open(filename, "w") as config_file:
60+ # Install a base file. This will be further customized by the charm later.
61+ config_file.write("""\
62+/var/log/juju/{}-*.log
63+{{
64+ missingok
65+ daily
66+ copytruncate
67+ rotate 7
68+ notifempty
69+}}
70+""".format(log_type))
71+ else:
72+ if os.path.exists(filename):
73+ os.unlink(filename)
74+
75
76 @when("config.changed")
77 def config_changed():

Subscribers

People subscribed via source and target branches

to all changes: