Skip to content

Commit d9116c8

Browse files
author
Andrew Stucki
authored
Add basic wildcard/keyword fallback for upcoming ECS releases (elastic#22521) (elastic#22568)
* Add basic wildcard/keyword fallback for upcoming ECS releases * update changelog * Invert global boolean * Remove global * Rename XPack to ElasticLicensed (cherry picked from commit 0fda306)
1 parent 015205f commit d9116c8

File tree

47 files changed

+395
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+395
-129
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
390390
- Add add_resource_metadata option setting (always enabled) for add_kubernetes_metadata setting. {pull}22189[22189]
391391
- Added Kafka version 2.2 to the list of supported versions. {pull}22328[22328]
392392
- Add support for ephemeral containers in kubernetes autodiscover and `add_kubernetes_metadata`. {pull}22389[22389] {pull}22439[22439]
393+
- Added support for wildcard fields and keyword fallback in beats setup commands. {pull}22521[22521]
393394

394395
*Auditbeat*
395396

auditbeat/cmd/root.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,29 @@ var withECSVersion = processing.WithFields(common.MapStr{
5454
},
5555
})
5656

57-
func init() {
58-
create := beater.Creator(
59-
beater.WithModuleOptions(
60-
module.WithEventModifier(core.AddDatasetToEvent),
61-
),
62-
)
57+
// AuditbeatSettings contains the default settings for auditbeat
58+
func AuditbeatSettings() instance.Settings {
6359
var runFlags = pflag.NewFlagSet(Name, pflag.ExitOnError)
64-
settings := instance.Settings{
60+
return instance.Settings{
6561
RunFlags: runFlags,
6662
Name: Name,
6763
HasDashboards: true,
6864
Processing: processing.MakeDefaultSupport(true, withECSVersion, processing.WithHost, processing.WithAgentMeta()),
6965
}
70-
RootCmd = cmd.GenRootCmdWithSettings(create, settings)
71-
RootCmd.AddCommand(ShowCmd)
66+
}
67+
68+
// Initialize initializes the entrypoint commands for journalbeat
69+
func Initialize(settings instance.Settings) *cmd.BeatsRootCmd {
70+
create := beater.Creator(
71+
beater.WithModuleOptions(
72+
module.WithEventModifier(core.AddDatasetToEvent),
73+
),
74+
)
75+
rootCmd := cmd.GenRootCmdWithSettings(create, settings)
76+
rootCmd.AddCommand(ShowCmd)
77+
return rootCmd
78+
}
79+
80+
func init() {
81+
RootCmd = Initialize(AuditbeatSettings())
7282
}

auditbeat/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ func TestSystem(t *testing.T) {
4545
}
4646

4747
func TestTemplate(t *testing.T) {
48-
template.TestTemplate(t, cmd.Name)
48+
template.TestTemplate(t, cmd.Name, false)
4949
}

filebeat/cmd/root.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,23 @@ import (
3535
// Name of this beat
3636
const Name = "filebeat"
3737

38-
// Filebeat build the beat root command for executing filebeat and it's subcommands.
39-
func Filebeat(inputs beater.PluginFactory) *cmd.BeatsRootCmd {
38+
// RootCmd to handle beats cli
39+
var RootCmd *cmd.BeatsRootCmd
40+
41+
// FilebeatSettings contains the default settings for filebeat
42+
func FilebeatSettings() instance.Settings {
4043
var runFlags = pflag.NewFlagSet(Name, pflag.ExitOnError)
4144
runFlags.AddGoFlag(flag.CommandLine.Lookup("once"))
4245
runFlags.AddGoFlag(flag.CommandLine.Lookup("modules"))
43-
settings := instance.Settings{
46+
return instance.Settings{
4447
RunFlags: runFlags,
4548
Name: Name,
4649
HasDashboards: true,
4750
}
51+
}
4852

53+
// Filebeat build the beat root command for executing filebeat and it's subcommands.
54+
func Filebeat(inputs beater.PluginFactory, settings instance.Settings) *cmd.BeatsRootCmd {
4955
command := cmd.GenRootCmdWithSettings(beater.New(inputs), settings)
5056
command.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("M"))
5157
command.TestCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("modules"))

filebeat/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
// Finally, input uses the registrar information, on restart, to
3434
// determine where in each file to restart a harvester.
3535
func main() {
36-
if err := cmd.Filebeat(inputs.Init).Execute(); err != nil {
36+
if err := cmd.Filebeat(inputs.Init, cmd.FilebeatSettings()).Execute(); err != nil {
3737
os.Exit(1)
3838
}
3939
}

filebeat/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var fbCommand *cmd.BeatsRootCmd
3636
func init() {
3737
testing.Init()
3838
systemTest = flag.Bool("systemTest", false, "Set to true when running system tests")
39-
fbCommand = fbcmd.Filebeat(inputs.Init)
39+
fbCommand = fbcmd.Filebeat(inputs.Init, fbcmd.FilebeatSettings())
4040
fbCommand.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest"))
4141
fbCommand.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile"))
4242
}
@@ -51,5 +51,5 @@ func TestSystem(t *testing.T) {
5151
}
5252

5353
func TestTemplate(t *testing.T) {
54-
template.TestTemplate(t, fbCommand.Name())
54+
template.TestTemplate(t, fbCommand.Name(), false)
5555
}

heartbeat/cmd/root.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,28 @@ var Name = "heartbeat"
3838
// RootCmd to handle beats cli
3939
var RootCmd *cmd.BeatsRootCmd
4040

41-
func init() {
42-
settings := instance.Settings{
41+
// HeartbeatSettings contains the default settings for heartbeat
42+
func HeartbeatSettings() instance.Settings {
43+
return instance.Settings{
4344
Name: Name,
4445
Processing: processing.MakeDefaultSupport(true, processing.WithECS, processing.WithAgentMeta()),
4546
HasDashboards: false,
4647
}
47-
RootCmd = cmd.GenRootCmdWithSettings(beater.New, settings)
48+
}
49+
50+
// Initialize initializes the entrypoint commands for heartbeat
51+
func Initialize(settings instance.Settings) *cmd.BeatsRootCmd {
52+
rootCmd := cmd.GenRootCmdWithSettings(beater.New, settings)
4853

4954
// remove dashboard from export commands
50-
for _, cmd := range RootCmd.ExportCmd.Commands() {
55+
for _, cmd := range rootCmd.ExportCmd.Commands() {
5156
if cmd.Name() == "dashboard" {
52-
RootCmd.ExportCmd.RemoveCommand(cmd)
57+
rootCmd.ExportCmd.RemoveCommand(cmd)
5358
}
5459
}
5560

5661
// only add defined flags to setup command
57-
setup := RootCmd.SetupCmd
62+
setup := rootCmd.SetupCmd
5863
setup.Short = "Setup Elasticsearch index template and pipelines"
5964
setup.Long = `This command does initial setup of the environment:
6065
* Index mapping template in Elasticsearch to ensure fields are mapped.
@@ -66,4 +71,10 @@ func init() {
6671
setup.Flags().MarkDeprecated(cmd.ILMPolicyKey, fmt.Sprintf("use --%s instead", cmd.IndexManagementKey))
6772
setup.Flags().Bool(cmd.TemplateKey, false, "Setup index template")
6873
setup.Flags().Bool(cmd.ILMPolicyKey, false, "Setup ILM policy")
74+
75+
return rootCmd
76+
}
77+
78+
func init() {
79+
RootCmd = Initialize(HeartbeatSettings())
6980
}

heartbeat/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ func TestSystem(t *testing.T) {
4444
}
4545

4646
func TestTemplate(t *testing.T) {
47-
template.TestTemplate(t, cmd.Name)
47+
template.TestTemplate(t, cmd.Name, false)
4848
}

journalbeat/cmd/root.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,18 @@ import (
3232
var Name = "journalbeat"
3333

3434
// RootCmd to handle beats cli
35-
var RootCmd = cmd.GenRootCmdWithSettings(beater.New, instance.Settings{Name: Name, HasDashboards: false})
35+
var RootCmd *cmd.BeatsRootCmd
36+
37+
// JournalbeatSettings contains the default settings for journalbeat
38+
func JournalbeatSettings() instance.Settings {
39+
return instance.Settings{Name: Name, HasDashboards: false}
40+
}
41+
42+
// Initialize initializes the entrypoint commands for journalbeat
43+
func Initialize(settings instance.Settings) *cmd.BeatsRootCmd {
44+
return cmd.GenRootCmdWithSettings(beater.New, settings)
45+
}
46+
47+
func init() {
48+
RootCmd = Initialize(JournalbeatSettings())
49+
}

journalbeat/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ func TestSystem(t *testing.T) {
4545
}
4646

4747
func TestTemplate(t *testing.T) {
48-
template.TestTemplate(t, cmd.Name)
48+
template.TestTemplate(t, cmd.Name, false)
4949
}

0 commit comments

Comments
 (0)