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

Remove deprecated --setup, --version, and --configflags CLI flags #10138

Merged
merged 15 commits into from
Jan 30, 2019
3 changes: 3 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Import ECS change https://github.com/elastic/ecs/pull/308[ecs#308]:
leaf field `user.group` is now the `group` field set. {pull}10275[10275]
- Docker and Kubernetes labels/annotations will be "dedoted" by default. {pull}10338[10338]
- Remove --setup command line flag. {pull}10138[10138]
- Remove --version command line flag. {pull}10138[10138]
- Remove --configtest command line flag. {pull}10138[10138]

*Auditbeat*

Expand Down
2 changes: 1 addition & 1 deletion auditbeat/auditbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ setup.template.settings:
#============================== Dashboards =====================================
# These settings control loading the sample dashboards to the Kibana index. Loading
# the dashboards is disabled by default and can be enabled either by setting the
# options here, or by using the `-setup` CLI flag or the `setup` command.
# options here or by using the `setup` command.
#setup.dashboards.enabled: false

# The URL from where to download the dashboards archive. By default this URL
Expand Down
2 changes: 1 addition & 1 deletion filebeat/filebeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ setup.template.settings:
#============================== Dashboards =====================================
# These settings control loading the sample dashboards to the Kibana index. Loading
# the dashboards is disabled by default and can be enabled either by setting the
# options here, or by using the `-setup` CLI flag or the `setup` command.
# options here or by using the `setup` command.
#setup.dashboards.enabled: false

# The URL from where to download the dashboards archive. By default this URL
Expand Down
23 changes: 8 additions & 15 deletions filebeat/tests/system/test_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,19 @@ def init(self):
self.index_name = "test-filebeat-ml"

@parameterized.expand([
(True, False),
(True, True),
(False, False),
(False, True),
(False,),
(True,),
])
@unittest.skipIf(not INTEGRATION_TESTS,
"integration tests are disabled, run with INTEGRATION_TESTS=1 to enable them.")
@unittest.skipIf(os.getenv("TESTING_ENVIRONMENT") == "2x",
"integration test not available on 2.x")
@unittest.skipIf(os.name == "nt", "skipped on Windows")
def test_ml_setup(self, setup_flag, modules_flag):
def test_ml_setup(self, modules_flag):
""" Test ML are installed in all possible ways """
self._run_ml_test(setup_flag, modules_flag)
self._run_ml_test(modules_flag)

def _run_ml_test(self, setup_flag, modules_flag):
def _run_ml_test(self, modules_flag):
self.init()

from elasticsearch import AuthorizationException
Expand All @@ -55,7 +53,7 @@ def _run_ml_test(self, setup_flag, modules_flag):
except AuthorizationException:
print("License already enabled")

print("Test setup_flag: {}, modules_flag: {}".format(setup_flag, modules_flag))
print("Test modules_flag: {}".format(modules_flag))

# Clean any previous state
for df in self.es.transport.perform_request("GET", "/_xpack/ml/datafeeds/")["datafeeds"]:
Expand Down Expand Up @@ -93,14 +91,9 @@ def _run_ml_test(self, setup_flag, modules_flag):
"-c", cfgfile
]

# Skipping dashboard loading to speed up tests, unfortunately only works for setup and not --setup
# Skipping dashboard loading to speed up tests
cmd += ["-E", "setup.dashboards.enabled=false"]

if setup_flag:
cmd += ["--setup"]
else:
cmd += ["setup", "--machine-learning"]

cmd += ["setup", "--machine-learning"]
if modules_flag:
cmd += ["--modules=nginx"]

Expand Down
2 changes: 1 addition & 1 deletion heartbeat/heartbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ setup.template.settings:
#============================== Dashboards =====================================
# These settings control loading the sample dashboards to the Kibana index. Loading
# the dashboards is disabled by default and can be enabled either by setting the
# options here, or by using the `-setup` CLI flag or the `setup` command.
# options here or by using the `setup` command.
#setup.dashboards.enabled: false

# The URL from where to download the dashboards archive. By default this URL
Expand Down
2 changes: 1 addition & 1 deletion journalbeat/journalbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ journalbeat.inputs:
#============================== Dashboards =====================================
# These settings control loading the sample dashboards to the Kibana index. Loading
# the dashboards is disabled by default and can be enabled either by setting the
# options here, or by using the `-setup` CLI flag or the `setup` command.
# options here or by using the `setup` command.
#setup.dashboards.enabled: false

# The URL from where to download the dashboards archive. By default this URL
Expand Down
2 changes: 1 addition & 1 deletion libbeat/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#============================== Dashboards =====================================
# These settings control loading the sample dashboards to the Kibana index. Loading
# the dashboards is disabled by default and can be enabled either by setting the
# options here, or by using the `-setup` CLI flag or the `setup` command.
# options here or by using the `setup` command.
#setup.dashboards.enabled: false

# The URL from where to download the dashboards archive. By default this URL
Expand Down
7 changes: 0 additions & 7 deletions libbeat/cfgfile/cfgfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package cfgfile

