Skip to content

Commit e7a48da

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

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-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: 22 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,12 @@ 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")
243255
retrier.Reset()
244256
p.initConnectionOnce.Do(func() {
245257
close(p.initConnectionCh)
@@ -252,7 +264,7 @@ connectLoop:
252264
client.DRPCConn().Close()
253265
return
254266
case <-client.DRPCConn().Closed():
255-
p.opts.Logger.Info(p.closeContext, "connection to coderd closed")
267+
logConnect(p.closeContext, "connection to coderd closed")
256268
continue connectLoop
257269
case p.clientCh <- client:
258270
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy