Skip to content

Commit 8b4f009

Browse files
committed
log provisionerd connection info conditionally
1 parent 56f1535 commit 8b4f009

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
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+
ExternalProvisioner: true,
243244
})
244245

245246
waitForProvisionerJobs := false

provisionerd/provisionerd.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Options struct {
5656
TracerProvider trace.TracerProvider
5757
Metrics *Metrics
5858

59+
ExternalProvisioner bool
5960
ForceCancelInterval time.Duration
6061
UpdateInterval time.Duration
6162
LogBufferInterval time.Duration
@@ -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+
externalProvisioner: opts.ExternalProvisioner,
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+
externalProvisioner bool
146149
}
147150

148151
type Metrics struct {
@@ -212,6 +215,10 @@ func NewMetrics(reg prometheus.Registerer) Metrics {
212215
func (p *Server) connect() {
213216
defer p.opts.Logger.Debug(p.closeContext, "connect loop exited")
214217
defer p.wg.Done()
218+
logConnect := p.opts.Logger.Debug
219+
if p.externalProvisioner {
220+
logConnect = p.opts.Logger.Info
221+
}
215222
// An exponential back-off occurs when the connection is failing to dial.
216223
// This is to prevent server spam in case of a coderd outage.
217224
connectLoop:
@@ -239,7 +246,13 @@ connectLoop:
239246
p.opts.Logger.Warn(p.closeContext, "coderd client failed to dial", slog.Error(err))
240247
continue
241248
}
242-
p.opts.Logger.Info(p.closeContext, "successfully connected to coderd")
249+
// This log is useful to verify that an external provisioner daemon is
250+
// successfully connecting to coderd. It doesn't add much value if the
251+
// daemon is built-in, so we only log it on the info level if p.externalProvisioner
252+
// is true. This log message is mentioned in the docs:
253+
// https://github.com/coder/coder/blob/5bd86cb1c06561d1d3e90ce689da220467e525c0/docs/admin/provisioners.md#L346
254+
logConnect(p.closeContext, "successfully connected to coderd")
255+
retrier.Reset()
243256
retrier.Reset()
244257
p.initConnectionOnce.Do(func() {
245258
close(p.initConnectionCh)
@@ -252,7 +265,7 @@ connectLoop:
252265
client.DRPCConn().Close()
253266
return
254267
case <-client.DRPCConn().Closed():
255-
p.opts.Logger.Info(p.closeContext, "connection to coderd closed")
268+
logConnect(p.closeContext, "connection to coderd closed")
256269
continue connectLoop
257270
case p.clientCh <- client:
258271
continue

provisionersdk/serve.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ type ServeOptions struct {
2525
// Listener serves multiple connections. Cannot be combined with Conn.
2626
Listener net.Listener
2727
// Conn is a single connection to serve. Cannot be combined with Listener.
28-
Conn drpc.Transport
29-
Logger slog.Logger
30-
WorkDirectory string
28+
Conn drpc.Transport
29+
Logger slog.Logger
30+
WorkDirectory string
31+
ExternalProvisioner bool
3132
}
3233

3334
type Server interface {

0 commit comments

Comments
 (0)