Skip to content

fix(agent): Allow overriding collection_jitter with 0s on a per-input basis#18519

Closed
WZH8898 wants to merge 1 commit intoinfluxdata:masterfrom
WZH8898:fix-collection-jitter-zero
Closed

fix(agent): Allow overriding collection_jitter with 0s on a per-input basis#18519
WZH8898 wants to merge 1 commit intoinfluxdata:masterfrom
WZH8898:fix-collection-jitter-zero

Conversation

@WZH8898
Copy link
Copy Markdown
Contributor

@WZH8898 WZH8898 commented Mar 12, 2026

Summary

Fix per-input collection_jitter = "0s" not overriding the agent-level jitter.

The input configuration parsing currently discards whether collection_jitter was explicitly set. As a result, both an unset value and an explicit 0s are represented as the zero-value duration, and the agent logic treats both cases as "use the global collection_jitter".

This change preserves whether collection_jitter was explicitly configured on the input and updates the agent-side selection logic so that:

  • an explicitly configured per-input value overrides the agent setting
  • collection_jitter = "0s" disables jitter for that input
  • an unset per-input value still falls back to the agent setting

Tests were added to verify:

  • explicit 0s is preserved during config parsing
  • explicit 0s overrides the agent-level jitter
  • unset values still inherit the agent-level jitter

Checklist

  • No AI generated code was used in this PR

Related Issues

resolves #18517

@WZH8898 WZH8898 force-pushed the fix-collection-jitter-zero branch from a4cf9f0 to 381d1be Compare March 12, 2026 07:53
@WZH8898 WZH8898 changed the title agent: allow per-input collection_jitter to override with 0s fix(agent): allow per-input collection_jitter to override with 0s Mar 12, 2026
@telegraf-tiger telegraf-tiger bot added the fix pr to fix corresponding bug label Mar 12, 2026
@WZH8898 WZH8898 force-pushed the fix-collection-jitter-zero branch from 381d1be to 75b3ba3 Compare March 12, 2026 10:02
Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @WZH8898! Please find my comments below...

agent/agent.go Outdated
if input.Config.CollectionJitter != 0 {
jitter = input.Config.CollectionJitter
}
jitter := getCollectionJitter(time.Duration(a.Config.Agent.CollectionJitter), input.Config)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't move this to a function as it makes code harder to read as we need to follow all the nested redirections! Furthermore, the minimal change would be

		jitter := time.Duration(a.Config.Agent.CollectionJitter)
		if input.Config.CollectionJitterSet {
			jitter = input.Config.CollectionJitter
		}

which is also much more readable!

}

func TestGetCollectionJitter(t *testing.T) {
t.Parallel()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No strong reason beyond a table-driven helper test pattern. I removed this test to avoid low-value indirection.

tests := []struct {
name string
config *models.InputConfig
want time.Duration
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please call this expected as we do in other places.


for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right, it wasn't needed here. Removed together with that helper test.

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := getCollectionJitter(agentJitter, tt.config)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No. Either really test the whole processing path, i.e. set the agent config, then initialize a model and check the jitter or skip the test altogether. This tests really doesn't gain anything as-is.

@srebhan srebhan changed the title fix(agent): allow per-input collection_jitter to override with 0s fix(agent): Allow overriding collection_jitter with 0s on a per-input basis Mar 19, 2026
@srebhan srebhan self-assigned this Mar 19, 2026
@srebhan srebhan added the waiting for response waiting for response from contributor label Mar 23, 2026
@WZH8898 WZH8898 force-pushed the fix-collection-jitter-zero branch from 75b3ba3 to 0245d69 Compare April 1, 2026 07:05
@telegraf-tiger
Copy link
Copy Markdown
Contributor

telegraf-tiger bot commented Apr 1, 2026

@telegraf-tiger
Copy link
Copy Markdown
Contributor

telegraf-tiger bot commented Apr 6, 2026

Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Forums or provide additional details in this issue and reqeust that it be re-opened. Thank you!

@telegraf-tiger telegraf-tiger bot closed this Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent fix pr to fix corresponding bug waiting for response waiting for response from contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

collection_jitter = "0s" per plugin doesn't disable jitter

2 participants