diff --git a/provisionerd/provisionerd.go b/provisionerd/provisionerd.go index feb0637c62f3e..f631f27208094 100644 --- a/provisionerd/provisionerd.go +++ b/provisionerd/provisionerd.go @@ -50,7 +50,7 @@ type Options struct { ForceCancelInterval time.Duration UpdateInterval time.Duration - LogDebounceInterval time.Duration + LogBufferInterval time.Duration PollInterval time.Duration Provisioners Provisioners WorkDirectory string @@ -67,8 +67,8 @@ func New(clientDialer Dialer, opts *Options) *Server { if opts.ForceCancelInterval == 0 { opts.ForceCancelInterval = time.Minute } - if opts.LogDebounceInterval == 0 { - opts.LogDebounceInterval = 50 * time.Millisecond + if opts.LogBufferInterval == 0 { + opts.LogBufferInterval = 50 * time.Millisecond } if opts.Filesystem == nil { opts.Filesystem = afero.NewOsFs() @@ -329,7 +329,7 @@ func (p *Server) acquireJob(ctx context.Context) { provisioner, p.opts.UpdateInterval, p.opts.ForceCancelInterval, - p.opts.LogDebounceInterval, + p.opts.LogBufferInterval, p.tracer, p.opts.Metrics.Runner, ) diff --git a/provisionerd/runner/runner.go b/provisionerd/runner/runner.go index dc4fd63954cd3..d32d5c8853162 100644 --- a/provisionerd/runner/runner.go +++ b/provisionerd/runner/runner.go @@ -898,6 +898,9 @@ func (r *Runner) startTrace(ctx context.Context, name string, opts ...trace.Span ))...) } +// queueLog adds a log to the buffer and debounces a timer +// if one exists to flush the logs. It stores a maximum of +// 100 log lines before flushing as a safe-guard mechanism. func (r *Runner) queueLog(ctx context.Context, log *proto.Log) { r.mutex.Lock() defer r.mutex.Unlock() @@ -906,6 +909,7 @@ func (r *Runner) queueLog(ctx context.Context, log *proto.Log) { r.flushLogsTimer.Reset(r.logBufferInterval) return } + // This can be configurable if there are a ton of logs. if len(r.queuedLogs) > 100 { // Flushing logs requires a lock, so this can happen async. go r.flushQueuedLogs(ctx) @@ -921,7 +925,7 @@ func (r *Runner) flushQueuedLogs(ctx context.Context) { if r.flushLogsTimer != nil { r.flushLogsTimer.Stop() } - logs := r.queuedLogs[:] + logs := r.queuedLogs r.queuedLogs = make([]*proto.Log, 0) r.mutex.Unlock() _, err := r.update(ctx, &proto.UpdateJobRequest{