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

Beats silently fails to start any input if there is an error when parsing the units sent by Elastic-Agent #43118

Open
belimawr opened this issue Mar 7, 2025 · 1 comment
Labels
bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Comments

@belimawr
Copy link
Contributor

belimawr commented Mar 7, 2025

When running under Elastic-Agent, if at least one unit has got an invalid configuration the Beat will silently fail without starting any input or producing any error log. During policy changes, it will log the received units, however they will never be started.

generateBeatConfig returns an error that reloadInputs correctly wraps, however it is not correctly handled by reload

When reload receives an error from reloadInputs, it will check if it is a list of errors, if it is, it correctly handles them, if it is not, then no error is handled and the code proceeds as if reloadInputs had succeeded.

if err := cm.reloadInputs(inputUnits); err != nil { // HERE
// cm.reloadInputs will use fmt.Errorf and join an error slice
// using errors.Join, so we need to unwrap the fmt wrapped error,
// then we can iterate over the errors list.
err = errors.Unwrap(err)
type unwrapList interface {
Unwrap() []error
}
//nolint:errorlint // That's a custom logic based on how reloadInputs builds the error
errList, isErrList := err.(unwrapList)
if isErrList {
for _, err := range errList.Unwrap() {
unitErr := cfgfile.UnitError{}
if errors.As(err, &unitErr) {
unitErrors[unitErr.UnitID] = append(unitErrors[unitErr.UnitID], unitErr.Err)
delete(healthyInputs, unitErr.UnitID)
}
}
}
}

This can be easily reproduced by adding the following (invalid) input configuration to an Elastic-Agent policy:

  - id: logfile-sample-2a176a73-63a4-448a-b208-bea77259a9ba
    name: threat_map-1
    revision: 1
    type: logfile
    use_output: default
    meta:
      package:
        name: threat_map
        version: 0.2.0
    data_stream:
      namespace: default
    package_policy_id: 2a176a73-63a4-448a-b208-bea77259a9ba

The Threat Map integration is currently generating this input, there is an open issue about it: elastic/integrations#13017

@belimawr belimawr added bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team labels Mar 7, 2025
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

No branches or pull requests

2 participants