Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions provisionerd/provisionerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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,
)
Expand Down
6 changes: 5 additions & 1 deletion provisionerd/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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{
Expand Down