Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ type Agent struct {

cacheRefreshInterval time.Duration
informerSyncTimeout time.Duration
clusterCache *appstatecache.Cache
// applicationInformerEventBufferInterval is the minimum time between processing
// Application informer update callbacks for the same object (e.g. only send
// Application .status update once every 10 seconds)
applicationInformerEventBufferInterval time.Duration
clusterCache *appstatecache.Cache

inflightMu sync.Mutex
// inflightLogs blocks starting a duplicate stream for the same request UUID (esp. follow=true).
Expand Down Expand Up @@ -296,12 +300,26 @@ func NewAgent(ctx context.Context, client *kube.KubernetesClient, namespace stri
return client.ApplicationsClientset.ArgoprojV1alpha1().Applications(appNamespace).Watch(ctx, config.LabelSelector(a.labelSelector))
}

// Default to un-buffered handlers
applicationAddHandler := a.addAppCreationToQueue
applicationUpdateHandler := a.addAppUpdateToQueue
applicationDeleteHandler := a.addAppDeletionToQueue

// If buffer is enabled, add a buffered layer between handlers and k8s informer callbacks
if a.applicationInformerEventBufferInterval != 0 {
log().Infof("Buffering of Application events is enabled at '%d' seconds", a.applicationInformerEventBufferInterval)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix duration format in log message.

The format string uses %d with a time.Duration, which will print the raw nanosecond value instead of seconds. Use int(a.applicationInformerEventBufferInterval.Seconds()) or change to %v to display the duration properly.

🔧 Proposed fix
-		log().Infof("Buffering of Application events is enabled at '%d' seconds", a.applicationInformerEventBufferInterval)
+		log().Infof("Buffering of Application events is enabled at '%v'", a.applicationInformerEventBufferInterval)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
log().Infof("Buffering of Application events is enabled at '%d' seconds", a.applicationInformerEventBufferInterval)
log().Infof("Buffering of Application events is enabled at '%v'", a.applicationInformerEventBufferInterval)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@agent/agent.go` at line 310, The log uses "%d" with a time.Duration which
prints nanoseconds; update the Infof call that references
a.applicationInformerEventBufferInterval (the log().Infof invocation) to format
the duration correctly by either using
int(a.applicationInformerEventBufferInterval.Seconds()) with "%d" or switch the
format specifier to "%v" and pass a.applicationInformerEventBufferInterval so
the duration is displayed in a human-readable form.

appBuffer := newInformerEventBuffer(a.addAppCreationToQueue, a.addAppUpdateToQueue, a.addAppDeletionToQueue, a.applicationInformerEventBufferInterval)
applicationAddHandler = appBuffer.receiveAddInformerEvent
applicationUpdateHandler = appBuffer.receiveUpdateInformerEvent
applicationDeleteHandler = appBuffer.receiveDeleteInformerEvent
}

appInformerOptions := []informer.InformerOption[*v1alpha1.Application]{
informer.WithListHandler[*v1alpha1.Application](appListFunc),
informer.WithWatchHandler[*v1alpha1.Application](appWatchFunc),
informer.WithAddHandler[*v1alpha1.Application](a.addAppCreationToQueue),
informer.WithUpdateHandler[*v1alpha1.Application](a.addAppUpdateToQueue),
informer.WithDeleteHandler[*v1alpha1.Application](a.addAppDeletionToQueue),
informer.WithAddHandler[*v1alpha1.Application](applicationAddHandler),
informer.WithUpdateHandler[*v1alpha1.Application](applicationUpdateHandler),
informer.WithDeleteHandler[*v1alpha1.Application](applicationDeleteHandler),
informer.WithFilters[*v1alpha1.Application](a.DefaultAppFilterChain()),
informer.WithNamespaceScope[*v1alpha1.Application](appNamespace),
informer.WithGroupResource[*v1alpha1.Application]("argoproj.io", "applications"),
Expand Down
Loading
Loading