This PR adds support for rotating file outputs, similar to log rotation. In our internal use of gnmic I have written some scripts to replay production events logged from the file output into a development environment so that we can reproduce bugs and do some load testing. Whenever I needed a production dump I would restart gnmic with a file output enabled for an hour or so and then grab the file and roll back to our previous configuration.
This option enables us to limit the disk space and just keep the last 3x 100MB files available on our k8s nodes should we need to grab them to replay or troubleshoot. No behavior is changed if not using the rotating file-type.
You can specify the file-type as rotating and then supply the following configuration to configure the rotation parameters:
rotation:
max-size: 100 # size in megabytes
max-age: 30 # max age in days
max-backups: 3 # maximum number of old files to store, not counting the current file
compress: false # whether or not to enable compression
This uses the lumberjack package in Go to handle the rotation when enabled.
To support this I've converted the File.file from an *os.File to a new file interface that is satisfied by the new rotatingFile struct. This allowed me to add the new behavior without modifying any of the existing logic.
Let me know if you have any comments or concerns about this!
This PR adds support for rotating file outputs, similar to log rotation. In our internal use of gnmic I have written some scripts to replay production events logged from the
file
output into a development environment so that we can reproduce bugs and do some load testing. Whenever I needed a production dump I would restart gnmic with a file output enabled for an hour or so and then grab the file and roll back to our previous configuration.This option enables us to limit the disk space and just keep the last 3x 100MB files available on our k8s nodes should we need to grab them to replay or troubleshoot. No behavior is changed if not using the
rotating
file-type.You can specify the file-type as
rotating
and then supply the following configuration to configure the rotation parameters:This uses the
lumberjack
package in Go to handle the rotation when enabled.To support this I've converted the
File.file
from an*os.File
to a newfile
interface that is satisfied by the newrotatingFile
struct. This allowed me to add the new behavior without modifying any of the existing logic.Let me know if you have any comments or concerns about this!