Skip to content

Commit

Permalink
remove os.Args hack for backwards compatible arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
leehinman committed Jan 3, 2025
1 parent 580f0f6 commit 143544c
Show file tree
Hide file tree
Showing 63 changed files with 64 additions and 228 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Fix metrics not being ingested, due to "Limit of total fields [10000] has been exceeded while adding new fields [...]". The total fields limit has been increased to 12500. No significant performance impact on Elasticsearch is anticipated. {pull}41640[41640]
- Set default kafka version to 2.1.0 in kafka output and filebeat. {pull}41662[41662]
- Fix templates and docs to use correct `--` version of command line arguments. {issue}42038[42038] {pull}42060[42060]
- removed support for a single `-` to precede multi-letter command line arguments. Use `--` instead. {issue}42117[42117] {pull}99999[99999]

*Auditbeat*

Expand Down
4 changes: 0 additions & 4 deletions auditbeat/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"

"github.com/elastic/beats/v7/auditbeat/cmd"
"github.com/elastic/beats/v7/libbeat/cfgfile"
"github.com/elastic/beats/v7/libbeat/tests/system/template"
)

Expand All @@ -35,14 +34,11 @@ func init() {
systemTest = flag.Bool("systemTest", false, "Set to true when running system tests")

cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest"))
cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest")
cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile"))
cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile")
}

