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

refactor beats argument parsing #41277

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

leehinman
Copy link
Contributor

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

  • Must be tested with these changes running under elastic-agent
  • Must be tested with beats imported into elastic-agent
  • Must be tested with apm-server

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@leehinman leehinman requested review from a team as code owners October 17, 2024 00:19
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Oct 17, 2024
@leehinman leehinman added Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team backport-8.x Automated backport to the 8.x branch with mergify labels Oct 17, 2024
@elasticmachine
Copy link
Collaborator

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

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Oct 17, 2024
@pierrehilbert pierrehilbert added Team:obs-ds-hosted-services Label for the Observability Hosted Services team Team:Security-Linux Platform Linux Platform Team in Security Solution Team:Security-Windows Platform Windows Platform Team in Security Solution Team:Security-Deployment and Devices Deployment and Devices Team in Security Solution labels Oct 17, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/sec-linux-platform (Team:Security-Linux Platform)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/sec-windows-platform (Team:Security-Windows Platform)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/sec-deployment-and-devices (Team:Security-Deployment and Devices)

libbeat/cfgfile/cfgfile.go Outdated Show resolved Hide resolved
libbeat/cfgfile/cfgfile.go Show resolved Hide resolved

"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/fleetmode"
"github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/logp"
)

// Command line flags.
// Evil package level globals
Copy link
Contributor

Choose a reason for hiding this comment

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

I love the honesty on this comment ❤️

@leehinman leehinman requested a review from a team as a code owner October 17, 2024 14:42
@leehinman leehinman force-pushed the 41153_argument_parsing branch 6 times, most recently from f0f6e8a to 60b1b1c Compare October 17, 2024 21:44
@leehinman leehinman force-pushed the 41153_argument_parsing branch 2 times, most recently from 64f67f9 to c2f8a09 Compare October 18, 2024 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:obs-ds-hosted-services Label for the Observability Hosted Services team Team:Security-Deployment and Devices Deployment and Devices Team in Security Solution Team:Security-Linux Platform Linux Platform Team in Security Solution Team:Security-Windows Platform Windows Platform Team in Security Solution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix libbeat argument parsing to allow beats to be imported in other code bases.
4 participants