beats icon indicating copy to clipboard operation
beats copied to clipboard

[8.x](backport #41277) refactor beats argument parsing

Open mergify[bot] opened this issue 1 year ago • 2 comments

Proposed commit message

Change beats argument parsing behavior.

Beats currently sets some command line flags in an init function, this means that any other project that imports beats will have conflicts if it uses the same options. This change moves this out of init.

Beats currently modifies the Argument list to offer backwards compatibility for flags in an init function. This would convert flags like -e to --e. This means if any other project imports beats, it's argument parsing would be changed. This change adds an allowed list of arguments that can be changed and moves it out of init.

Beats currently detects if it is fleet managed by looking at the command line flags. This change keeps that behavior, but adds the ability to set this directly. This allows setting the flag without the command line option.

Checklist

  • [ ] My code follows the style guidelines of this project
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Disruptive User Impact

The goal is none, however if any flags are missed, then the user would have to call them as --flag instead of -flag.

Author's Checklist

  • [x] Must be tested with these changes running under elastic-agent (main elastic agent, beats built from this PR, policy had auditd and system metrics)
  • [x] Must be tested with beats imported into elastic-agent (main elastic-agent, importing beats and implementing filebeat receiver, beats builts from this PR, policy had auditd and system metrics). Verified filebeatreceiver worked, normal agentbeat worked and that -1s could be passed as an argument to --fleet-server-timeout
  • [x] Must be tested with apm-server. Built apm-server using this PR, had to make changes to internal/beatcmd/beat.go and internal/beatcmd/reloader.go. This was expected for change to uuidv5 and storage of the reload registry. Also had to upgrade to badgerv4, also expected, but may be a breaking change. Tested that apm-server -E management.enabled=true -E logging.to_stderr=true still worked as expected. No changes were required to apm-server argument parsing.

How to test this PR locally

Related issues

  • Closes #41153

Use cases

Screenshots

Logs


This is an automatic backport of pull request #41277 done by [Mergify](https://mergify.com).

mergify[bot] avatar Oct 22 '24 15:10 mergify[bot]

This pull request doesn't have a Team:<team> label.

botelastic[bot] avatar Oct 22 '24 15:10 botelastic[bot]

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

elasticmachine avatar Oct 22 '24 15:10 elasticmachine

run docs-build

jlind23 avatar Oct 23 '24 06:10 jlind23