import (
"flag"
"fmt"
"os"
"path/filepath"
Expand All @@ -34,7 +33,6 @@ var (
// be called prior to flags.Parse().
configfiles = common.StringArrFlag(nil, "c", "beat.yml", "Configuration file, relative to path.config")
overwrites = common.SettingFlag(nil, "E", "Configuration overwrite")
testConfig = flag.Bool("configtest", false, "Test configuration and exit.")

// Additional default settings, that must be available for variable expansion
defaults = common.MustNewConfigFrom(map[string]interface{}{
Expand Down Expand Up @@ -199,8 +197,3 @@ func GetPathConfig() string {
// TODO: Do we need this or should we always return *homePath?
return ""
}

// IsTestConfig returns whether or not this is configuration used for testing
func IsTestConfig() bool {
return *testConfig
}
37 changes: 4 additions & 33 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,10 @@ type beatConfig struct {
ILM *common.Config `config:"output.elasticsearch.ilm"`
}

var (
printVersion bool
setup bool
)

var debugf = logp.MakeDebug("beat")

func init() {
initRand()

flag.BoolVar(&printVersion, "version", false, "Print the version and exit")
flag.BoolVar(&setup, "setup", false, "Load sample Kibana dashboards and setup Machine Learning")
}

// initRand initializes the runtime random number generator seed using
Expand Down Expand Up @@ -381,26 +373,13 @@ func (b *Beat) launch(settings Settings, bt beat.Creator) error {
defer reporter.Stop()
}

// If -configtest was specified, exit now prior to run.
if cfgfile.IsTestConfig() {
cfgwarn.Deprecate("6.0", "-configtest flag has been deprecated, use configtest subcommand")
fmt.Println("Config OK")
return beat.GracefulExit
}

ctx, cancel := context.WithCancel(context.Background())
svc.HandleSignals(beater.Stop, cancel)

err = b.loadDashboards(ctx, false)
if err != nil {
return err
}
if setup && b.SetupMLCallback != nil {
err = b.SetupMLCallback(&b.Beat, b.Config.Kibana)
if err != nil {
return err
}
}

logp.Info("%s start running.", b.Info.Beat)

Expand Down Expand Up @@ -548,18 +527,10 @@ func (b *Beat) Setup(bt beat.Creator, settings SetupSettings) error {
}())
}

// handleFlags parses the command line flags. It handles the '-version' flag
// and invokes the HandleFlags callback if implemented by the Beat.
// handleFlags parses the command line flags. It invokes the HandleFlags
// callback if implemented by the Beat.
func (b *Beat) handleFlags() error {
flag.Parse()

if printVersion {
cfgwarn.Deprecate("6.0", "-version flag has been deprecated, use version subcommand")
fmt.Printf("%s version %s (%s), libbeat %s\n",
b.Info.Beat, b.Info.Version, runtime.GOARCH, version.GetDefaultVersion())
return beat.GracefulExit
}

return cfgfile.HandleFlags()
}

Expand Down Expand Up @@ -722,8 +693,8 @@ func openRegular(filename string) (*os.File, error) {
}

func (b *Beat) loadDashboards(ctx context.Context, force bool) error {
if setup || force {
// -setup implies dashboards.enabled=true
if force {
// force implies dashboards.enabled=true
if b.Config.Dashboards == nil {
b.Config.Dashboards = common.NewConfig()
}
Expand Down
8 changes: 0 additions & 8 deletions libbeat/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ func genRunCmd(settings instance.Settings, beatCreator beat.Creator, runFlags *p
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("httpprof"))
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("cpuprofile"))
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("memprofile"))
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("setup"))

// TODO deprecate in favor of subcommands (7.0):
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("configtest"))
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("version"))

runCmd.Flags().MarkDeprecated("version", "use version subcommand")
runCmd.Flags().MarkDeprecated("configtest", "use test config subcommand")

