Skip to content

Commit

Permalink
{,x-pack/}filebeat: clean up dead code (#30483)
Browse files Browse the repository at this point in the history
* {,x-pack/}filebeat: run gofumpt

[git-generate]
gofumpt -w ./{,x-pack/}filebeat

* {,x-pack/}filebeat: remove dead code an unused fields, vars and consts

This removes the majority of unused identified by running:

staticcheck -checks 'U*' ./{,x-pack/}filebeat/...

Care has been taken to not remove platform-specific code and mage-required code.
  • Loading branch information
efd6 authored Mar 1, 2022
1 parent ff8e234 commit 0192a90
Show file tree
Hide file tree
Showing 131 changed files with 557 additions and 696 deletions.
4 changes: 2 additions & 2 deletions filebeat/beater/acker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func TestACKer(t *testing.T) {
{
name: "only stateful",
data: []interface{}{file.State{Source: "-"}, file.State{Source: "-"}},
stateful: []file.State{file.State{Source: "-"}, file.State{Source: "-"}},
stateful: []file.State{{Source: "-"}, {Source: "-"}},
stateless: 0,
},
{
name: "both",
data: []interface{}{file.State{Source: "-"}, nil, file.State{Source: "-"}},
stateful: []file.State{file.State{Source: "-"}, file.State{Source: "-"}},
stateful: []file.State{{Source: "-"}, {Source: "-"}},
stateless: 1,
},
{
Expand Down
4 changes: 1 addition & 3 deletions filebeat/beater/filebeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ const pipelinesWarning = "Filebeat is unable to load the ingest pipelines for th
" already loaded the ingest pipelines or are using Logstash pipelines, you" +
" can ignore this warning."

var (
once = flag.Bool("once", false, "Run filebeat only once until all harvesters reach EOF")
)
var once = flag.Bool("once", false, "Run filebeat only once until all harvesters reach EOF")

// Filebeat is a beater object. Contains all objects needed to run the beat
type Filebeat struct {
Expand Down
5 changes: 0 additions & 5 deletions filebeat/beater/signalwait.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package beater

import (
"sync"
"time"

"github.com/elastic/beats/v7/libbeat/logp"
Expand Down Expand Up @@ -71,10 +70,6 @@ func (s *signalWait) Signal() {
s.Add(func() {})
}

func waitGroup(wg *sync.WaitGroup) signaler {
return wg.Wait
}

func waitChannel(c <-chan struct{}) signaler {
return func() { <-c }
}
Expand Down
3 changes: 1 addition & 2 deletions filebeat/channel/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ func newCommonConfigEditor(
var indexProcessor processors.Processor
if !config.Index.IsEmpty() {
staticFields := fmtstr.FieldsForBeat(beatInfo.Beat, beatInfo.Version)
timestampFormat, err :=
fmtstr.NewTimestampFormatString(&config.Index, staticFields)
timestampFormat, err := fmtstr.NewTimestampFormatString(&config.Index, staticFields)
if err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion filebeat/channel/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (o *subOutlet) Done() <-chan struct{} {
}

func (o *subOutlet) OnEvent(event beat.Event) bool {

o.mutex.Lock()
defer o.mutex.Unlock()
select {
Expand Down
4 changes: 1 addition & 3 deletions filebeat/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import (
"github.com/elastic/beats/v7/libbeat/paths"
)

var (
defaultHomePath = paths.Resolve(paths.Home, "")
)
var defaultHomePath = paths.Resolve(paths.Home, "")

func genGenerateCmd() *cobra.Command {
generateCmd := cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion filebeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var RootCmd *cmd.BeatsRootCmd

// FilebeatSettings contains the default settings for filebeat
func FilebeatSettings() instance.Settings {
var runFlags = pflag.NewFlagSet(Name, pflag.ExitOnError)
runFlags := pflag.NewFlagSet(Name, pflag.ExitOnError)
runFlags.AddGoFlag(flag.CommandLine.Lookup("once"))
runFlags.AddGoFlag(flag.CommandLine.Lookup("modules"))
return instance.Settings{
Expand Down
24 changes: 10 additions & 14 deletions filebeat/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,16 @@ type Registry struct {
MigrateFile string `config:"migrate_file"`
}

var (
DefaultConfig = Config{
Registry: Registry{
Path: "registry",
Permissions: 0600,
MigrateFile: "",
CleanInterval: 5 * time.Minute,
},
ShutdownTimeout: 0,
OverwritePipelines: false,
}
)
var DefaultConfig = Config{
Registry: Registry{
Path: "registry",
Permissions: 0o600,
MigrateFile: "",
CleanInterval: 5 * time.Minute,
},
ShutdownTimeout: 0,
OverwritePipelines: false,
}

// getConfigFiles returns list of config files.
// In case path is a file, it will be directly returned.
Expand All @@ -86,7 +84,6 @@ func getConfigFiles(path string) (configFiles []string, err error) {

if stat.IsDir() {
files, err := filepath.Glob(path + "/*.yml")

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -138,7 +135,6 @@ func (config *Config) FetchConfigs() error {
logp.Info("Additional config files are fetched from: %s", configDir)

configFiles, err := getConfigFiles(configDir)

if err != nil {
log.Fatal("Could not use config_dir of: ", configDir, err)
return err
Expand Down
Loading

0 comments on commit 0192a90

Please sign in to comment.