Skip to content

fix(inputs.ping): Warn on using timeout parameter for native method#18455

Open
WZH8898 wants to merge 1 commit intoinfluxdata:masterfrom
WZH8898:fix-ping-native-timeout
Open

fix(inputs.ping): Warn on using timeout parameter for native method#18455
WZH8898 wants to merge 1 commit intoinfluxdata:masterfrom
WZH8898:fix-ping-native-timeout

Conversation

@WZH8898
Copy link
Contributor

@WZH8898 WZH8898 commented Mar 4, 2026

Summary

Fix issue where the timeout parameter was ignored when using method = "native".

The native pinger uses a global timeout, so this change computes an effective
runtime timeout based on:

  • configured timeout
  • send interval between packets
  • packet count

The computed timeout is also capped by the configured deadline.

Unit tests have been added for the timeout calculation.

Checklist

Related issues

resolves #18395

@telegraf-tiger telegraf-tiger bot added area/ping fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Mar 4, 2026
@WZH8898 WZH8898 force-pushed the fix-ping-native-timeout branch from d00b3b1 to 8952c84 Compare March 4, 2026 09:08
@srebhan
Copy link
Member

srebhan commented Mar 4, 2026

@WZH8898 please restore the PR description template, especially the AI section, so we can review your contribution!

@srebhan srebhan self-assigned this Mar 4, 2026
@WZH8898
Copy link
Contributor Author

WZH8898 commented Mar 4, 2026

@WZH8898 please restore the PR description template, especially the AI section, so we can review your contribution!

Thanks! I've restored the PR template and added the AI checklist section.
Please let me know if anything else needs to be adjusted.

@srebhan
Copy link
Member

srebhan commented Mar 5, 2026

@WZH8898 to be honest I don't like the approach too much as it has too many assumptions. How about rather than trying to guess ask the user to use the deadline configuration option instead as this is what is used already? I.e. if you see timeout to be set with the native method, you should error out (or warn) in Init() that this parameter is not used for the method and what to do instead. Maybe also add some documentation to the README?

@WZH8898 WZH8898 force-pushed the fix-ping-native-timeout branch from 8952c84 to dc17cd5 Compare March 6, 2026 01:21
@WZH8898
Copy link
Contributor Author

WZH8898 commented Mar 6, 2026

@WZH8898 to be honest I don't like the approach too much as it has too many assumptions. How about rather than trying to guess ask the user to use the deadline configuration option instead as this is what is used already? I.e. if you see timeout to be set with the native method, you should error out (or warn) in Init() that this parameter is not used for the method and what to do instead. Maybe also add some documentation to the README?

Thanks for the suggestion! I've updated the implementation to warn when timeout is used with the native method and documented the behavior in the README.
Please let me know if further adjustments are needed.

@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Mar 6, 2026

Copy link
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 @WZH8898! Some more small comments...

Comment on lines +93 to +95
if p.Method == "native" && p.Timeout > 0 && p.Log != nil {
p.Log.Warn(`"timeout" is ignored when method = "native"; use "deadline" to control the total runtime`)
}
Copy link
Member

Choose a reason for hiding this comment

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

Log always is non-nil at runtime. If you see a panic here it's because the tests do not define Log which is a bug and should be fixed by setting the logger in the test!


pinger.Source = p.sourceAddress
pinger.Interval = p.calcInterval

Copy link
Member

Choose a reason for hiding this comment

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

Please keep the newline.

Comment on lines +24 to +25
## the "-W" option of the ping command. This setting is used by the "exec"
## method only.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## the "-W" option of the ping command. This setting is used by the "exec"
## method only.
## the "-W" option of the ping command (for "exec" method only)

Comment on lines +28 to +30
## If set, the total ping deadline, in seconds. Operates like the "-w"
## option of the ping command. Use this option to control timeout behavior
## when using the "native" method.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## If set, the total ping deadline, in seconds. Operates like the "-w"
## option of the ping command. Use this option to control timeout behavior
## when using the "native" method.
## If set, the total ping deadline, in seconds. Operates like the "-w"
## option of the ping command. Use this option to control timeout behavior
## when using the "native" method.

@srebhan srebhan changed the title fix(inputs.ping): honor timeout parameter for native method fix(inputs.ping): Warn on using timeout parameter for native method Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ping fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inputs.ping with method "native" ignores "timeout" parameter

2 participants