Skip to content

Commit df6c093

Browse files
committed
workqueue: improve logging (add retry count, misc)
Signed-off-by: Dr. Jan-Philip Gehrcke <[email protected]>
1 parent 73954fe commit df6c093

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/workqueue/workqueue.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ func (q *WorkQueue) EnqueueWithKey(obj any, key string, callback func(ctx contex
140140

141141
q.Lock()
142142
q.activeOps[key] = workItem
143+
// Do we also want to make sure here that a previously enqueued task for
144+
// this key isn't going to be run anymore, if not yet started? Currently,
145+
// the next-scheduled retry attempt is still executed, and business logic is
146+
// hopefully resilient enough.
147+
klog.V(7).Infof("enqueue with key: %s", key)
143148
q.queue.AddRateLimited(workItem)
144149
q.Unlock()
145150
}
@@ -157,16 +162,17 @@ func (q *WorkQueue) processNextWorkItem(ctx context.Context) {
157162
return
158163
}
159164

165+
attempts := q.queue.NumRequeues(item)
160166
err := q.reconcile(ctx, workItem)
161167
if err != nil {
162168
// Most often, this is an expected, retryable error in the context of an
163169
// eventually consistent system. Hence, do not log on an error level. Rely
164170
// on inner business logic to log unexpected errors on an error level.
165-
klog.V(1).Infof("Reconcile: %v", err)
171+
klog.Infof("Reconcile: %v (attempt %d)", err, attempts)
166172
// Only retry if we're still the current operation for this key
167173
q.Lock()
168174
if q.activeOps[workItem.Key] != nil && q.activeOps[workItem.Key] != workItem {
169-
klog.Errorf("Work item with key '%s' has been replaced with a newer enqueued one, not retrying", workItem.Key)
175+
klog.Infof("Do not re-enqueue failed work item with key '%s': a newer item was enqueued", workItem.Key)
170176
q.queue.Forget(workItem)
171177
} else {
172178
q.queue.AddRateLimited(workItem)

0 commit comments

Comments
 (0)