Skip to content

Commit 9a14ad0

Browse files
committed
log provisionerd connection info conditionally
1 parent 56f1535 commit 9a14ad0

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

enterprise/cli/provisionerdaemonstart.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,11 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
236236
ProvisionerKey: provisionerKey,
237237
})
238238
}, &provisionerd.Options{
239-
Logger: logger,
240-
UpdateInterval: 500 * time.Millisecond,
241-
Connector: connector,
242-
Metrics: metrics,
239+
Logger: logger,
240+
UpdateInterval: 500 * time.Millisecond,
241+
Connector: connector,
242+
Metrics: metrics,
243+
IsExternalProvisioner: true,
243244
})
244245

245246
waitForProvisionerJobs := false

provisionerd/provisionerd.go

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ type Options struct {
5656
TracerProvider trace.TracerProvider
5757
Metrics *Metrics
5858

59-
ForceCancelInterval time.Duration
60-
UpdateInterval time.Duration
61-
LogBufferInterval time.Duration
62-
Connector Connector
63-
InitConnectionCh chan struct{} // only to be used in tests
59+
IsExternalProvisioner bool
60+
ForceCancelInterval time.Duration
61+
UpdateInterval time.Duration
62+
LogBufferInterval time.Duration
63+
Connector Connector
64+
InitConnectionCh chan struct{} // only to be used in tests
6465
}
6566

6667
// New creates and starts a provisioner daemon.
@@ -97,12 +98,13 @@ func New(clientDialer Dialer, opts *Options) *Server {
9798
clientDialer: clientDialer,
9899
clientCh: make(chan proto.DRPCProvisionerDaemonClient),
99100

100-
closeContext: ctx,
101-
closeCancel: ctxCancel,
102-
closedCh: make(chan struct{}),
103-
shuttingDownCh: make(chan struct{}),
104-
acquireDoneCh: make(chan struct{}),
105-
initConnectionCh: opts.InitConnectionCh,
101+
closeContext: ctx,
102+
closeCancel: ctxCancel,
103+
closedCh: make(chan struct{}),
104+
shuttingDownCh: make(chan struct{}),
105+
acquireDoneCh: make(chan struct{}),
106+
initConnectionCh: opts.InitConnectionCh,
107+
isExternalProvisioner: opts.IsExternalProvisioner,
106108
}
107109

108110
daemon.wg.Add(2)
@@ -141,8 +143,9 @@ type Server struct {
141143
// shuttingDownCh will receive when we start graceful shutdown
142144
shuttingDownCh chan struct{}
143145
// acquireDoneCh will receive when the acquireLoop exits
144-
acquireDoneCh chan struct{}
145-
activeJob *runner.Runner
146+
acquireDoneCh chan struct{}
147+
activeJob *runner.Runner
148+
isExternalProvisioner bool
146149
}
147150

148151
type Metrics struct {
@@ -239,7 +242,16 @@ connectLoop:
239242
p.opts.Logger.Warn(p.closeContext, "coderd client failed to dial", slog.Error(err))
240243
continue
241244
}
242-
p.opts.Logger.Info(p.closeContext, "successfully connected to coderd")
245+
// This log is useful to verify that an external provisioner daemon is
246+
// successfully connecting to coderd. It doesn't add much value if the
247+
// daemon is built-in, so we only log it on the info level if isExternalProvisioner
248+
// is true. This log message is mentioned in the docs:
249+
// https://github.com/coder/coder/blob/5bd86cb1c06561d1d3e90ce689da220467e525c0/docs/admin/provisioners.md#L346
250+
if p.isExternalProvisioner {
251+
p.opts.Logger.Info(p.closeContext, "successfully connected to coderd")
252+
} else {
253+
p.opts.Logger.Debug(p.closeContext, "successfully connected to coderd")
254+
}
243255
retrier.Reset()
244256
p.initConnectionOnce.Do(func() {
245257
close(p.initConnectionCh)
@@ -252,7 +264,11 @@ connectLoop:
252264
client.DRPCConn().Close()
253265
return
254266
case <-client.DRPCConn().Closed():
255-
p.opts.Logger.Info(p.closeContext, "connection to coderd closed")
267+
if p.isExternalProvisioner {
268+
p.opts.Logger.Info(p.closeContext, "connection to coderd closed")
269+
} else {
270+
p.opts.Logger.Debug(p.closeContext, "connection to coderd closed")
271+
}
256272
continue connectLoop
257273
case p.clientCh <- client:
258274
continue

0 commit comments

Comments
 (0)