// Test started when the test binary is started. Only calls main.
func TestSystem(*testing.T) {
cfgfile.ConvertFlagsForBackwardsCompatibility()
if *systemTest {
main()
}
Expand Down
2 changes: 1 addition & 1 deletion auditbeat/tests/system/test_show_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_show_auditd_rules(self):
}
}]
)
proc = self.start_beat(extra_args=['-strict.perms=false'])
proc = self.start_beat(extra_args=['--strict.perms=false'])
# auditbeat adds an extra rule to ignore itself
self.wait_log_contains('Successfully added {0} of {0} audit rules.'.format(len(rules) + 1),
max_timeout=30)
Expand Down
8 changes: 4 additions & 4 deletions dev-tools/cmd/dashboards/export_dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {
insecure := flag.Bool("insecure", false, "Disable TLS verification.")
spaceID := flag.String("space-id", "", "Space ID")
dashboard := flag.String("dashboard", "", "Dashboard ID")
fileOutput := flag.String("output", "", "Output NDJSON file, when exporting dashboards for Beats, please use -folder instead")
fileOutput := flag.String("output", "", "Output NDJSON file, when exporting dashboards for Beats, please use --folder instead")
folderOutput := flag.String("folder", "", "Output folder to save all assets to more human friendly JSON format")
ymlFile := flag.String("yml", "", "Path to the module.yml file containing the dashboards")
flag.BoolVar(&indexPattern, "indexPattern", false, "include index-pattern in output")
Expand All @@ -56,7 +56,7 @@ func main() {
log.SetFlags(0)

if len(*fileOutput) > 0 {
log.Fatalf("-output is configured, please use -folder flag instead to get the expected formatting of assets")
log.Fatalf("-output is configured, please use --folder flag instead to get the expected formatting of assets")
}

u, err := url.Parse(*kibanaURL)
Expand Down Expand Up @@ -92,10 +92,10 @@ func main() {

if len(*ymlFile) == 0 && len(*dashboard) == 0 {
flag.Usage()
log.Fatalf("Please specify a dashboard ID (-dashboard) or a manifest file (-yml)")
log.Fatalf("Please specify a dashboard ID (--dashboard) or a manifest file (--yml)")
}
if len(*folderOutput) == 0 {
log.Fatalf("Please specify a target folder using -folder flag")
log.Fatalf("Please specify a target folder using --folder flag")
}

if len(*ymlFile) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions dev-tools/mage/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func ExportDashboard() error {
folder := CWD("module", module)

args := []string{
"-folder", folder,
"-dashboard", id,
"--folder", folder,
"--dashboard", id,
}
if kibanaURL := EnvOr("KIBANA_URL", ""); kibanaURL != "" {
args = append(args, "-kibana", kibanaURL)
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/mage/gotool/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func HasTests(pkg string) (bool, error) {
}

func (goTest) WithCoverage(to string) ArgOpt {
return combine(flagArg("-cover", ""), flagArgIf("-test.coverprofile", to))
return combine(flagArg("-cover", ""), flagArgIf("--test.coverprofile", to))
}
func (goTest) Short(b bool) ArgOpt { return flagBoolIf("-test.short", b) }
func (goTest) Use(bin string) ArgOpt { return extraArgIf("use", bin) }
Expand Down
2 changes: 1 addition & 1 deletion docs/devguide/migrate-dashboards.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ Using the yml file, you can export all the dashboards for a single module or for
[source,shell]
----
cd metricbeat/module/system
go run ../../../dev-tools/cmd/dashboards/export_dashboards.go -yml module.yml
go run ../../../dev-tools/cmd/dashboards/export_dashboards.go --yml module.yml
----

2 changes: 1 addition & 1 deletion docs/devguide/modules-dev-guide.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Then run `export_dashboards` like this:
----
$ cd dev-tools/cmd/dashboards
$ make # if export_dashboard is not built yet
$ ./export_dashboards -yml '../../../filebeat/module/{module}/module.yml'
$ ./export_dashboards --yml '../../../filebeat/module/{module}/module.yml'
----

New Filebeat modules might not be compatible with Kibana 5.x. To export dashboards
Expand Down
6 changes: 3 additions & 3 deletions docs/devguide/newdashboards.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ MODULE=redis ID=AV4REOpp5NkDleZmzKkE mage exportDashboard

[source,shell]
---------------
./filebeat export dashboard -id 7fea2930-478e-11e7-b1f0-cb29bac6bf8b -folder module/redis
./filebeat export dashboard --id 7fea2930-478e-11e7-b1f0-cb29bac6bf8b --folder module/redis
---------------

This generates an appropriate folder under module/redis for the dashboard, separating assets into dashboards, searches, vizualizations, etc.
Expand Down Expand Up @@ -289,12 +289,12 @@ By passing the yml file to the `export_dashboards.go` script or to the Beat, you

[source,shell]
-------------------
go run dev-tools/cmd/dashboards/export_dashboards.go -yml filebeat/module/system/module.yml -folder dashboards
go run dev-tools/cmd/dashboards/export_dashboards.go --yml filebeat/module/system/module.yml --folder dashboards
-------------------

[source,shell]
-------------------
./filebeat export dashboard -yml filebeat/module/system/module.yml
./filebeat export dashboard --yml filebeat/module/system/module.yml
-------------------


Expand Down
2 changes: 1 addition & 1 deletion filebeat/beater/filebeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func newBeater(b *beat.Beat, plugins PluginFactory, rawConfig *conf.C) (beat.Bea
}

if *once && config.ConfigInput.Enabled() && config.ConfigModules.Enabled() {
return nil, fmt.Errorf("input configs and -once cannot be used together")
return nil, fmt.Errorf("input configs and --once cannot be used together")
}

if config.IsInputEnabled("stdin") && len(enabledInputs) > 1 {
Expand Down
7 changes: 0 additions & 7 deletions filebeat/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/elastic/beats/v7/filebeat/generator/fields"
"github.com/elastic/beats/v7/filebeat/generator/fileset"
"github.com/elastic/beats/v7/filebeat/generator/module"
"github.com/elastic/beats/v7/libbeat/cfgfile"
"github.com/elastic/beats/v7/libbeat/common/cli"
"github.com/elastic/elastic-agent-libs/paths"
)
Expand Down Expand Up @@ -64,9 +63,7 @@ func genGenerateModuleCmd() *cobra.Command {
}

genModuleCmd.Flags().String("modules-path", defaultHomePath, "Path to modules directory")
cfgfile.AddAllowedBackwardsCompatibleFlag("modules-path")
genModuleCmd.Flags().String("es-beats", defaultHomePath, "Path to Elastic Beats")
cfgfile.AddAllowedBackwardsCompatibleFlag("es-beats")

return genModuleCmd
}
Expand All @@ -91,9 +88,7 @@ func genGenerateFilesetCmd() *cobra.Command {
}

genFilesetCmd.Flags().String("modules-path", defaultHomePath, "Path to modules directory")
cfgfile.AddAllowedBackwardsCompatibleFlag("modules-path")
genFilesetCmd.Flags().String("es-beats", defaultHomePath, "Path to Elastic Beats")
cfgfile.AddAllowedBackwardsCompatibleFlag("es-beats")

return genFilesetCmd
}
Expand All @@ -118,9 +113,7 @@ func genGenerateFieldsCmd() *cobra.Command {
}

genFieldsCmd.Flags().String("es-beats", defaultHomePath, "Path to Elastic Beats")
cfgfile.AddAllowedBackwardsCompatibleFlag("es-beats")
genFieldsCmd.Flags().Bool("without-documentation", false, "Do not add description fields")
cfgfile.AddAllowedBackwardsCompatibleFlag("without-documentation")

return genFieldsCmd
}
5 changes: 0 additions & 5 deletions filebeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/elastic/beats/v7/filebeat/fileset"
"github.com/elastic/beats/v7/filebeat/include"
"github.com/elastic/beats/v7/filebeat/input"
"github.com/elastic/beats/v7/libbeat/cfgfile"
"github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/libbeat/cmd/instance"

Expand All @@ -50,9 +49,7 @@ func FilebeatSettings(moduleNameSpace string) instance.Settings {
}
runFlags := pflag.NewFlagSet(Name, pflag.ExitOnError)
runFlags.AddGoFlag(flag.CommandLine.Lookup("once"))
cfgfile.AddAllowedBackwardsCompatibleFlag("once")
runFlags.AddGoFlag(flag.CommandLine.Lookup("modules"))
cfgfile.AddAllowedBackwardsCompatibleFlag("modules")
return instance.Settings{
RunFlags: runFlags,
Name: Name,
Expand All @@ -69,10 +66,8 @@ func FilebeatSettings(moduleNameSpace string) instance.Settings {
func Filebeat(inputs beater.PluginFactory, settings instance.Settings) *cmd.BeatsRootCmd {
command := cmd.GenRootCmdWithSettings(beater.New(inputs), settings)
command.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("M"))
cfgfile.AddAllowedBackwardsCompatibleFlag("M")
command.TestCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("modules"))
command.SetupCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("modules"))
cfgfile.AddAllowedBackwardsCompatibleFlag("modules")
command.AddCommand(cmd.GenModulesCmd(Name, "", buildModulesManager))
command.AddCommand(genGenerateCmd())
return command
Expand Down
4 changes: 0 additions & 4 deletions filebeat/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

fbcmd "github.com/elastic/beats/v7/filebeat/cmd"
inputs "github.com/elastic/beats/v7/filebeat/input/default-inputs"
"github.com/elastic/beats/v7/libbeat/cfgfile"
cmd "github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/libbeat/tests/system/template"
)
Expand All @@ -41,14 +40,11 @@ func init() {
systemTest = flag.Bool("systemTest", false, "Set to true when running system tests")
fbCommand = fbcmd.Filebeat(inputs.Init, fbcmd.FilebeatSettings(""))
fbCommand.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest"))
cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest")
fbCommand.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile"))
cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile")
}

// Test started when the test binary is started. Only calls main.
func TestSystem(t *testing.T) {
cfgfile.ConvertFlagsForBackwardsCompatibility()
if *systemTest {
if err := fbCommand.Execute(); err != nil {
os.Exit(1)
Expand Down
12 changes: 6 additions & 6 deletions filebeat/tests/system/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_generate_module(self):

self._create_clean_test_modules()
exit_code = self.run_beat(
extra_args=["generate", "module", "my_module", "-modules-path", "test_modules", "-es-beats", self.beat_path])
extra_args=["generate", "module", "my_module", "--modules-path", "test_modules", "--es-beats", self.beat_path])
assert exit_code == 0

module_root = os.path.join("test_modules", "module", "my_module")
Expand Down Expand Up @@ -47,11 +47,11 @@ def test_generate_fileset(self):

self._create_clean_test_modules()
exit_code = self.run_beat(
extra_args=["generate", "module", "my_module", "-modules-path", "test_modules", "-es-beats", self.beat_path])
extra_args=["generate", "module", "my_module", "--modules-path", "test_modules", "--es-beats", self.beat_path])
assert exit_code == 0

exit_code = self.run_beat(
extra_args=["generate", "fileset", "my_module", "my_fileset", "-modules-path", "test_modules", "-es-beats", self.beat_path])
extra_args=["generate", "fileset", "my_module", "my_fileset", "--modules-path", "test_modules", "--es-beats", self.beat_path])
assert exit_code == 0

fileset_root = os.path.join("test_modules", "module", "my_module", "my_fileset")
Expand Down Expand Up @@ -88,11 +88,11 @@ def test_generate_fields_yml(self):

self._create_clean_test_modules()
exit_code = self.run_beat(
extra_args=["generate", "module", "my_module", "-modules-path", "test_modules", "-es-beats", self.beat_path])
extra_args=["generate", "module", "my_module", "--modules-path", "test_modules", "--es-beats", self.beat_path])
assert exit_code == 0

