Skip to content

Commit

Permalink
Do not load dashboards where not available (#15802) (#15850)
Browse files Browse the repository at this point in the history
## What does this PR do?

This PR adds a new setting to Beat to indicate if it has a dashboard or not. If the Beat lacks dashboards, running `setup` does not attempt to load those.

## Why is it important?

Running the command `setup` fails if the Beat does not have dashboards in the appropriate folder.

## Checklist

<!-- Mandatory
Add a checklist of things that are required to be reviewed in order to have the PR approved

List here all the items you have verified BEFORE sending this PR. Please DO NOT remove any item, striking through those that do not apply. (Just in case, strikethrough uses two tildes. ~~Scratch this.~~)
-->

- [x] My code follows the style guidelines of this project
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] I have made the corresponding change to the default configuration files
- [x] I have added tests that prove my fix is effective or that my feature works

## How to test this PR locally

Both Journalbeat and Functionbeat are affected. So both Beats can/should be tested.

```sh
./functionbeat setup
```

## Related issues

Closes #13276
Closes #11751
(cherry picked from commit 8260623)
  • Loading branch information
kvch committed Jan 27, 2020
1 parent a7c3591 commit 2574e8f
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix panic in the Logstash output when trying to send events to closed connection. {pull}15568[15568]
- Fix missing output in dockerlogbeat {pull}15719[15719]
- Fix logging target settings being ignored when Beats are started via systemd or docker. {issue}12024[12024] {pull}15422[15442]
- Do not load dashboards where not available. {pull}15802[15802]

*Auditbeat*

Expand Down
7 changes: 6 additions & 1 deletion auditbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func init() {
),
)
var runFlags = pflag.NewFlagSet(Name, pflag.ExitOnError)
RootCmd = cmd.GenRootCmdWithSettings(create, instance.Settings{RunFlags: runFlags, Name: Name})
settings := instance.Settings{
RunFlags: runFlags,
Name: Name,
HasDashboards: true,
}
RootCmd = cmd.GenRootCmdWithSettings(create, settings)
RootCmd.AddCommand(ShowCmd)
}
7 changes: 6 additions & 1 deletion filebeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ func init() {
var runFlags = pflag.NewFlagSet(Name, pflag.ExitOnError)
runFlags.AddGoFlag(flag.CommandLine.Lookup("once"))
runFlags.AddGoFlag(flag.CommandLine.Lookup("modules"))
RootCmd = cmd.GenRootCmdWithSettings(beater.New, instance.Settings{RunFlags: runFlags, Name: Name})
settings := instance.Settings{
RunFlags: runFlags,
Name: Name,
HasDashboards: true,
}
RootCmd = cmd.GenRootCmdWithSettings(beater.New, settings)
RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("M"))
RootCmd.TestCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("modules"))
RootCmd.SetupCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("modules"))
Expand Down
5 changes: 3 additions & 2 deletions heartbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ var RootCmd *cmd.BeatsRootCmd

