Skip to content

Commit

Permalink
chore: Fix changes from buffer provisioner logs (#4924)
Browse files Browse the repository at this point in the history
Comments from #4918 were missed because of auto-merge.
  • Loading branch information
kylecarbs committed Nov 7, 2022
1 parent 3028185 commit 53f2449
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions provisionerd/provisionerd.go
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
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

0 comments on commit 53f2449

Please sign in to comment.