Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(agent): Add support for input probing #16333

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

LandonTClipp
Copy link
Contributor

@LandonTClipp LandonTClipp commented Dec 19, 2024

Summary

This PR adds support in RunningInput and the Agent to call an input plugin's Probe method if it exists and if the plugin has been configured for probing.

Checklist

  • No AI generated code was used in this PR

Related issues

related to #15915
replaces #16028
derived from #16305

@telegraf-tiger telegraf-tiger bot added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Dec 19, 2024
@telegraf-tiger
Copy link
Contributor

@srebhan srebhan changed the title feat(startup_error_behavior = "probe"): Add support for input probing. feat(agent): Add support for input probing. Dec 19, 2024
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 @LandonTClipp for the PR! Some minor comments in the code, the most important one is to call Stop if probing fails to not leak connections or the like.

agent/agent.go Outdated
Comment on lines 384 to 385
log.Printf("I! [agent] Failed to probe %s, shutting down plugin: %s", input.LogName(), err)
continue
Copy link
Member

Choose a reason for hiding this comment

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

I think you must call Stop for the input as it successfully passed the Start stage...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! Done.

Comment on lines 502 to 549
func TestRunningInputProbing(t *testing.T) {
probeErr := errors.New("probing error")
for _, tt := range []struct {
name string
input telegraf.Input
startupErrorBehavior string
expectedError bool
}{
{
name: "non-probing plugin with probe value set",
input: &mockInput{},
startupErrorBehavior: "probe",
expectedError: false,
},
{
name: "non-probing plugin with probe value not set",
input: &mockInput{},
startupErrorBehavior: "ignore",
expectedError: false,
},
{
name: "probing plugin with probe value set",
input: &mockProbingInput{probeErr},
startupErrorBehavior: "probe",
expectedError: true,
},
{
name: "probing plugin with probe value not set",
input: &mockProbingInput{probeErr},
startupErrorBehavior: "ignore",
expectedError: false,
},
} {
t.Run(tt.name, func(t *testing.T) {
ri := NewRunningInput(tt.input, &InputConfig{
Name: "TestRunningInput",
StartupErrorBehavior: tt.startupErrorBehavior,
})
ri.log = testutil.Logger{}
err := ri.Probe()
if tt.expectedError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Please split the test into one where the tests are expected to pass and one where the tests are expected to fail. Furthermore, you must use the require package instead of assert!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

plugin.go Outdated
Comment on lines 60 to 61
// ProbePlugin is an interface that all input/output plugins need to
// implement in order to support the `probe` value of `startup_error_behavior`.
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
// ProbePlugin is an interface that all input/output plugins need to
// implement in order to support the `probe` value of `startup_error_behavior`.
// ProbePlugin is an interface that all input/output plugins need to
// implement in order to support the `probe` value of `startup_error_behavior`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You want to delete the period? 🤷🏻 Done.

agent/agent.go Outdated
Comment on lines 382 to 383
// Probe failures are not fatal to Telegraf itself, so simply skip
// adding the input.
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
// Probe failures are not fatal to Telegraf itself, so simply skip
// adding the input.
// Probe failures are none-fatal to the agent but should only remove the plugin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@srebhan srebhan changed the title feat(agent): Add support for input probing. feat(agent): Add support for input probing Dec 19, 2024
@srebhan srebhan self-assigned this Dec 19, 2024
@srebhan srebhan added area/aws AWS plugins including cloudwatch, ecs, kinesis plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Dec 19, 2024
@LandonTClipp
Copy link
Contributor Author

Blocked on #16364.

@Hipska
Copy link
Contributor

Hipska commented Jan 6, 2025

I'm not sure this resolves #15915 as it doesn't add a Probe method for nvidia plugin?

@LandonTClipp
Copy link
Contributor Author

I'm not sure this resolves #15915 as it doesn't add a Probe method for nvidia plugin?

You're right, I changed the verbiage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/aws AWS plugins including cloudwatch, ecs, kinesis feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin 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.

3 participants