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

Subscribers

People subscribed via source and target branches

to all changes: