From 8938136179f922d1271e73ef57a977a6c5f2636d Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Mon, 4 Nov 2024 10:31:17 -0800 Subject: [PATCH] Configure native Gerrit log rotation and cleanup Prior to Gerrit 3.10 Gerrit would automatically rotate and compress log files; however, it would not delete them. With Gerrit 3.10 you can now configure a time to keep value for rotated log files and Gerrit will delete files older than the keep value. Explicitly configure log compression and rotation to true (these are the defaults but being explicit here makes sense to me if setting time to keep) and add a 30 day timeToKeep value. This matches our current Gerrit log pruning cronjob retention period of 30 days. Landing this under Gerrit 3.9 should be safe then when we upgrade to 3.10 we can remove our cronjob and rely on Gerrit to do this for us. Note that cleanup happens in Gerrit at midnight and our cronjob runs at 0600. These should be separated by enough time that we can safely have both running after the upgrade. Change-Id: I4219e48c1fab5da97f80130d45badb759af680a1 --- playbooks/roles/gerrit/tasks/main.yaml | 2 ++ playbooks/roles/gerrit/templates/gerrit.config.j2 | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/playbooks/roles/gerrit/tasks/main.yaml b/playbooks/roles/gerrit/tasks/main.yaml index ba443a882b..db7a8c400b 100644 --- a/playbooks/roles/gerrit/tasks/main.yaml +++ b/playbooks/roles/gerrit/tasks/main.yaml @@ -349,6 +349,8 @@ # Gerrit rotates their own logs, but doesn't clean them out # Delete logs older than a month +# TODO set state to absent then remove entirely after we upgrade to +# Gerrit 3.10 and set log.timeToKeep to do this rotation natively. - name: Set up cron job to clean old gerrit logs cron: name: clear-gerrit-logs diff --git a/playbooks/roles/gerrit/templates/gerrit.config.j2 b/playbooks/roles/gerrit/templates/gerrit.config.j2 index 759a7c68a7..b989115a8d 100644 --- a/playbooks/roles/gerrit/templates/gerrit.config.j2 +++ b/playbooks/roles/gerrit/templates/gerrit.config.j2 @@ -42,6 +42,10 @@ javaHome = /usr/lib/jvm/java-17-openjdk-amd64 javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance" javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance" +[log] + rotate = true + compress = true + timeToKeep = 30d [gc] [core] packedGitOpenFiles = {{ gerrit_packed_git_open_files }}