exit_code = self.run_beat(
extra_args=["generate", "fileset", "my_module", "my_fileset", "-modules-path", "test_modules", "-es-beats", self.beat_path])
extra_args=["generate", "fileset", "my_module", "my_fileset", "--modules-path", "test_modules", "--es-beats", self.beat_path])
assert exit_code == 0

test_pipeline_path = os.path.join(self.beat_path, "tests", "system", "input", "my-module-pipeline.json")
Expand All @@ -102,7 +102,7 @@ def test_generate_fields_yml(self):
shutil.copyfile(test_pipeline_path, fileset_pipeline)

exit_code = self.run_beat(
extra_args=["generate", "fields", "my_module", "my_fileset", "-es-beats", "test_modules", "-without-documentation"])
extra_args=["generate", "fields", "my_module", "my_fileset", "--es-beats", "test_modules", "--without-documentation"])
assert exit_code == 0

fields_yml_path = os.path.join("test_modules", "module", "my_module", "my_fileset", "_meta", "fields.yml")
Expand Down
2 changes: 1 addition & 1 deletion filebeat/tests/system/test_keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def add_secret(self, key, value="hello world\n", force=False):
Add new secret using the --stdin option
"""
args = [self.test_binary,
"-systemTest",
"--systemTest",
"-c", os.path.join(self.working_dir, self.beat_name + ".yml"),
"-e", "-v", "-d", "*",
"keystore", "add", key, "--stdin",
Expand Down
10 changes: 5 additions & 5 deletions filebeat/tests/system/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ def run_on_file(self, module, fileset, test_file, cfgfile):
self.wait_until(lambda: not self.es.indices.exists(self.index_name))

cmd = [
self.filebeat, "-systemTest",
"-d", "*", "-once",
self.filebeat, "--systemTest",
"-d", "*", "--once",
"-c", cfgfile,
"-E", "setup.ilm.enabled=false",
"-modules={}".format(module),
"--modules={}".format(module),
"-M", "{module}.*.enabled=false".format(module=module),
"-M", "{module}.{fileset}.enabled=true".format(
module=module, fileset=fileset),
Expand All @@ -191,7 +191,7 @@ def run_on_file(self, module, fileset, test_file, cfgfile):
module=module, fileset=fileset))

if ".journal" in test_file:
cmd.remove("-once")
cmd.remove("--once")
cmd.append("-M")
cmd.append("{module}.{fileset}.var.use_journald=true".format(
module=module, fileset=fileset))
Expand Down Expand Up @@ -224,7 +224,7 @@ def run_on_file(self, module, fileset, test_file, cfgfile):
stderr=subprocess.STDOUT,
bufsize=0)
# The journald input (used by some modules like 'system') does not
# support the -once flag, hence we run Filebeat for at most
# support the --once flag, hence we run Filebeat for at most
# 15 seconds, if it does not finish, then kill the process.
# If for any reason the Filebeat process gets stuck, only SIGKILL
# will terminate it. We use SIGKILL to avoid leaking any running
Expand Down
2 changes: 1 addition & 1 deletion filebeat/tests/system/test_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_once(self):

file.close()

filebeat = self.start_beat(extra_args=["-once"])
filebeat = self.start_beat(extra_args=["--once"])

# Make sure all lines are read
self.wait_until(
Expand Down
4 changes: 2 additions & 2 deletions filebeat/tests/system/test_stdin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def test_stdin_eof(self):
close_eof="true",
)

args = [self.test_binary, "-systemTest"]
args = [self.test_binary, "--systemTest"]
if os.getenv("TEST_COVERAGE") == "true":
args += ["-test.coverprofile",
args += ["--test.coverprofile",
os.path.join(self.working_dir, "coverage.cov")]
args += ["-c", os.path.join(self.working_dir, "filebeat.yml"), "-e",
"-v", "-d", "*"]
Expand Down
2 changes: 0 additions & 2 deletions heartbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/elastic/beats/v7/heartbeat/beater"
"github.com/elastic/beats/v7/heartbeat/include"
"github.com/elastic/beats/v7/libbeat/cfgfile"
cmd "github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/libbeat/cmd/instance"
"github.com/elastic/beats/v7/libbeat/ecs"
Expand Down Expand Up @@ -82,7 +81,6 @@ func Initialize(settings instance.Settings) *cmd.BeatsRootCmd {
`
setup.ResetFlags()
setup.Flags().Bool(cmd.IndexManagementKey, false, "Setup all components related to Elasticsearch index management, including template, ilm policy and rollover alias")
cfgfile.AddAllowedBackwardsCompatibleFlag(cmd.IndexManagementKey)

return rootCmd
}
Expand Down
4 changes: 0 additions & 4 deletions heartbeat/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"

"github.com/elastic/beats/v7/heartbeat/cmd"
"github.com/elastic/beats/v7/libbeat/cfgfile"
"github.com/elastic/beats/v7/libbeat/tests/system/template"
)

Expand All @@ -34,14 +33,11 @@ func init() {
testing.Init()
systemTest = flag.Bool("systemTest", false, "Set to true when running system tests")
cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest"))
cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest")
cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile"))
cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile")
}

// Test started when the test binary is started. Only calls main.
func TestSystem(_ *testing.T) {
cfgfile.ConvertFlagsForBackwardsCompatibility()
if *systemTest {
main()
}
Expand Down
Loading

0 comments on commit 143544c

Please sign in to comment.