log/sockstatlog: limit sockstat logs to 5 MB

Updates tailscale/corp#9230

Signed-off-by: Will Norris <will@tailscale.com>
This commit is contained in:
Will Norris 2023-04-12 15:17:37 -07:00 committed by Will Norris
parent 9e50da321b
commit bb34589748
1 changed files with 10 additions and 1 deletions

View File

@ -35,6 +35,12 @@ const pollInterval = time.Second / 10
// which itself creates additional sockstat events.
const logInterval = 3 * time.Second
// maxLogFileSize specifies the maximum size of a log file before it is rotated.
// Our logs are fairly compact, and we are mostly only looking at a few hours of data.
// Combined with the fact that these are often uploaded over cellular connections,
// we keep this relatively small.
const maxLogFileSize = 5 << 20 // 5 MB
// Logger logs statistics about network sockets.
type Logger struct {
// enabled identifies whether the logger is enabled.
@ -95,7 +101,10 @@ func NewLogger(logdir string, logf logger.Logf, logID logid.PublicID) (*Logger,
return nil, err
}
filchPrefix := filepath.Join(logdir, "sockstats")
filch, err := filch.New(filchPrefix, filch.Options{ReplaceStderr: false})
filch, err := filch.New(filchPrefix, filch.Options{
MaxFileSize: maxLogFileSize,
ReplaceStderr: false,
})
if err != nil {
return nil, err
}