-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Conversation
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services) |
Pinging @elastic/sec-linux-platform (Team:Security-Linux Platform) |
Pinging @elastic/sec-windows-platform (Team:Security-Windows Platform) |
Pinging @elastic/sec-deployment-and-devices (Team:Security-Deployment and Devices) |
|
||
"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 |
There was a problem hiding this comment.
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 ❤️
968dbf6
to
ffcfe48
Compare
f0f6e8a
to
60b1b1c
Compare
64f67f9
to
c2f8a09
Compare
Co-authored-by: Tiago Queiroz <me@tiago.life>
20e1daf
to
1242459
Compare
@qcorporation / @bturquet could we have someone from your teams to review here please? |
// HandleFlags adapts default config settings based on command line | ||
// flags. This also stores if -E management.enabled=true was set on | ||
// command line to determine if running the Beat under agent. It will | ||
// call Initialize() to register the flags like `-E`. | ||
func HandleFlags() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: what's the guidance for downstream clients ? Do they have to call flag.Parse
before calling this ?
asking mostly because of elastic/apm-server#14214 and the previous apm server issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kruskall I built apm-server
with this PR. Had to make changes to internal/beatcmd/beat.go
and internal/beatcmd/reloader.go
for the change to uuidv5 and how the reload registry is stored. Also had to upgrade to badgerv4, that is probably a breaking change but I think someone from APM team will have to work on that. I tested that apm-server -E management.enabled=true -E logging.to_stderr=true
and apm-server -d "*" -e
work the same as before. Also apm-server --d "*" --e
works the same as before.
So at least for APM server, it shouldn't require changes to how it handles flag parsing. Other clients may have to register any flags they want to have the -c
to --c
conversion done with cfgfile.AddAllowedBackwardsCompatibleFlag("c")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@leehinman we are good to go. |
* modify beats argument parsing to not happen during init * allowlist for backwards compatible args, to conver -arg to --arg Co-authored-by: Tiago Queiroz <me@tiago.life> (cherry picked from commit 15eae5f)
* modify beats argument parsing to not happen during init * allowlist for backwards compatible args, to conver -arg to --arg Co-authored-by: Tiago Queiroz <me@tiago.life> (cherry picked from commit 15eae5f) Co-authored-by: Lee E Hinman <57081003+leehinman@users.noreply.github.com>
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
CHANGELOG.next.asciidoc
orCHANGELOG-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
elastic-agent
(main elastic agent, beats built from this PR, policy had auditd and system metrics)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
apm-server
. Built apm-server using this PR, had to make changes tointernal/beatcmd/beat.go
andinternal/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 thatapm-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
Use cases
Screenshots
Logs