Skip to content

Commit e098e00

Browse files
authored
[Heartbeat] Remove not needed flags from setup command (elastic#11856)
The setup command until now contained all the possible options from the other Beats. As Heartbeat does not ship anymore with dashboards, the --dashboards command is not needed anymore and is only confusing. I also removed all the other commands except `--ilm-policy` and `--template`. I'm not aware that `--pipelines` or `--machine-learning` would be used. Here the comparison between `./heartbeat setup -h` from before and after. Before: ``` This command does initial setup of the environment: * Index mapping template in Elasticsearch to ensure fields are mapped. * Kibana dashboards (where available). * ML jobs (where available). * Ingest pipelines (where available). * ILM policy (for Elasticsearch 6.5 and newer). Usage: heartbeat setup [flags] Flags: --dashboards Setup dashboards -h, --help help for setup --ilm-policy Setup ILM policy --machine-learning Setup machine learning job configurations --pipelines Setup Ingest pipelines --template Setup index template ``` After: ``` This command does initial setup of the environment: * Index mapping template in Elasticsearch to ensure fields are mapped. * ILM Policy Usage: heartbeat setup [flags] Flags: -h, --help help for setup --ilm-policy Setup ILM policy --template Setup index template ``` In this PR I did not include a check for the config option `setup.dashboards` to make sure they are not there like apm-server does (https://github.com/elastic/apm-server/blob/2baefab778fdfe70c47bc2fb488677b2e43e4635/beater/beater.go#L60) as I don't think it's necessary.
1 parent 89f93e3 commit e098e00

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

heartbeat/cmd/root.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,36 @@ package cmd
1919

2020
import (
2121
// register default heartbeat monitors
22-
_ "github.com/elastic/beats/heartbeat/monitors/defaults"
23-
"github.com/elastic/beats/libbeat/cmd/instance"
24-
2522
"github.com/elastic/beats/heartbeat/beater"
23+
_ "github.com/elastic/beats/heartbeat/monitors/defaults"
2624
cmd "github.com/elastic/beats/libbeat/cmd"
25+
"github.com/elastic/beats/libbeat/cmd/instance"
2726
)
2827

2928
// Name of this beat
3029
var Name = "heartbeat"
3130

3231
// RootCmd to handle beats cli
33-
var RootCmd = cmd.GenRootCmdWithSettings(beater.New, instance.Settings{Name: Name})
32+
var RootCmd *cmd.BeatsRootCmd
33+
34+
func init() {
35+
RootCmd = cmd.GenRootCmdWithSettings(beater.New, instance.Settings{Name: Name})
36+
37+
// remove dashboard from export commands
38+
for _, cmd := range RootCmd.ExportCmd.Commands() {
39+
if cmd.Name() == "dashboard" {
40+
RootCmd.ExportCmd.RemoveCommand(cmd)
41+
}
42+
}
43+
44+
// only add defined flags to setup command
45+
setup := RootCmd.SetupCmd
46+
setup.Short = "Setup Elasticsearch index template and pipelines"
47+
setup.Long = `This command does initial setup of the environment:
48+
* Index mapping template in Elasticsearch to ensure fields are mapped.
49+
* ILM Policy
50+
`
51+
setup.ResetFlags()
52+
setup.Flags().Bool(cmd.TemplateKey, false, "Setup index template")
53+
setup.Flags().Bool(cmd.ILMPolicyKey, false, "Setup ILM policy")
54+
}

0 commit comments

Comments
 (0)