diff --git a/cmd/apm-server/main.go b/cmd/apm-server/main.go index 72244c3d3d3..30a4789c57e 100644 --- a/cmd/apm-server/main.go +++ b/cmd/apm-server/main.go @@ -25,6 +25,7 @@ import ( ) func main() { + beatcmd.InitBeatCmd() rootCmd := beatcmd.NewRootCommand(beatcmd.BeatParams{ NewRunner: func(args beatcmd.RunnerParams) (beatcmd.Runner, error) { return beater.NewRunner(beater.RunnerParams{ diff --git a/internal/beatcmd/init.go b/internal/beatcmd/init.go index bbf657006ac..2ccecda29f5 100644 --- a/internal/beatcmd/init.go +++ b/internal/beatcmd/init.go @@ -19,6 +19,7 @@ package beatcmd import ( cryptorand "crypto/rand" + "flag" "log" "math" "math/big" @@ -38,7 +39,7 @@ import ( _ "github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue" ) -func init() { +func InitBeatCmd() { initRand() initFlags() } @@ -62,6 +63,7 @@ func initFlags() { } } + flag.Parse() if err := cfgfile.HandleFlags(); err != nil { log.Fatal(err) } diff --git a/x-pack/apm-server/main.go b/x-pack/apm-server/main.go index caab7b061e2..2ec2c6d2c0b 100644 --- a/x-pack/apm-server/main.go +++ b/x-pack/apm-server/main.go @@ -275,6 +275,7 @@ func cleanup() error { } func Main() error { + beatcmd.InitBeatCmd() rootCmd := newXPackRootCommand( func(args beatcmd.RunnerParams) (beatcmd.Runner, error) { return beater.NewRunner(beater.RunnerParams{ diff --git a/x-pack/apm-server/root_test.go b/x-pack/apm-server/root_test.go index 39fbf2aa30d..d916a0e73f8 100644 --- a/x-pack/apm-server/root_test.go +++ b/x-pack/apm-server/root_test.go @@ -13,6 +13,7 @@ import ( ) func TestSubCommands(t *testing.T) { + beatcmd.InitBeatCmd() rootCmd := newXPackRootCommand(func(beatcmd.RunnerParams) (beatcmd.Runner, error) { panic("unexpected call") })