if runFlags != nil {
runCmd.Flags().AddFlagSet(runFlags)
Expand Down
23 changes: 4 additions & 19 deletions libbeat/docs/command-reference.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -523,21 +523,6 @@ the end of the file is reached. By default harvesters are closed after
`close_inactive` is reached.
endif::[]

*`--setup`*::
ifdef::deprecate_dashboard_loading[]
deprecated[{deprecate_dashboard_loading}]
endif::[]
+
ifdef::has_ml_jobs[]
Loads the initial setup, including Elasticsearch template, {kib} index pattern,
{kib} dashboards (when available), and Machine learning jobs.
endif::[]
ifndef::has_ml_jobs[]
Loads the initial setup, including Elasticsearch template, {kib} index pattern, and {kib} dashboards (when available).
endif::[]
If you want to use the command without running {beatname_uc}, use the <<setup-command,`setup`>> command instead.


ifeval::["{beatname_lc}"=="metricbeat"]
*`--system.hostfs MOUNT_POINT`*::

Expand All @@ -558,14 +543,14 @@ endif::[]

["source","sh",subs="attributes"]
-----
{beatname_lc} run -e --setup
{beatname_lc} run -e
-----

Or:

["source","sh",subs="attributes"]
-----
{beatname_lc} -e --setup
{beatname_lc} -e
Copy link
Contributor

Choose a reason for hiding this comment

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

Also remove the sentence on line 571/572 that says: "Use this command instead of run --setup when you want to set up the environment without actually running {beatname_uc} and ingesting data.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks. I modified the sentence to:

Use this command if you want to set up the environment without actually running
{beatname_uc} and ingesting data.

-----

[[setup-command]]
Expand All @@ -583,8 +568,8 @@ ifdef::has_ml_jobs[]
necessary to analyze data for anomalies.
endif::[]

Use this command instead of `run --setup` when you want to set up the
environment without actually running {beatname_uc} and ingesting data.
Use this command if you want to set up the environment without actually running
{beatname_uc} and ingesting data.

*SYNOPSIS*

Expand Down
2 changes: 2 additions & 0 deletions libbeat/tests/system/beat/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def start_beat(self,
def render_config_template(self, template_name=None,
output=None, **kargs):

print("render config")

# Init defaults
if template_name is None:
template_name = self.beat_name
Expand Down
58 changes: 0 additions & 58 deletions libbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,6 @@ def test_invalid_config_cli_param(self):
assert exit_code == 1
assert self.log_contains("error unpacking config data") is True

def test_config_test(self):
"""
Checks if -configtest works as expected
"""
shutil.copy(self.beat_path + "/_meta/config.yml",
os.path.join(self.working_dir, "libbeat.yml"))
with open(self.working_dir + "/mockbeat.template.json", "w") as f:
f.write('{"template": true}')
with open(self.working_dir + "/mockbeat.template-es2x.json", "w") as f:
f.write('{"template": true}')

exit_code = self.run_beat(
config="libbeat.yml",
extra_args=["-configtest",
"-path.config", self.working_dir])

assert exit_code == 0
assert self.log_contains("Config OK") is True

# NOTE(ph): I've removed the code to crash with theses settings, but the test is still usefull if
# more settings are added.
# def test_invalid_config_with_removed_settings(self):
Expand All @@ -101,45 +82,6 @@ def test_config_test(self):
# assert self.log_contains("setting 'queue_size' has been removed")
# assert self.log_contains("setting 'bulk_queue_size' has been removed")

def test_version_simple(self):
"""
Tests -version prints a version and exits.
"""
self.start_beat(extra_args=["-version"]).check_wait()
assert self.log_contains("beat version") is True

def test_version(self):
"""
Checks if version param works
"""
args = [self.beat_path + "/libbeat.test"]

args.extend(["-version",
"-e",
"-systemTest",
"-v",
"-d", "*",
])
if os.getenv("TEST_COVERAGE") == "true":
args.extend([
"-test.coverprofile",
os.path.join(self.working_dir, "coverage.cov"),
])

assert self.log_contains("error loading config file") is False

with open(os.path.join(self.working_dir, "mockbeat.log"), "wb") \
as outputfile:
proc = subprocess.Popen(args,
stdout=outputfile,
stderr=subprocess.STDOUT)
exit_code = proc.wait()
assert exit_code == 0

assert self.log_contains("mockbeat") is True
assert self.log_contains("version") is True
assert self.log_contains("9.9.9") is True

def test_console_output_timed_flush(self):
"""
outputs/console - timed flush
Expand Down
35 changes: 0 additions & 35 deletions libbeat/tests/system/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,6 @@ def test_setup_template(self):
assert exit_code == 0
assert len(self.es.cat.templates(name='mockbeat-*', h='name')) > 0

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
@attr('integration')
def test_setup_flag(self):
"""
Test --setup flag on run command
"""
# Delete any existing template
try:
self.es.indices.delete_template('mockbeat-*')
except:
pass

assert len(self.es.cat.templates(name='mockbeat-*', h='name')) == 0

shutil.copy(self.beat_path + "/_meta/config.yml",
os.path.join(self.working_dir, "libbeat.yml"))
shutil.copy(self.beat_path + "/fields.yml",
os.path.join(self.working_dir, "fields.yml"))

proc = self.start_beat(
extra_args=["--setup",
"--path.config", self.working_dir,
"-E", "setup.dashboards.file=" +
os.path.join(self.beat_path, "tests", "files", "testbeat-dashboards.zip"),
"-E", "setup.dashboards.beat=testbeat",
"-E", "setup.kibana.protocol=http",
"-E", "setup.kibana.host=" + self.get_kibana_host(),
"-E", "setup.kibana.port=" + self.get_kibana_port(),
"-E", "output.elasticsearch.hosts=['" + self.get_host() + "']"],
config="libbeat.yml")

self.wait_until(lambda: self.es.cat.templates(name='mockbeat-*', h='name') > 0)
self.wait_until(lambda: self.log_contains("Kibana dashboards successfully loaded"))
proc.check_kill_and_wait()

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
@attr('integration')
def test_test_config(self):
Expand Down
Loading