mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 13:18:53 +00:00
logpolicy: expose MaxBufferSize and MaxUploadSize options (#14903)
Updates tailscale/corp#26342 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
@@ -503,6 +503,18 @@ type Options struct {
|
||||
// If nil, [TransportOptions.New] is used to construct a new client
|
||||
// with that particular transport sending logs to the default logs server.
|
||||
HTTPC *http.Client
|
||||
|
||||
// MaxBufferSize is the maximum size of the log buffer.
|
||||
// This controls the amount of logs that can be temporarily stored
|
||||
// before the logs can be successfully upload.
|
||||
// If zero, a default buffer size is chosen.
|
||||
MaxBufferSize int
|
||||
|
||||
// MaxUploadSize is the maximum size per upload.
|
||||
// This should only be set by clients that have been authenticated
|
||||
// with the logging service as having a higher upload limit.
|
||||
// If zero, a default upload size is chosen.
|
||||
MaxUploadSize int
|
||||
}
|
||||
|
||||
// New returns a new log policy (a logger and its instance ID).
|
||||
@@ -603,10 +615,11 @@ func (opts Options) New() *Policy {
|
||||
}
|
||||
|
||||
conf := logtail.Config{
|
||||
Collection: newc.Collection,
|
||||
PrivateID: newc.PrivateID,
|
||||
Stderr: logWriter{console},
|
||||
CompressLogs: true,
|
||||
Collection: newc.Collection,
|
||||
PrivateID: newc.PrivateID,
|
||||
Stderr: logWriter{console},
|
||||
CompressLogs: true,
|
||||
MaxUploadSize: opts.MaxUploadSize,
|
||||
}
|
||||
if opts.Collection == logtail.CollectionNode {
|
||||
conf.MetricsDelta = clientmetric.EncodeLogTailMetricsDelta
|
||||
@@ -620,7 +633,7 @@ func (opts Options) New() *Policy {
|
||||
} else {
|
||||
// Only attach an on-disk filch buffer if we are going to be sending logs.
|
||||
// No reason to persist them locally just to drop them later.
|
||||
attachFilchBuffer(&conf, opts.Dir, opts.CmdName, opts.Logf)
|
||||
attachFilchBuffer(&conf, opts.Dir, opts.CmdName, opts.MaxBufferSize, opts.Logf)
|
||||
conf.HTTPC = opts.HTTPC
|
||||
|
||||
if conf.HTTPC == nil {
|
||||
@@ -676,9 +689,10 @@ func (opts Options) New() *Policy {
|
||||
// attachFilchBuffer creates an on-disk ring buffer using filch and attaches
|
||||
// it to the logtail config. Note that this is optional; if no buffer is set,
|
||||
// logtail will use an in-memory buffer.
|
||||
func attachFilchBuffer(conf *logtail.Config, dir, cmdName string, logf logger.Logf) {
|
||||
func attachFilchBuffer(conf *logtail.Config, dir, cmdName string, maxFileSize int, logf logger.Logf) {
|
||||
filchOptions := filch.Options{
|
||||
ReplaceStderr: redirectStderrToLogPanics(),
|
||||
MaxFileSize: maxFileSize,
|
||||
}
|
||||
filchPrefix := filepath.Join(dir, cmdName)
|
||||
|
||||
|
Reference in New Issue
Block a user