func init() {
settings := instance.Settings{
Name: Name,
Processing: processing.MakeDefaultSupport(true, processing.WithECS, processing.WithBeatMeta("agent")),
Name: Name,
Processing: processing.MakeDefaultSupport(true, processing.WithECS, processing.WithBeatMeta("agent")),
HasDashboards: false,
}
RootCmd = cmd.GenRootCmdWithSettings(beater.New, settings)

Expand Down
2 changes: 1 addition & 1 deletion journalbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ import (
var Name = "journalbeat"

// RootCmd to handle beats cli
var RootCmd = cmd.GenRootCmdWithSettings(beater.New, instance.Settings{Name: Name})
var RootCmd = cmd.GenRootCmdWithSettings(beater.New, instance.Settings{Name: Name, HasDashboards: false})
2 changes: 1 addition & 1 deletion libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func (b *Beat) Setup(settings Settings, bt beat.Creator, setup SetupSettings) er
fmt.Println("Index setup finished.")
}

if setup.Dashboard {
if setup.Dashboard && settings.HasDashboards {
fmt.Println("Loading dashboards (Kibana must be running and reachable)")
err = b.loadDashboards(context.Background(), true)

Expand Down
1 change: 1 addition & 0 deletions libbeat/cmd/instance/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Settings struct {
Name string
IndexPrefix string
Version string
HasDashboards bool
Monitoring report.Settings
RunFlags *pflag.FlagSet
ConfigOverrides []cfgfile.ConditionalOverride
Expand Down
2 changes: 1 addition & 1 deletion libbeat/mock/mockbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
var Version = "9.9.9"
var Name = "mockbeat"

var Settings = instance.Settings{Name: Name, Version: Version}
var Settings = instance.Settings{Name: Name, Version: Version, HasDashboards: true}

type Mockbeat struct {
done chan struct{}
Expand Down
1 change: 0 additions & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var (
// BeatsWithDashboards is a list of Beats to collect dashboards from.
BeatsWithDashboards = []string{
"heartbeat",
"journalbeat",
"packetbeat",
"winlogbeat",
"x-pack/auditbeat",
Expand Down
7 changes: 6 additions & 1 deletion metricbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ var RootCmd *cmd.BeatsRootCmd
func init() {
var runFlags = pflag.NewFlagSet(Name, pflag.ExitOnError)
runFlags.AddGoFlag(flag.CommandLine.Lookup("system.hostfs"))
RootCmd = cmd.GenRootCmdWithSettings(beater.DefaultCreator(), instance.Settings{RunFlags: runFlags, Name: Name})
settings := instance.Settings{
RunFlags: runFlags,
Name: Name,
HasDashboards: true,
}
RootCmd = cmd.GenRootCmdWithSettings(beater.DefaultCreator(), settings)
RootCmd.AddCommand(cmd.GenModulesCmd(Name, "", BuildModulesManager))
RootCmd.TestCmd.AddCommand(test.GenTestModulesCmd(Name, "", beater.DefaultTestModulesCreator()))
}
7 changes: 6 additions & 1 deletion packetbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func init() {
runFlags.AddGoFlag(flag.CommandLine.Lookup("l"))
runFlags.AddGoFlag(flag.CommandLine.Lookup("dump"))

RootCmd = cmd.GenRootCmdWithSettings(beater.New, instance.Settings{RunFlags: runFlags, Name: Name})
settings := instance.Settings{
RunFlags: runFlags,
Name: Name,
HasDashboards: true,
}
RootCmd = cmd.GenRootCmdWithSettings(beater.New, settings)
RootCmd.AddCommand(genDevicesCommand())
}
2 changes: 1 addition & 1 deletion winlogbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ import (
var Name = "winlogbeat"

// RootCmd to handle beats cli
var RootCmd = cmd.GenRootCmdWithSettings(beater.New, instance.Settings{Name: Name})
var RootCmd = cmd.GenRootCmdWithSettings(beater.New, instance.Settings{Name: Name, HasDashboards: true})
1 change: 1 addition & 0 deletions x-pack/functionbeat/manager/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var RootCmd *cmd.BeatsRootCmd
func init() {
RootCmd = cmd.GenRootCmdWithSettings(beater.New, instance.Settings{
Name: Name,
HasDashboards: false,
ConfigOverrides: config.Overrides,
})

Expand Down
7 changes: 6 additions & 1 deletion x-pack/metricbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ var RootCmd *cmd.BeatsRootCmd
func init() {
var runFlags = pflag.NewFlagSet(Name, pflag.ExitOnError)
runFlags.AddGoFlag(flag.CommandLine.Lookup("system.hostfs"))
RootCmd = cmd.GenRootCmdWithSettings(beater.DefaultCreator(), instance.Settings{RunFlags: runFlags, Name: Name})
settings := instance.Settings{
RunFlags: runFlags,
Name: Name,
HasDashboards: true,
}
RootCmd = cmd.GenRootCmdWithSettings(beater.DefaultCreator(), settings)
RootCmd.AddCommand(cmd.GenModulesCmd(Name, "", mbcmd.BuildModulesManager))
RootCmd.TestCmd.AddCommand(test.GenTestModulesCmd(Name, "", beater.DefaultTestModulesCreator()))
xpackcmd.AddXPack(RootCmd, Name)
Expand Down

0 comments on commit 2574e8f

Please sign in to comment.