Skip to content

Commit 53f2449

Browse files
authored
chore: Fix changes from buffer provisioner logs (#4924)
Comments from #4918 were missed because of auto-merge.
1 parent 3028185 commit 53f2449

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

provisionerd/provisionerd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Options struct {
5050

5151
ForceCancelInterval time.Duration
5252
UpdateInterval time.Duration
53-
LogDebounceInterval time.Duration
53+
LogBufferInterval time.Duration
5454
PollInterval time.Duration
5555
Provisioners Provisioners
5656
WorkDirectory string
@@ -67,8 +67,8 @@ func New(clientDialer Dialer, opts *Options) *Server {
6767
if opts.ForceCancelInterval == 0 {
6868
opts.ForceCancelInterval = time.Minute
6969
}
70-
if opts.LogDebounceInterval == 0 {
71-
opts.LogDebounceInterval = 50 * time.Millisecond
70+
if opts.LogBufferInterval == 0 {
71+
opts.LogBufferInterval = 50 * time.Millisecond
7272
}
7373
if opts.Filesystem == nil {
7474
opts.Filesystem = afero.NewOsFs()
@@ -329,7 +329,7 @@ func (p *Server) acquireJob(ctx context.Context) {
329329
provisioner,
330330
p.opts.UpdateInterval,
331331
p.opts.ForceCancelInterval,
332-
p.opts.LogDebounceInterval,
332+
p.opts.LogBufferInterval,
333333
p.tracer,
334334
p.opts.Metrics.Runner,
335335
)

provisionerd/runner/runner.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,9 @@ func (r *Runner) startTrace(ctx context.Context, name string, opts ...trace.Span
898898
))...)
899899
}
900900

901+
// queueLog adds a log to the buffer and debounces a timer
902+
// if one exists to flush the logs. It stores a maximum of
903+
// 100 log lines before flushing as a safe-guard mechanism.
901904
func (r *Runner) queueLog(ctx context.Context, log *proto.Log) {
902905
r.mutex.Lock()
903906
defer r.mutex.Unlock()
@@ -906,6 +909,7 @@ func (r *Runner) queueLog(ctx context.Context, log *proto.Log) {
906909
r.flushLogsTimer.Reset(r.logBufferInterval)
907910
return
908911
}
912+
// This can be configurable if there are a ton of logs.
909913
if len(r.queuedLogs) > 100 {
910914
// Flushing logs requires a lock, so this can happen async.
911915
go r.flushQueuedLogs(ctx)
@@ -921,7 +925,7 @@ func (r *Runner) flushQueuedLogs(ctx context.Context) {
921925
if r.flushLogsTimer != nil {
922926
r.flushLogsTimer.Stop()
923927
}
924-
logs := r.queuedLogs[:]
928+
logs := r.queuedLogs
925929
r.queuedLogs = make([]*proto.Log, 0)
926930
r.mutex.Unlock()
927931
_, err := r.update(ctx, &proto.UpdateJobRequest{

0 commit comments

Comments
 (0)