Skip to content

Conversation

@dlipovetsky
Copy link
Contributor

@dlipovetsky dlipovetsky commented Aug 25, 2025

What problem does this PR solve?:
Given our disk space requirements (about 1GB), the audit logs hold about 1-2 hours. By enabling compression, we can increase this by a factor of 12, i.e. 12-24 hours.

In this PR, 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. We expect disk space requirements to remain the same.

Which issue(s) this PR fixes:
Fixes #

How Has This Been Tested?:

Special notes for your reviewer:

fluent-bit should continue to work, because it supports reading log files compressed using gzip as of fluent/fluent-bit#8585, released in https://github.com/fluent/fluent-bit/releases/tag/v3.0.0.

However, I need to verify this!

@dlipovetsky
Copy link
Contributor Author

With the current configuration, we have 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.

# ls -1sh /host/var/log/kubernetes/audit/
total 1.1G
101M kube-apiserver-audit-2025-09-09T17-41-04.279.log
100M kube-apiserver-audit-2025-09-09T17-50-31.236.log
101M kube-apiserver-audit-2025-09-09T18-00-13.040.log
100M kube-apiserver-audit-2025-09-09T18-10-03.179.log
101M kube-apiserver-audit-2025-09-09T18-20-22.732.log
100M kube-apiserver-audit-2025-09-09T18-30-21.178.log
101M kube-apiserver-audit-2025-09-09T18-40-33.055.log
100M kube-apiserver-audit-2025-09-09T18-52-45.786.log
100M kube-apiserver-audit-2025-09-09T19-04-47.481.log
100M kube-apiserver-audit-2025-09-09T19-16-32.832.log
100M kube-apiserver-audit.log

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 should reduce the size of the uncompressed log. For example, we could keep audit-log-maxsize unchanged at 100, but increase audit-log-maxbackup to 90. Then we would 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!

@dlipovetsky dlipovetsky force-pushed the dlipovetsky/audit-logs-compress branch from 4e92564 to 55978d5 Compare September 9, 2025 20:40
@dlipovetsky dlipovetsky marked this pull request as ready for review September 9, 2025 20:42
@dlipovetsky dlipovetsky requested a review from dkoshkin September 9, 2025 20:53
Copy link
Contributor

@dkoshkin dkoshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dlipovetsky dlipovetsky force-pushed the dlipovetsky/audit-logs-compress branch from 55978d5 to a904f0b Compare September 9, 2025 23:25
@dlipovetsky dlipovetsky changed the title perf: Enable compression of audit logs, and increase max file size perf: Enable compression of audit logs to increase retention, without changing disk space requirements Sep 10, 2025
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!
@dlipovetsky dlipovetsky force-pushed the dlipovetsky/audit-logs-compress branch from a904f0b to 5910b9c Compare September 10, 2025 15:34
@dlipovetsky dlipovetsky enabled auto-merge (squash) September 10, 2025 15:37
@dlipovetsky dlipovetsky merged commit df047f4 into main Sep 10, 2025
22 checks passed
@dlipovetsky dlipovetsky deleted the dlipovetsky/audit-logs-compress branch September 10, 2025 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants