Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3d8b77d

Browse files
authored
chore: improve clarity of the agent logs (#6345)
I looked through these logs when debugging and there was a bit of spam!
1 parent ec6f78d commit 3d8b77d

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

agent/agent.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (a *agent) runLoop(ctx context.Context) {
156156
go a.reportLifecycleLoop(ctx)
157157

158158
for retrier := retry.New(100*time.Millisecond, 10*time.Second); retrier.Wait(ctx); {
159-
a.logger.Info(ctx, "running loop")
159+
a.logger.Info(ctx, "connecting to coderd")
160160
err := a.run(ctx)
161161
// Cancel after the run is complete to clean up any leaked resources!
162162
if err == nil {
@@ -169,7 +169,7 @@ func (a *agent) runLoop(ctx context.Context) {
169169
return
170170
}
171171
if errors.Is(err, io.EOF) {
172-
a.logger.Info(ctx, "likely disconnected from coder", slog.Error(err))
172+
a.logger.Info(ctx, "disconnected from coderd")
173173
continue
174174
}
175175
a.logger.Warn(ctx, "run exited with error", slog.Error(err))
@@ -197,7 +197,7 @@ func (a *agent) reportLifecycleLoop(ctx context.Context) {
197197
break
198198
}
199199

200-
a.logger.Debug(ctx, "post lifecycle state", slog.F("state", state))
200+
a.logger.Debug(ctx, "reporting lifecycle state", slog.F("state", state))
201201

202202
err := a.client.PostLifecycle(ctx, agentsdk.PostLifecycleRequest{
203203
State: state,
@@ -242,7 +242,7 @@ func (a *agent) run(ctx context.Context) error {
242242
if err != nil {
243243
return xerrors.Errorf("fetch metadata: %w", err)
244244
}
245-
a.logger.Info(ctx, "fetched metadata")
245+
a.logger.Info(ctx, "fetched metadata", slog.F("metadata", metadata))
246246

247247
// Expand the directory and send it back to coderd so external
248248
// applications that rely on the directory can use it.
@@ -330,13 +330,10 @@ func (a *agent) run(ctx context.Context) error {
330330
go NewWorkspaceAppHealthReporter(
331331
a.logger, metadata.Apps, a.client.PostAppHealth)(appReporterCtx)
332332

333-
a.logger.Debug(ctx, "running tailnet with derpmap", slog.F("derpmap", metadata.DERPMap))
334-
335333
a.closeMutex.Lock()
336334
network := a.network
337335
a.closeMutex.Unlock()
338336
if network == nil {
339-
a.logger.Debug(ctx, "creating tailnet")
340337
network, err = a.createTailnet(ctx, metadata.DERPMap)
341338
if err != nil {
342339
return xerrors.Errorf("create tailnet: %w", err)
@@ -385,10 +382,9 @@ func (a *agent) run(ctx context.Context) error {
385382
network.SetDERPMap(metadata.DERPMap)
386383
}
387384

388-
a.logger.Debug(ctx, "running coordinator")
385+
a.logger.Debug(ctx, "running tailnet connection coordinator")
389386
err = a.runCoordinator(ctx, network)
390387
if err != nil {
391-
a.logger.Debug(ctx, "coordinator exited", slog.Error(err))
392388
return xerrors.Errorf("run coordinator: %w", err)
393389
}
394390
return nil
@@ -474,7 +470,9 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (_
474470
for {
475471
conn, err := reconnectingPTYListener.Accept()
476472
if err != nil {
477-
logger.Debug(ctx, "accept pty failed", slog.Error(err))
473+
if !a.isClosed() {
474+
logger.Debug(ctx, "accept pty failed", slog.Error(err))
475+
}
478476
break
479477
}
480478
wg.Add(1)
@@ -529,7 +527,9 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (_
529527
for {
530528
conn, err := speedtestListener.Accept()
531529
if err != nil {
532-
a.logger.Debug(ctx, "speedtest listener failed", slog.Error(err))
530+
if !a.isClosed() {
531+
a.logger.Debug(ctx, "speedtest listener failed", slog.Error(err))
532+
}
533533
break
534534
}
535535
wg.Add(1)
@@ -600,7 +600,7 @@ func (a *agent) runCoordinator(ctx context.Context, network *tailnet.Conn) error
600600
return err
601601
}
602602
defer coordinator.Close()
603-
a.logger.Info(ctx, "connected to coordination server")
603+
a.logger.Info(ctx, "connected to coordination endpoint")
604604
sendNodes, errChan := tailnet.ServeCoordinator(coordinator, func(nodes []*tailnet.Node) error {
605605
return network.UpdateNodes(nodes, false)
606606
})
@@ -646,7 +646,6 @@ func (a *agent) runStartupScript(ctx context.Context, script string) error {
646646
}
647647

648648
func (a *agent) init(ctx context.Context) {
649-
a.logger.Info(ctx, "generating host key")
650649
// Clients' should ignore the host key when connecting.
651650
// The agent needs to authenticate with coderd to SSH,
652651
// so SSH authentication doesn't improve security.

0 commit comments

Comments
 (0)