Skip to content

Commit df047f4

Browse files
authored
perf: Enable compression of audit logs to increase retention, without changing disk space requirements (#1270)
**What problem does this PR solve?**: We enable compression of audit logs. Whenever a log file is rotated, it is compressed. Experiments show that gzip yields a compression factor of approximately 12 for audit logs, so we increase the maximum file size by that factor. With the previous configuration, we had 1 log file of 100MB, and 10 rotated log files of 100MB each, for a total of 1100MB. That's our target disk space requirement. We want to keep this disk space usage, but enable compression. We can't just make the maximum file size larger. For example, if we increase it to 1000MB, then we'll end up with 1 1000MB log, plus 10 compressed, rotated logs of approximately 100MB each, for a total of 2000MB, much higher than our target. To increase retention, we reduce the size of the uncompressed log. We keep --audit-log-maxsize unchanged at 100, but increase --audit-log-maxbackup to 90. We end up with 1 100MB uncompressed log, plus 90 compressed, rotated logs of approximately 10MB each, for a total of 1000MB. That's a little below our target!
1 parent 6fe03f8 commit df047f4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

pkg/handlers/generic/mutation/auditpolicy/inject.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ func (h *auditPolicyPatchHandler) Mutate(
6969
apiServer.ExtraArgs = make(map[string]string, 5)
7070
}
7171

72+
// Originally, we had 1 log of 100MB, and 10 rotated logs of 100MB each, for a total of 1100MB.
73+
// We wanted to increase retention, but keep the total disk usage about the same.
74+
// Now, we have 1 log of 100MB, and 90 compressed, rotated logs of approximately 10MB each,
75+
// for a total of approximately 1000MB.
7276
apiServer.ExtraArgs["audit-log-path"] = "/var/log/audit/kube-apiserver-audit.log"
73-
apiServer.ExtraArgs["audit-log-maxage"] = "30"
74-
apiServer.ExtraArgs["audit-log-maxbackup"] = "10"
75-
apiServer.ExtraArgs["audit-log-maxsize"] = "100"
77+
apiServer.ExtraArgs["audit-log-maxage"] = "30" // Maximum number of days to retain audit log files.
78+
apiServer.ExtraArgs["audit-log-maxbackup"] = "90" // Maximum number of audit log files to retain.
79+
apiServer.ExtraArgs["audit-log-maxsize"] = "100" // Maximum size of log file in MB before it is rotated.
80+
apiServer.ExtraArgs["audit-log-compress"] = "true" // Compress (gzip) audit log file when it is rotated.
7681
apiServer.ExtraArgs["audit-policy-file"] = auditPolicyPath
7782

7883
if apiServer.ExtraVolumes == nil {

pkg/handlers/generic/mutation/auditpolicy/inject_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ var _ = Describe("Generate Audit Policy patches", func() {
4949
gomega.HaveKeyWithValue(
5050
"extraArgs",
5151
map[string]interface{}{
52-
"audit-log-maxbackup": "10",
52+
"audit-log-maxbackup": "90",
5353
"audit-log-maxsize": "100",
5454
"audit-log-path": "/var/log/audit/kube-apiserver-audit.log",
5555
"audit-policy-file": "/etc/kubernetes/audit-policy.yaml",
5656
"audit-log-maxage": "30",
57+
"audit-log-compress": "true",
5758
},
5859
),
5960
gomega.HaveKeyWithValue(

0 commit comments

Comments
 (0)