Skip to content

Commit 4c4cb2c

Browse files
authored
agent: Fix misaligned contextual k/v logging arguments. (#25629)
Arguments passed to hclog log lines should always have an even number to provide the expected k/v output.
1 parent 27caae2 commit 4c4cb2c

File tree

9 files changed

+16
-13
lines changed

9 files changed

+16
-13
lines changed

client/allocrunner/taskrunner/api_hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (h *apiHook) Stop(ctx context.Context, req *interfaces.TaskStopRequest, res
9797
if h.ln != nil {
9898
if err := h.ln.Close(); err != nil {
9999
if !errors.Is(err, net.ErrClosed) {
100-
h.logger.Debug("error closing task listener: %v", err)
100+
h.logger.Debug("error closing task listener", "error", err)
101101
}
102102
}
103103
h.ln = nil

client/allocrunner/taskrunner/dynamic_users_hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (h *dynamicUsersHook) Prestart(_ context.Context, request *interfaces.TaskP
7777
// allocate an unused UID/GID from the pool
7878
ugid, err := h.pool.Acquire()
7979
if err != nil {
80-
h.logger.Error("unable to acquire anonymous UID/GID: %v", err)
80+
h.logger.Error("unable to acquire anonymous UID/GID", "error", err)
8181
return err
8282
}
8383

client/allocrunner/taskrunner/identity_hook.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,13 @@ func (h *identityHook) watchIdentity(wid *structs.WorkloadIdentity, runCh chan s
134134
if signedWID == nil {
135135
// The only way to hit this should be a bug as it indicates the server
136136
// did not sign an identity for a task on this alloc.
137-
h.logger.Error("missing workload identity %q", wid.Name)
137+
h.logger.Error("missing workload identity", "identity", wid.Name)
138138
return
139139
}
140140

141141
if err := h.setAltToken(wid, signedWID.JWT); err != nil {
142-
h.logger.Error(err.Error())
142+
h.logger.Error("failed to set workload identity token",
143+
"identity", wid.Name, "error", err)
143144
}
144145

145146
// Skip ChangeMode on firstRun and notify caller it can proceed
@@ -148,7 +149,8 @@ func (h *identityHook) watchIdentity(wid *structs.WorkloadIdentity, runCh chan s
148149
case runCh <- struct{}{}:
149150
default:
150151
// Not great but not necessarily fatal
151-
h.logger.Warn("task started before identity %q was fetched", wid.Name)
152+
h.logger.Warn("task started before identity was fetched",
153+
"identity", wid.Name)
152154
}
153155

154156
firstRun = false

client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ func (c *Client) restoreState() error {
13331333
allocState, err := c.stateDB.GetAcknowledgedState(alloc.ID)
13341334
if err != nil {
13351335
c.logger.Error("error restoring last acknowledged alloc state, will update again",
1336-
err, "alloc_id", alloc.ID)
1336+
"error", err, "alloc_id", alloc.ID)
13371337
} else {
13381338
ar.AcknowledgeState(allocState)
13391339
}

client/widmgr/widmgr.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ func (m *WIDMgr) Run() error {
121121

122122
hasExpired, err := m.restoreStoredIdentities()
123123
if err != nil {
124-
m.logger.Warn("failed to get signed identities from state DB, refreshing from server: %w", err)
124+
m.logger.Warn("failed to get signed identities from state DB, refreshing from server",
125+
"error", err)
125126
}
126127
if hasExpired {
127128
if err := m.getInitialIdentities(); err != nil {

nomad/job_endpoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,7 @@ func (j *Job) Dispatch(args *structs.JobDispatchRequest, reply *structs.JobDispa
21072107
// Commit this update via Raft
21082108
_, jobCreateIndex, err := j.srv.raftApply(structs.JobRegisterRequestType, regReq)
21092109
if err != nil {
2110-
j.logger.Error("dispatched job register failed", "error")
2110+
j.logger.Error("dispatched job register failed", "error", err)
21112111
return err
21122112
}
21132113

nomad/leader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,7 +2624,7 @@ func (s *Server) initializeKeyring(stopCh <-chan struct{}) {
26242624
store := s.fsm.State()
26252625
key, err := store.GetActiveRootKey(nil)
26262626
if err != nil {
2627-
logger.Error("failed to get active key: %v", err)
2627+
logger.Error("failed to get active key", "error", err)
26282628
return
26292629
}
26302630
if key != nil {
@@ -2653,7 +2653,7 @@ func (s *Server) initializeKeyring(stopCh <-chan struct{}) {
26532653
rootKey, err := structs.NewUnwrappedRootKey(structs.EncryptionAlgorithmAES256GCM)
26542654
rootKey = rootKey.MakeActive()
26552655
if err != nil {
2656-
logger.Error("could not initialize keyring: %v", err)
2656+
logger.Error("could not initialize keyring", "error", err)
26572657
return
26582658
}
26592659

nomad/locks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (s *Server) CreateVariableLockTTLTimer(variable structs.VariableEncrypted)
5757
lock := s.lockTTLTimer.Get(lockID)
5858
if lock != nil {
5959
// If this was to happen, there is a sync issue somewhere else
60-
s.logger.Error("attempting to recreate existing lock: %s", lockID)
60+
s.logger.Error("attempting to recreate existing lock", "lock", lockID)
6161
return
6262
}
6363

@@ -146,7 +146,7 @@ func (s *Server) RemoveVariableLockTTLTimer(variable structs.VariableEncrypted)
146146
lock := s.lockTTLTimer.Get(lockID)
147147
if lock == nil {
148148
// If this was to happen, there is a sync issue somewhere else.
149-
s.logger.Error("attempting to removed missing lock: %s", lockID)
149+
s.logger.Error("attempting to removed missing lock", "lock", lockID)
150150
return
151151
}
152152

scheduler/scheduler_system.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func (s *SystemScheduler) computePlacements(place []allocTuple) error {
362362

363363
node, ok := nodeByID[missing.Alloc.NodeID]
364364
if !ok {
365-
s.logger.Debug("could not find node %q", missing.Alloc.NodeID)
365+
s.logger.Debug("could not find node", "node", missing.Alloc.NodeID)
366366
continue
367367
}
368368

0 commit comments

Comments
 (0)