diff --git a/filebeat/beater/acker_test.go b/filebeat/beater/acker_test.go index 19a8476bbf53..4200552f31bc 100644 --- a/filebeat/beater/acker_test.go +++ b/filebeat/beater/acker_test.go @@ -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, }, { diff --git a/filebeat/beater/filebeat.go b/filebeat/beater/filebeat.go index c266faf10ae1..2f3623d977d3 100644 --- a/filebeat/beater/filebeat.go +++ b/filebeat/beater/filebeat.go @@ -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 { diff --git a/filebeat/beater/signalwait.go b/filebeat/beater/signalwait.go index a6115f8d7066..f9501a6e095d 100644 --- a/filebeat/beater/signalwait.go +++ b/filebeat/beater/signalwait.go @@ -18,7 +18,6 @@ package beater import ( - "sync" "time" "github.com/elastic/beats/v7/libbeat/logp" @@ -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 } } diff --git a/filebeat/channel/runner.go b/filebeat/channel/runner.go index 11e31ad88415..1019dc2ff274 100644 --- a/filebeat/channel/runner.go +++ b/filebeat/channel/runner.go @@ -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 } diff --git a/filebeat/channel/util.go b/filebeat/channel/util.go index 2c2125534548..4097c789e4d6 100644 --- a/filebeat/channel/util.go +++ b/filebeat/channel/util.go @@ -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 { diff --git a/filebeat/cmd/generate.go b/filebeat/cmd/generate.go index 822b1acc953b..23a636eb049d 100644 --- a/filebeat/cmd/generate.go +++ b/filebeat/cmd/generate.go @@ -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{ diff --git a/filebeat/cmd/root.go b/filebeat/cmd/root.go index 1a17e64cdbbf..2831a10bd64a 100644 --- a/filebeat/cmd/root.go +++ b/filebeat/cmd/root.go @@ -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{ diff --git a/filebeat/config/config.go b/filebeat/config/config.go index 75289d2f0c94..3a294dc22c47 100644 --- a/filebeat/config/config.go +++ b/filebeat/config/config.go @@ -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. @@ -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 } @@ -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 diff --git a/filebeat/fileset/compatibility_test.go b/filebeat/fileset/compatibility_test.go index 79b10eb263df..c82b3087c82b 100644 --- a/filebeat/fileset/compatibility_test.go +++ b/filebeat/fileset/compatibility_test.go @@ -48,7 +48,8 @@ func TestAdaptPipelineForCompatibility(t *testing.T) { "field": "foo.http_user_agent", }, }, - }}, + }, + }, isErrExpected: true, }, { @@ -159,7 +160,8 @@ func TestReplaceSetIgnoreEmptyValue(t *testing.T) { "ignore_empty_value": true, }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -185,7 +187,8 @@ func TestReplaceSetIgnoreEmptyValue(t *testing.T) { "ignore_empty_value": true, }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -211,7 +214,8 @@ func TestReplaceSetIgnoreEmptyValue(t *testing.T) { "ignore_empty_value": true, }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -238,7 +242,8 @@ func TestReplaceSetIgnoreEmptyValue(t *testing.T) { "if": "ctx?.panw?.panos?.ruleset != null", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -248,7 +253,8 @@ func TestReplaceSetIgnoreEmptyValue(t *testing.T) { "if": "ctx?.panw?.panos?.ruleset != null", }, }, - }}, + }, + }, isErrExpected: false, }, { @@ -264,7 +270,8 @@ func TestReplaceSetIgnoreEmptyValue(t *testing.T) { "if": "ctx?.panw?.panos?.ruleset != null", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -274,7 +281,8 @@ func TestReplaceSetIgnoreEmptyValue(t *testing.T) { "if": "ctx?.panw?.panos?.ruleset != null", }, }, - }}, + }, + }, isErrExpected: false, }, { @@ -288,7 +296,8 @@ func TestReplaceSetIgnoreEmptyValue(t *testing.T) { "ignore_empty_value": false, }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -296,7 +305,8 @@ func TestReplaceSetIgnoreEmptyValue(t *testing.T) { "field": "rule.name", }, }, - }}, + }, + }, isErrExpected: false, }, } @@ -336,7 +346,8 @@ func TestReplaceAppendAllowDuplicates(t *testing.T) { "allow_duplicates": true, }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -361,7 +372,8 @@ func TestReplaceAppendAllowDuplicates(t *testing.T) { "allow_duplicates": false, }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -387,7 +399,8 @@ func TestReplaceAppendAllowDuplicates(t *testing.T) { "allow_duplicates": false, }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -413,7 +426,8 @@ func TestReplaceAppendAllowDuplicates(t *testing.T) { "allow_duplicates": false, }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -440,7 +454,8 @@ func TestReplaceAppendAllowDuplicates(t *testing.T) { "if": "ctx?.host?.hostname != null", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -450,7 +465,8 @@ func TestReplaceAppendAllowDuplicates(t *testing.T) { "if": "ctx?.host?.hostname != null && ((ctx?.related?.hosts instanceof List && !ctx?.related?.hosts.contains(ctx?.host?.hostname)) || ctx?.related?.hosts != ctx?.host?.hostname)", }, }, - }}, + }, + }, isErrExpected: false, }, { @@ -466,7 +482,8 @@ func TestReplaceAppendAllowDuplicates(t *testing.T) { "if": "!ctx?.related?.hosts.contains(ctx?.host?.hostname)", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -476,7 +493,8 @@ func TestReplaceAppendAllowDuplicates(t *testing.T) { "if": "!ctx?.related?.hosts.contains(ctx?.host?.hostname)", }, }, - }}, + }, + }, isErrExpected: false, }, { @@ -490,7 +508,8 @@ func TestReplaceAppendAllowDuplicates(t *testing.T) { "allow_duplicates": false, }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -498,7 +517,8 @@ func TestReplaceAppendAllowDuplicates(t *testing.T) { "field": "related.hosts", }, }, - }}, + }, + }, isErrExpected: false, }, } @@ -543,7 +563,8 @@ func TestRemoveURIPartsProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -573,7 +594,8 @@ func TestRemoveURIPartsProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -588,7 +610,8 @@ func TestRemoveURIPartsProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, isErrExpected: false, }, { @@ -608,7 +631,8 @@ func TestRemoveURIPartsProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -623,7 +647,8 @@ func TestRemoveURIPartsProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, isErrExpected: false, }, } @@ -670,7 +695,8 @@ func TestRemoveNetworkDirectionProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -702,7 +728,8 @@ func TestRemoveNetworkDirectionProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -719,7 +746,8 @@ func TestRemoveNetworkDirectionProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, isErrExpected: false, }, { @@ -741,7 +769,8 @@ func TestRemoveNetworkDirectionProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -758,7 +787,8 @@ func TestRemoveNetworkDirectionProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, isErrExpected: false, }, } @@ -985,7 +1015,8 @@ func TestRemoveRegisteredDomainProcessor(t *testing.T) { "field": "foo", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -1014,7 +1045,8 @@ func TestRemoveRegisteredDomainProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -1028,7 +1060,8 @@ func TestRemoveRegisteredDomainProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, isErrExpected: false, }, { @@ -1047,7 +1080,8 @@ func TestRemoveRegisteredDomainProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -1061,7 +1095,8 @@ func TestRemoveRegisteredDomainProcessor(t *testing.T) { "value": "testvalue", }, }, - }}, + }, + }, isErrExpected: false, }, } @@ -1369,7 +1404,8 @@ func TestRemoveDescription(t *testing.T) { "description": "This is a description", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -1400,7 +1436,8 @@ func TestRemoveDescription(t *testing.T) { "description": "This is a description", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ @@ -1426,7 +1463,8 @@ func TestRemoveDescription(t *testing.T) { "description": "This is a description", }, }, - }}, + }, + }, expected: map[string]interface{}{ "processors": []interface{}{ map[string]interface{}{ diff --git a/filebeat/fileset/factory.go b/filebeat/fileset/factory.go index 12c74d33e31c..0ad4186bb662 100644 --- a/filebeat/fileset/factory.go +++ b/filebeat/fileset/factory.go @@ -32,9 +32,7 @@ import ( "github.com/elastic/beats/v7/libbeat/outputs/elasticsearch" ) -var ( - moduleList = monitoring.NewUniqueList() -) +var moduleList = monitoring.NewUniqueList() func init() { monitoring.NewFunc(monitoring.GetNamespace("state").GetRegistry(), "module", moduleList.Report, monitoring.Report) diff --git a/filebeat/fileset/fileset.go b/filebeat/fileset/fileset.go index 52947f0c67fa..c0573982751b 100644 --- a/filebeat/fileset/fileset.go +++ b/filebeat/fileset/fileset.go @@ -64,8 +64,8 @@ func New( modulesPath string, name string, mname string, - fcfg *FilesetConfig) (*Fileset, error) { - + fcfg *FilesetConfig) (*Fileset, error, +) { modulePath := filepath.Join(modulesPath, mname) if _, err := os.Stat(modulePath); os.IsNotExist(err) { return nil, fmt.Errorf("module %s (%s) doesn't exist", mname, modulePath) diff --git a/filebeat/fileset/modules.go b/filebeat/fileset/modules.go index 3591fb97590b..80f72ca14c60 100644 --- a/filebeat/fileset/modules.go +++ b/filebeat/fileset/modules.go @@ -261,8 +261,8 @@ func getModuleFilesets(modulePath, module string) ([]string, error) { func applyOverrides(fcfg *FilesetConfig, module, fileset string, - overrides *ModuleOverrides) (*FilesetConfig, error) { - + overrides *ModuleOverrides) (*FilesetConfig, error, +) { if overrides == nil { return fcfg, nil } diff --git a/filebeat/fileset/modules_integration_test.go b/filebeat/fileset/modules_integration_test.go index be22b9c16803..18fa9b478aff 100644 --- a/filebeat/fileset/modules_integration_test.go +++ b/filebeat/fileset/modules_integration_test.go @@ -191,7 +191,7 @@ func TestLoadMultiplePipelines(t *testing.T) { "multibad": {Enabled: &disabled}, } configs := []*ModuleConfig{ - &ModuleConfig{"foo", &enabled, filesetConfigs}, + {"foo", &enabled, filesetConfigs}, } reg, err := newModuleRegistry(modulesPath, configs, nil, makeTestInfo("6.6.0")) diff --git a/filebeat/fileset/modules_test.go b/filebeat/fileset/modules_test.go index 79da4ceab090..428dc360723e 100644 --- a/filebeat/fileset/modules_test.go +++ b/filebeat/fileset/modules_test.go @@ -206,7 +206,8 @@ func TestApplyOverrides(t *testing.T) { "nginx": map[string]*common.Config{ "access": load(t, map[string]interface{}{ "var.a": "test1", - "var.b.c": "test2"}), + "var.b.c": "test2", + }), }, }, expected: FilesetConfig{ @@ -232,7 +233,8 @@ func TestApplyOverrides(t *testing.T) { "nginx": map[string]*common.Config{ "access": load(t, map[string]interface{}{ "enabled": true, - "var.paths": []interface{}{"/var/local/nginx/log"}}), + "var.paths": []interface{}{"/var/local/nginx/log"}, + }), }, }, expected: FilesetConfig{ @@ -624,5 +626,4 @@ func TestEnableFilesetsFromOverrides(t *testing.T) { assert.Equal(t, test.Expected, test.Cfg) }) } - } diff --git a/filebeat/fileset/pipelines.go b/filebeat/fileset/pipelines.go index 03ee9200a97e..660a151ad269 100644 --- a/filebeat/fileset/pipelines.go +++ b/filebeat/fileset/pipelines.go @@ -182,7 +182,6 @@ func interpretError(initialErr error, body []byte) error { return fmt.Errorf("this module requires an Elasticsearch plugin that provides the %s processor. "+ "Please visit the Elasticsearch documentation for instructions on how to install this plugin. "+ "Response body: %s", response.Error.RootCause[0].Header.ProcessorType, body) - } // older ES version? diff --git a/filebeat/generator/fields/fields.go b/filebeat/generator/fields/fields.go index 7f26081201d0..4727990b2332 100644 --- a/filebeat/generator/fields/fields.go +++ b/filebeat/generator/fields/fields.go @@ -30,38 +30,33 @@ import ( ) const ( - pipelinePath = "%s/module/%s/%s/ingest/pipeline.json" - fieldsYmlPath = "%s/module/%s/%s/_meta/fields.yml" - typeIdx = 0 elementsIdx = 1 hintIdx = 2 ) -var ( - types = map[string]string{ - "group": "group", - "DATA": "text", - "GREEDYDATA": "text", - "GREEDYMULTILINE": "text", - "HOSTNAME": "keyword", - "IP": "ip", - "IPV4": "ip", - "IPV6": "ip", - "IPHOST": "keyword", - "IPORHOST": "keyword", - "LOGLEVEL": "keyword", - "MULTILINEQUERY": "text", - "NUMBER": "long", - "POSINT": "long", - "SYSLOGHOST": "keyword", - "SYSLOGTIMESTAMP": "text", - "LOCALDATETIME": "text", - "TIMESTAMP": "text", - "USERNAME": "keyword", - "WORD": "keyword", - } -) +var types = map[string]string{ + "group": "group", + "DATA": "text", + "GREEDYDATA": "text", + "GREEDYMULTILINE": "text", + "HOSTNAME": "keyword", + "IP": "ip", + "IPV4": "ip", + "IPV6": "ip", + "IPHOST": "keyword", + "IPORHOST": "keyword", + "LOGLEVEL": "keyword", + "MULTILINEQUERY": "text", + "NUMBER": "long", + "POSINT": "long", + "SYSLOGHOST": "keyword", + "SYSLOGTIMESTAMP": "text", + "LOCALDATETIME": "text", + "TIMESTAMP": "text", + "USERNAME": "keyword", + "WORD": "keyword", +} type pipeline struct { Description string `json:"description"` @@ -121,7 +116,7 @@ func readPipeline(filesetPath string) (*pipeline, error) { func writeFieldsYml(filesetPath string, fieldsBytes []byte) error { output := filepath.Join(filesetPath, "_meta/fields.yml") - return ioutil.WriteFile(output, fieldsBytes, 0644) + return ioutil.WriteFile(output, fieldsBytes, 0o644) } func newFieldYml(name, typeName string, noDoc bool) *fieldYml { diff --git a/filebeat/generator/fields/fields_test.go b/filebeat/generator/fields/fields_test.go index bba33e08d892..d500c4ed62dc 100644 --- a/filebeat/generator/fields/fields_test.go +++ b/filebeat/generator/fields/fields_test.go @@ -36,7 +36,7 @@ type RemoveProcessorTestCase struct { func TestFieldsGenerator(t *testing.T) { tests := []FieldsGeneratorTestCase{ - FieldsGeneratorTestCase{ + { patterns: []string{ "%{LOCALDATETIME:postgresql.log.timestamp} %{WORD:postgresql.log.timezone} \\[%{NUMBER:postgresql.log.thread_id}\\] %{USERNAME:postgresql.log.user}@%{HOSTNAME:postgresql.log.database} %{WORD:postgresql.log.level}: duration: %{NUMBER:postgresql.log.duration} ms statement: %{MULTILINEQUERY:postgresql.log.query}", "%{LOCALDATETIME:postgresql.log.timestamp} %{WORD:postgresql.log.timezone} \\[%{NUMBER:postgresql.log.thread_id}\\] \\[%{USERNAME:postgresql.log.user}\\]@\\[%{HOSTNAME:postgresql.log.database}\\] %{WORD:postgresql.log.level}: duration: %{NUMBER:postgresql.log.duration} ms statement: %{MULTILINEQUERY:postgresql.log.query}", @@ -45,94 +45,98 @@ func TestFieldsGenerator(t *testing.T) { "%{LOCALDATETIME:postgresql.log.timestamp} %{WORD:postgresql.log.timezone} \\[%{NUMBER:postgresql.log.thread_id}\\] %{WORD:postgresql.log.level}: ?%{GREEDYDATA:postgresql.log.message}", }, fields: []*fieldYml{ - &fieldYml{Name: "log", Description: "Please add description", Example: "Please add example", Type: "group", Fields: []*fieldYml{ - &fieldYml{Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, - &fieldYml{Name: "timezone", Description: "Please add description", Example: "Please add example", Type: "keyword"}, - &fieldYml{Name: "thread_id", Description: "Please add description", Example: "Please add example", Type: "long"}, - &fieldYml{Name: "user", Description: "Please add description", Example: "Please add example", Type: "keyword"}, - &fieldYml{Name: "database", Description: "Please add description", Example: "Please add example", Type: "keyword"}, - &fieldYml{Name: "level", Description: "Please add description", Example: "Please add example", Type: "keyword"}, - &fieldYml{Name: "duration", Description: "Please add description", Example: "Please add example", Type: "long"}, - &fieldYml{Name: "query", Description: "Please add description", Example: "Please add example", Type: "text"}, - &fieldYml{Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, - }, + { + Name: "log", Description: "Please add description", Example: "Please add example", Type: "group", Fields: []*fieldYml{ + {Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, + {Name: "timezone", Description: "Please add description", Example: "Please add example", Type: "keyword"}, + {Name: "thread_id", Description: "Please add description", Example: "Please add example", Type: "long"}, + {Name: "user", Description: "Please add description", Example: "Please add example", Type: "keyword"}, + {Name: "database", Description: "Please add description", Example: "Please add example", Type: "keyword"}, + {Name: "level", Description: "Please add description", Example: "Please add example", Type: "keyword"}, + {Name: "duration", Description: "Please add description", Example: "Please add example", Type: "long"}, + {Name: "query", Description: "Please add description", Example: "Please add example", Type: "text"}, + {Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, + }, }, }, }, - FieldsGeneratorTestCase{ + { patterns: []string{ "%{DATA:nginx.error.time} \\[%{DATA:nginx.error.level}\\] %{NUMBER:nginx.error.pid}#%{NUMBER:nginx.error.tid}: (\\*%{NUMBER:nginx.error.connection_id} )?%{GREEDYDATA:nginx.error.message}", }, fields: []*fieldYml{ - &fieldYml{Name: "error", Description: "Please add description", Example: "Please add example", Type: "group", Fields: []*fieldYml{ - &fieldYml{Name: "time", Description: "Please add description", Example: "Please add example", Type: "text"}, - &fieldYml{Name: "level", Description: "Please add description", Example: "Please add example", Type: "text"}, - &fieldYml{Name: "pid", Description: "Please add description", Example: "Please add example", Type: "long"}, - &fieldYml{Name: "tid", Description: "Please add description", Example: "Please add example", Type: "long"}, - &fieldYml{Name: "connection_id", Description: "Please add description", Example: "Please add example", Type: "long"}, - &fieldYml{Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, - }, + { + Name: "error", Description: "Please add description", Example: "Please add example", Type: "group", Fields: []*fieldYml{ + {Name: "time", Description: "Please add description", Example: "Please add example", Type: "text"}, + {Name: "level", Description: "Please add description", Example: "Please add example", Type: "text"}, + {Name: "pid", Description: "Please add description", Example: "Please add example", Type: "long"}, + {Name: "tid", Description: "Please add description", Example: "Please add example", Type: "long"}, + {Name: "connection_id", Description: "Please add description", Example: "Please add example", Type: "long"}, + {Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, + }, }, }, }, - FieldsGeneratorTestCase{ + { patterns: []string{ "\\[%{TIMESTAMP:icinga.main.timestamp}\\] %{WORD:icinga.main.severity}/%{WORD:icinga.main.facility}: %{GREEDYMULTILINE:icinga.main.message}", }, fields: []*fieldYml{ - &fieldYml{Name: "main", Description: "Please add description", Example: "Please add example", Type: "group", Fields: []*fieldYml{ - &fieldYml{Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, - &fieldYml{Name: "severity", Description: "Please add description", Example: "Please add example", Type: "keyword"}, - &fieldYml{Name: "facility", Description: "Please add description", Example: "Please add example", Type: "keyword"}, - &fieldYml{Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, - }, + { + Name: "main", Description: "Please add description", Example: "Please add example", Type: "group", Fields: []*fieldYml{ + {Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, + {Name: "severity", Description: "Please add description", Example: "Please add example", Type: "keyword"}, + {Name: "facility", Description: "Please add description", Example: "Please add example", Type: "keyword"}, + {Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, + }, }, }, }, - FieldsGeneratorTestCase{ + { patterns: []string{ "(%{POSINT:redis.log.pid}:%{CHAR:redis.log.role} )?%{REDISTIMESTAMP:redis.log.timestamp} %{REDISLEVEL:redis.log.level} %{GREEDYDATA:redis.log.message}", "%{POSINT:redis.log.pid}:signal-handler \\(%{POSINT:redis.log.timestamp}\\) %{GREEDYDATA:redis.log.message}", }, fields: []*fieldYml{ - &fieldYml{Name: "log", Description: "Please add description", Example: "Please add example", Type: "group", Fields: []*fieldYml{ - &fieldYml{Name: "pid", Description: "Please add description", Example: "Please add example", Type: "long"}, - &fieldYml{Name: "role", Description: "Please add description", Example: "Please add example"}, - &fieldYml{Name: "timestamp", Description: "Please add description", Example: "Please add example"}, - &fieldYml{Name: "level", Description: "Please add description", Example: "Please add example"}, - &fieldYml{Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, - }, + { + Name: "log", Description: "Please add description", Example: "Please add example", Type: "group", Fields: []*fieldYml{ + {Name: "pid", Description: "Please add description", Example: "Please add example", Type: "long"}, + {Name: "role", Description: "Please add description", Example: "Please add example"}, + {Name: "timestamp", Description: "Please add description", Example: "Please add example"}, + {Name: "level", Description: "Please add description", Example: "Please add example"}, + {Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, + }, }, }, }, - FieldsGeneratorTestCase{ + { patterns: []string{ "\\[%{TIMESTAMP:timestamp}\\] %{WORD:severity}/%{WORD:facility}: %{GREEDYMULTILINE:message}", }, fields: []*fieldYml{ - &fieldYml{Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, - &fieldYml{Name: "severity", Description: "Please add description", Example: "Please add example", Type: "keyword"}, - &fieldYml{Name: "facility", Description: "Please add description", Example: "Please add example", Type: "keyword"}, - &fieldYml{Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, + {Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, + {Name: "severity", Description: "Please add description", Example: "Please add example", Type: "keyword"}, + {Name: "facility", Description: "Please add description", Example: "Please add example", Type: "keyword"}, + {Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, }, }, - FieldsGeneratorTestCase{ + { patterns: []string{ "\\[%{TIMESTAMP:timestamp}\\] %{WORD:severity}/%{WORD}: %{GREEDYMULTILINE:message}", }, fields: []*fieldYml{ - &fieldYml{Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, - &fieldYml{Name: "severity", Description: "Please add description", Example: "Please add example", Type: "keyword"}, - &fieldYml{Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, + {Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, + {Name: "severity", Description: "Please add description", Example: "Please add example", Type: "keyword"}, + {Name: "message", Description: "Please add description", Example: "Please add example", Type: "text"}, }, }, - FieldsGeneratorTestCase{ + { patterns: []string{ "\\[%{TIMESTAMP:timestamp}\\] %{NUMBER:idx:int}", }, fields: []*fieldYml{ - &fieldYml{Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, - &fieldYml{Name: "idx", Description: "Please add description", Example: "Please add example", Type: "int"}, + {Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, + {Name: "idx", Description: "Please add description", Example: "Please add example", Type: "int"}, }, }, } @@ -155,23 +159,24 @@ func TestFieldsGenerator(t *testing.T) { func TestFieldsGeneratorKnownLimitations(t *testing.T) { tests := []FieldsGeneratorTestCase{ // FIXME Field names including dots are not parsed properly - FieldsGeneratorTestCase{ + { patterns: []string{ "^# User@Host: %{USER:mysql.slowlog.user}(\\[[^\\]]+\\])? @ %{HOSTNAME:mysql.slowlog.host} \\[(%{IP:mysql.slowlog.ip})?\\](\\s*Id:\\s* %{NUMBER:mysql.slowlog.id})?\n# Query_time: %{NUMBER:mysql.slowlog.query_time.sec}\\s* Lock_time: %{NUMBER:mysql.slowlog.lock_time.sec}\\s* Rows_sent: %{NUMBER:mysql.slowlog.rows_sent}\\s* Rows_examined: %{NUMBER:mysql.slowlog.rows_examined}\n(SET timestamp=%{NUMBER:mysql.slowlog.timestamp};\n)?%{GREEDYMULTILINE:mysql.slowlog.query}", }, fields: []*fieldYml{ - &fieldYml{Name: "slowlog", Description: "Please add description", Example: "Please add example", Type: "group", Fields: []*fieldYml{ - &fieldYml{Name: "user", Description: "Please add description", Example: "Please add example", Type: "keyword"}, - &fieldYml{Name: "host", Description: "Please add description", Example: "Please add example", Type: "keyword"}, - &fieldYml{Name: "ip", Description: "Please add description", Example: "Please add example"}, - &fieldYml{Name: "id", Description: "Please add description", Example: "Please add example", Type: "long"}, - &fieldYml{Name: "query_time.ms", Description: "Please add description", Example: "Please add example", Type: "long"}, - &fieldYml{Name: "lock_time.ms", Description: "Please add description", Example: "Please add example", Type: "long"}, - &fieldYml{Name: "rows_sent", Description: "Please add description", Example: "Please add example", Type: "long"}, - &fieldYml{Name: "rows_examined", Description: "Please add description", Example: "Please add example", Type: "long"}, - &fieldYml{Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, - &fieldYml{Name: "query", Description: "Please add description", Example: "Please add example", Type: "text"}, - }, + { + Name: "slowlog", Description: "Please add description", Example: "Please add example", Type: "group", Fields: []*fieldYml{ + {Name: "user", Description: "Please add description", Example: "Please add example", Type: "keyword"}, + {Name: "host", Description: "Please add description", Example: "Please add example", Type: "keyword"}, + {Name: "ip", Description: "Please add description", Example: "Please add example"}, + {Name: "id", Description: "Please add description", Example: "Please add example", Type: "long"}, + {Name: "query_time.ms", Description: "Please add description", Example: "Please add example", Type: "long"}, + {Name: "lock_time.ms", Description: "Please add description", Example: "Please add example", Type: "long"}, + {Name: "rows_sent", Description: "Please add description", Example: "Please add example", Type: "long"}, + {Name: "rows_examined", Description: "Please add description", Example: "Please add example", Type: "long"}, + {Name: "timestamp", Description: "Please add description", Example: "Please add example", Type: "text"}, + {Name: "query", Description: "Please add description", Example: "Please add example", Type: "text"}, + }, }, }, }, @@ -193,25 +198,25 @@ func TestFieldsGeneratorKnownLimitations(t *testing.T) { func TestRemoveProcessor(t *testing.T) { tests := []RemoveProcessorTestCase{ - RemoveProcessorTestCase{ + { processor: map[string]interface{}{ "field": []string{}, }, fields: []string{}, }, - RemoveProcessorTestCase{ + { processor: map[string]interface{}{ "field": []interface{}{}, }, fields: []string{}, }, - RemoveProcessorTestCase{ + { processor: map[string]interface{}{ "field": "prospector.type", }, fields: []string{"prospector.type"}, }, - RemoveProcessorTestCase{ + { processor: map[string]interface{}{ "field": []string{"prospector.type", "input.type"}, }, diff --git a/filebeat/generator/generator.go b/filebeat/generator/generator.go index 40df8311ede3..b490864e61bd 100644 --- a/filebeat/generator/generator.go +++ b/filebeat/generator/generator.go @@ -38,7 +38,7 @@ func DirExists(dir string) bool { func CreateDirectories(baseDir string, directories ...string) error { for _, d := range directories { p := path.Join(baseDir, d) - err := os.MkdirAll(p, 0750) + err := os.MkdirAll(p, 0o750) if err != nil { return err } @@ -66,7 +66,7 @@ func AppendTemplate(template, dest string, replace map[string]string) error { return err } - f, err := os.OpenFile(dest, os.O_WRONLY|os.O_APPEND, 0644) + f, err := os.OpenFile(dest, os.O_WRONLY|os.O_APPEND, 0o644) if err == nil { _, err = f.Write(c) } @@ -83,7 +83,7 @@ func copyTemplate(template, dest string, replace map[string]string) error { return err } - err = ioutil.WriteFile(dest, c, 0644) + err = ioutil.WriteFile(dest, c, 0o644) if err != nil { return fmt.Errorf("cannot copy template: %v", err) } diff --git a/filebeat/generator/module/module.go b/filebeat/generator/module/module.go index 64a470dcb17e..e725e57e462f 100644 --- a/filebeat/generator/module/module.go +++ b/filebeat/generator/module/module.go @@ -32,7 +32,7 @@ func Generate(module, modulesPath, beatsPath string) error { return fmt.Errorf("module already exists: %s", module) } - err := os.MkdirAll(path.Join(modulePath, "_meta"), 0750) + err := os.MkdirAll(path.Join(modulePath, "_meta"), 0o750) if err != nil { return err } diff --git a/filebeat/input/config.go b/filebeat/input/config.go index 448a878a607d..bd393f14cdbc 100644 --- a/filebeat/input/config.go +++ b/filebeat/input/config.go @@ -24,12 +24,10 @@ import ( "github.com/elastic/beats/v7/libbeat/common/cfgwarn" ) -var ( - defaultConfig = inputConfig{ - ScanFrequency: 10 * time.Second, - Type: cfg.DefaultType, - } -) +var defaultConfig = inputConfig{ + ScanFrequency: 10 * time.Second, + Type: cfg.DefaultType, +} type inputConfig struct { ScanFrequency time.Duration `config:"scan_frequency" validate:"min=0,nonzero"` diff --git a/filebeat/input/file/file.go b/filebeat/input/file/file.go index 963a1015fb8c..3a92eaea5639 100644 --- a/filebeat/input/file/file.go +++ b/filebeat/input/file/file.go @@ -34,7 +34,6 @@ type File struct { // It is used to check if the file has been renamed. func IsSameFile(path string, info os.FileInfo) bool { fileInfo, err := os.Stat(path) - if err != nil { logp.Err("Error during file comparison: %s with %s - Error: %s", path, info.Name(), err) return false diff --git a/filebeat/input/file/glob_test.go b/filebeat/input/file/glob_test.go index 97b1e250ee99..7bdd124f892c 100644 --- a/filebeat/input/file/glob_test.go +++ b/filebeat/input/file/glob_test.go @@ -34,7 +34,7 @@ func TestGlob(t *testing.T) { if err != nil { t.Fatal(err) } - os.MkdirAll(filepath.Join(root, "foo/bar/baz/qux/quux"), 0755) + os.MkdirAll(filepath.Join(root, "foo/bar/baz/qux/quux"), 0o755) for _, test := range globTests { pattern := filepath.Join(root, test.pattern) matches, err := Glob(pattern, 4) diff --git a/filebeat/input/file/identifier.go b/filebeat/input/file/identifier.go index c16535f3e19e..120a468da6de 100644 --- a/filebeat/input/file/identifier.go +++ b/filebeat/input/file/identifier.go @@ -36,13 +36,11 @@ const ( identitySep = "::" ) -var ( - identifierFactories = map[string]IdentifierFactory{ - nativeName: newINodeDeviceIdentifier, - pathName: newPathIdentifier, - inodeMarkerName: newINodeMarkerIdentifier, - } -) +var identifierFactories = map[string]IdentifierFactory{ + nativeName: newINodeDeviceIdentifier, + pathName: newPathIdentifier, + inodeMarkerName: newINodeMarkerIdentifier, +} type IdentifierFactory func(*common.Config) (StateIdentifier, error) diff --git a/filebeat/input/file/identifier_test.go b/filebeat/input/file/identifier_test.go index 8990f16ea28e..d5231a39a578 100644 --- a/filebeat/input/file/identifier_test.go +++ b/filebeat/input/file/identifier_test.go @@ -40,11 +40,11 @@ func TestINodeDeviceIdentifier(t *testing.T) { tests := map[string]stateTestCase{ "two states poiting to the same file": { [2]State{ - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 1, Device: 1}, }, - State{ + { Source: "/path/to/this/file/2", FileStateOS: file.StateOS{Inode: 1, Device: 1}, }, @@ -53,11 +53,11 @@ func TestINodeDeviceIdentifier(t *testing.T) { }, "two states poiting to different files": { [2]State{ - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 1, Device: 1}, }, - State{ + { Source: "/path/to/this/file/2", FileStateOS: file.StateOS{Inode: 2, Device: 1}, }, @@ -84,11 +84,11 @@ func TestPathIdentifier(t *testing.T) { tests := map[string]stateTestCase{ "two states poiting to the same file": { [2]State{ - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 1, Device: 1}, }, - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 1, Device: 1}, }, @@ -97,11 +97,11 @@ func TestPathIdentifier(t *testing.T) { }, "two states poiting to different files": { [2]State{ - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 1, Device: 1}, }, - State{ + { Source: "/path/to/this/file/2", FileStateOS: file.StateOS{Inode: 2, Device: 1}, }, @@ -127,11 +127,11 @@ func TestInodeMarkerIdentifier(t *testing.T) { tests := map[string]stateTestCase{ "two states poiting to the same file i.": { [2]State{ - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 1, Device: 1}, }, - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 1, Device: 1}, }, @@ -140,11 +140,11 @@ func TestInodeMarkerIdentifier(t *testing.T) { }, "two states poiting to the same file ii.": { [2]State{ - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 1, Device: 1}, }, - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 1, Device: 2}, }, @@ -153,11 +153,11 @@ func TestInodeMarkerIdentifier(t *testing.T) { }, "two states poiting to different files i.": { [2]State{ - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 1, Device: 1}, }, - State{ + { Source: "/path/to/this/file/2", FileStateOS: file.StateOS{Inode: 2, Device: 1}, }, @@ -166,11 +166,11 @@ func TestInodeMarkerIdentifier(t *testing.T) { }, "two states poiting to different files ii.": { [2]State{ - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 1, Device: 1}, }, - State{ + { Source: "/path/to/this/file/1", FileStateOS: file.StateOS{Inode: 2, Device: 3}, }, diff --git a/filebeat/input/file/states_test.go b/filebeat/input/file/states_test.go index 5e1fb3890b56..6f77d5063334 100644 --- a/filebeat/input/file/states_test.go +++ b/filebeat/input/file/states_test.go @@ -39,21 +39,24 @@ var cleanupTests = []struct { State{ TTL: 0, Finished: true, - }, 1, 1, 0, + }, + 1, 1, 0, }, { "Unfinished but TTL set to 0", State{ TTL: 0, Finished: false, - }, 1, 0, 1, + }, + 1, 0, 1, }, { "TTL = -1 means not expiring", State{ TTL: -1, Finished: true, - }, 1, 0, 1, + }, + 1, 0, 1, }, { "Expired and finished", @@ -61,7 +64,8 @@ var cleanupTests = []struct { TTL: 1 * time.Second, Timestamp: time.Now().Add(-2 * time.Second), Finished: true, - }, 1, 1, 0, + }, + 1, 1, 0, }, { "Expired but unfinished", @@ -69,7 +73,8 @@ var cleanupTests = []struct { TTL: 1 * time.Second, Timestamp: time.Now().Add(-2 * time.Second), Finished: false, - }, 1, 0, 1, + }, + 1, 0, 1, }, } diff --git a/filebeat/input/filestream/copytruncate_prospector.go b/filebeat/input/filestream/copytruncate_prospector.go index 5c217332de08..2611ab0c30fd 100644 --- a/filebeat/input/filestream/copytruncate_prospector.go +++ b/filebeat/input/filestream/copytruncate_prospector.go @@ -37,9 +37,7 @@ const ( copiedFileIdx = 0 ) -var ( - numericSuffixRegexp = regexp.MustCompile("\\d*$") -) +var numericSuffixRegexp = regexp.MustCompile("\\d*$") // sorter is required for ordering rotated log files // The slice is ordered so the newest rotated file comes first. @@ -169,12 +167,6 @@ func (r rotatedFilestreams) isOriginalAdded(path string) bool { return ok } -// originalSrc returns the original Source information of a given -// original file path. -func (r rotatedFilestreams) originalSrc(path string) loginp.Source { - return r.table[path].originalSrc -} - // addRotatedFile adds a new rotated file to the list and returns its index. // if a file is already added, the source is updated and the index is returned. func (r rotatedFilestreams) addRotatedFile(original, rotated string, src loginp.Source) int { @@ -197,17 +189,6 @@ func (r rotatedFilestreams) addRotatedFile(original, rotated string, src loginp. return -1 } -// addRotatedFile adds a new rotated file to the list and returns its index. -// if a file is already added, the source is updated and the index is returned. -func (r rotatedFilestreams) removeRotatedFile(original, rotated string) { - for idx, fi := range r.table[original].rotated { - if fi.path == rotated { - r.table[original].rotated = append(r.table[original].rotated[:idx], r.table[original].rotated[idx+1:]...) - return - } - } -} - type copyTruncateFileProspector struct { fileProspector rotatedSuffix *regexp.Regexp @@ -261,12 +242,10 @@ func (p *copyTruncateFileProspector) onFSEvent( group loginp.HarvesterGroup, ignoreSince time.Time, ) { - switch event.Op { case loginp.OpCreate, loginp.OpWrite: if event.Op == loginp.OpCreate { log.Debugf("A new file %s has been found", event.NewPath) - } else if event.Op == loginp.OpWrite { log.Debugf("File %s has been updated", event.NewPath) } @@ -323,6 +302,7 @@ func (p *copyTruncateFileProspector) onFSEvent( log.Error("Unkown return value %v", event.Op) } } + func (p *copyTruncateFileProspector) isRotated(event loginp.FSEvent) bool { if p.rotatedSuffix.MatchString(event.NewPath) { return true diff --git a/filebeat/input/filestream/copytruncate_prospector_test.go b/filebeat/input/filestream/copytruncate_prospector_test.go index 52d6b1e33915..277ef8ba9444 100644 --- a/filebeat/input/filestream/copytruncate_prospector_test.go +++ b/filebeat/input/filestream/copytruncate_prospector_test.go @@ -38,8 +38,8 @@ func TestCopyTruncateProspector_Create(t *testing.T) { }{ "one new file, then rotated": { events: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/file"}, - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, + {Op: loginp.OpCreate, NewPath: "/path/to/file"}, + {Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, }, expectedEvents: []harvesterEvent{ harvesterStart("path::/path/to/file"), @@ -47,19 +47,19 @@ func TestCopyTruncateProspector_Create(t *testing.T) { harvesterGroupStop{}, }, expectedRotatedFiles: map[string][]string{ - "/path/to/file": []string{ + "/path/to/file": { "/path/to/file.1", }, }, }, "one new file, then rotated twice in order": { events: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/file"}, - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, - loginp.FSEvent{Op: loginp.OpTruncate, NewPath: "/path/to/file"}, - loginp.FSEvent{Op: loginp.OpRename, NewPath: "/path/to/file.2", OldPath: "/path/to/file.1"}, - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, - loginp.FSEvent{Op: loginp.OpTruncate, NewPath: "/path/to/file"}, + {Op: loginp.OpCreate, NewPath: "/path/to/file"}, + {Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, + {Op: loginp.OpTruncate, NewPath: "/path/to/file"}, + {Op: loginp.OpRename, NewPath: "/path/to/file.2", OldPath: "/path/to/file.1"}, + {Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, + {Op: loginp.OpTruncate, NewPath: "/path/to/file"}, }, expectedEvents: []harvesterEvent{ harvesterStart("path::/path/to/file"), @@ -72,7 +72,7 @@ func TestCopyTruncateProspector_Create(t *testing.T) { harvesterGroupStop{}, }, expectedRotatedFiles: map[string][]string{ - "/path/to/file": []string{ + "/path/to/file": { "/path/to/file.1", "/path/to/file.2", }, @@ -80,13 +80,13 @@ func TestCopyTruncateProspector_Create(t *testing.T) { }, "one new file, then rotated twice with renaming": { events: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/file.2"}, - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/file"}, - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, - loginp.FSEvent{Op: loginp.OpRename, NewPath: "/path/to/file.3", OldPath: "/path/to/file.2"}, - loginp.FSEvent{Op: loginp.OpRename, NewPath: "/path/to/file.2", OldPath: "/path/to/file.1"}, - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, - loginp.FSEvent{Op: loginp.OpTruncate, NewPath: "/path/to/file"}, + {Op: loginp.OpCreate, NewPath: "/path/to/file.2"}, + {Op: loginp.OpCreate, NewPath: "/path/to/file"}, + {Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, + {Op: loginp.OpRename, NewPath: "/path/to/file.3", OldPath: "/path/to/file.2"}, + {Op: loginp.OpRename, NewPath: "/path/to/file.2", OldPath: "/path/to/file.1"}, + {Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, + {Op: loginp.OpTruncate, NewPath: "/path/to/file"}, }, expectedEvents: []harvesterEvent{ harvesterStart("path::/path/to/file.2"), @@ -101,7 +101,7 @@ func TestCopyTruncateProspector_Create(t *testing.T) { harvesterGroupStop{}, }, expectedRotatedFiles: map[string][]string{ - "/path/to/file": []string{ + "/path/to/file": { "/path/to/file.1", "/path/to/file.2", "/path/to/file.3", @@ -110,7 +110,7 @@ func TestCopyTruncateProspector_Create(t *testing.T) { }, "first rotated file, when rotated file not exist": { events: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, + {Op: loginp.OpCreate, NewPath: "/path/to/file.1"}, }, expectedEvents: []harvesterEvent{ harvesterStart("path::/path/to/file.1"), @@ -167,7 +167,7 @@ func TestNumericSorter(t *testing.T) { }{ "one fileinfo": { fileinfos: []rotatedFileInfo{ - rotatedFileInfo{path: "/path/to/apache.log.1"}, + {path: "/path/to/apache.log.1"}, }, expectedOrder: []string{ "/path/to/apache.log.1", @@ -175,9 +175,9 @@ func TestNumericSorter(t *testing.T) { }, "ordered fileinfos": { fileinfos: []rotatedFileInfo{ - rotatedFileInfo{path: "/path/to/apache.log.1"}, - rotatedFileInfo{path: "/path/to/apache.log.2"}, - rotatedFileInfo{path: "/path/to/apache.log.3"}, + {path: "/path/to/apache.log.1"}, + {path: "/path/to/apache.log.2"}, + {path: "/path/to/apache.log.3"}, }, expectedOrder: []string{ "/path/to/apache.log.1", @@ -187,9 +187,9 @@ func TestNumericSorter(t *testing.T) { }, "unordered fileinfos": { fileinfos: []rotatedFileInfo{ - rotatedFileInfo{path: "/path/to/apache.log.3"}, - rotatedFileInfo{path: "/path/to/apache.log.1"}, - rotatedFileInfo{path: "/path/to/apache.log.2"}, + {path: "/path/to/apache.log.3"}, + {path: "/path/to/apache.log.1"}, + {path: "/path/to/apache.log.2"}, }, expectedOrder: []string{ "/path/to/apache.log.1", @@ -199,9 +199,9 @@ func TestNumericSorter(t *testing.T) { }, "unordered fileinfos with numbers in filename": { fileinfos: []rotatedFileInfo{ - rotatedFileInfo{path: "/path/to/apache42.log.3"}, - rotatedFileInfo{path: "/path/to/apache43.log.1"}, - rotatedFileInfo{path: "/path/to/apache44.log.2"}, + {path: "/path/to/apache42.log.3"}, + {path: "/path/to/apache43.log.1"}, + {path: "/path/to/apache44.log.2"}, }, expectedOrder: []string{ "/path/to/apache43.log.1", @@ -219,10 +219,10 @@ func TestNumericSorter(t *testing.T) { for i, fi := range test.fileinfos { require.Equal(t, test.expectedOrder[i], fi.path) } - }) } } + func TestDateSorter(t *testing.T) { testCases := map[string]struct { fileinfos []rotatedFileInfo @@ -230,7 +230,7 @@ func TestDateSorter(t *testing.T) { }{ "one fileinfo": { fileinfos: []rotatedFileInfo{ - rotatedFileInfo{path: "/path/to/apache.log-20140506"}, + {path: "/path/to/apache.log-20140506"}, }, expectedOrder: []string{ "/path/to/apache.log-20140506", @@ -238,9 +238,9 @@ func TestDateSorter(t *testing.T) { }, "ordered fileinfos": { fileinfos: []rotatedFileInfo{ - rotatedFileInfo{path: "/path/to/apache.log-20140506"}, - rotatedFileInfo{path: "/path/to/apache.log-20140507"}, - rotatedFileInfo{path: "/path/to/apache.log-20140508"}, + {path: "/path/to/apache.log-20140506"}, + {path: "/path/to/apache.log-20140507"}, + {path: "/path/to/apache.log-20140508"}, }, expectedOrder: []string{ "/path/to/apache.log-20140508", @@ -250,9 +250,9 @@ func TestDateSorter(t *testing.T) { }, "unordered fileinfos": { fileinfos: []rotatedFileInfo{ - rotatedFileInfo{path: "/path/to/apache.log-20140507"}, - rotatedFileInfo{path: "/path/to/apache.log-20140508"}, - rotatedFileInfo{path: "/path/to/apache.log-20140506"}, + {path: "/path/to/apache.log-20140507"}, + {path: "/path/to/apache.log-20140508"}, + {path: "/path/to/apache.log-20140506"}, }, expectedOrder: []string{ "/path/to/apache.log-20140508", @@ -270,7 +270,6 @@ func TestDateSorter(t *testing.T) { for i, fi := range test.fileinfos { require.Equal(t, test.expectedOrder[i], fi.path) } - }) } } diff --git a/filebeat/input/filestream/environment_test.go b/filebeat/input/filestream/environment_test.go index e5de5aabd05c..623ea4166e4b 100644 --- a/filebeat/input/filestream/environment_test.go +++ b/filebeat/input/filestream/environment_test.go @@ -15,6 +15,9 @@ // specific language governing permissions and limitations // under the License. +//go:build integration +// +build integration + package filestream import ( @@ -107,7 +110,7 @@ func (e *inputTestingEnvironment) waitUntilInputStops() { func (e *inputTestingEnvironment) mustWriteLinesToFile(filename string, lines []byte) { path := e.abspath(filename) - err := ioutil.WriteFile(path, lines, 0644) + err := ioutil.WriteFile(path, lines, 0o644) if err != nil { e.t.Fatalf("failed to write file '%s': %+v", path, err) } @@ -115,7 +118,7 @@ func (e *inputTestingEnvironment) mustWriteLinesToFile(filename string, lines [] func (e *inputTestingEnvironment) mustAppendLinesToFile(filename string, lines []byte) { path := e.abspath(filename) - f, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0644) + f, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0o644) if err != nil { e.t.Fatalf("failed to open file '%s': %+v", path, err) } @@ -505,7 +508,6 @@ func (pc *mockPipelineConnector) ConnectWith(config beat.ClientConfig) (beat.Cli pc.clients = append(pc.clients, c) return c, nil - } func (pc *mockPipelineConnector) cancelAllClients() { @@ -534,7 +536,6 @@ func newMockACKHandler(starter context.Context, blocking bool, config beat.Clien } return acker.Combine(blockingACKer(starter), config.ACKHandler) - } func blockingACKer(starter context.Context) beat.ACKer { diff --git a/filebeat/input/filestream/filestream.go b/filebeat/input/filestream/filestream.go index 884fbd213a99..82da084a5c7d 100644 --- a/filebeat/input/filestream/filestream.go +++ b/filebeat/input/filestream/filestream.go @@ -175,7 +175,6 @@ func (f *logFile) shouldBeClosed() bool { if !f.closeRemoved && !f.closeRenamed { return false - } info, statErr := f.file.Stat() diff --git a/filebeat/input/filestream/fswatch.go b/filebeat/input/filestream/fswatch.go index 822763de022d..3930cd79b9ff 100644 --- a/filebeat/input/filestream/fswatch.go +++ b/filebeat/input/filestream/fswatch.go @@ -38,11 +38,9 @@ const ( watcherDebugKey = "file_watcher" ) -var ( - watcherFactories = map[string]watcherFactory{ - scannerName: newScannerWatcher, - } -) +var watcherFactories = map[string]watcherFactory{ + scannerName: newScannerWatcher, +} type watcherFactory func(paths []string, cfg *common.Config) (loginp.FSWatcher, error) @@ -198,7 +196,6 @@ func (w *fileWatcher) watch(ctx unison.Canceler) { return case w.events <- createEvent(path, info): } - } w.log.Debugf("Found %d paths", len(paths)) diff --git a/filebeat/input/filestream/fswatch_test.go b/filebeat/input/filestream/fswatch_test.go index 54fe3804f02d..3992e78f0a72 100644 --- a/filebeat/input/filestream/fswatch_test.go +++ b/filebeat/input/filestream/fswatch_test.go @@ -96,7 +96,7 @@ func TestFileScanner(t *testing.T) { } files := fs.GetFiles() paths := make([]string, 0) - for p, _ := range files { + for p := range files { paths = append(paths, p) } assert.ElementsMatch(t, paths, test.expectedFiles) @@ -132,7 +132,7 @@ func TestFileWatchNewDeleteModified(t *testing.T) { "new_path": testFileInfo{"new_path", 5, oldTs, nil}, }, expectedEvents: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpCreate, OldPath: "", NewPath: "new_path", Info: testFileInfo{"new_path", 5, oldTs, nil}}, + {Op: loginp.OpCreate, OldPath: "", NewPath: "new_path", Info: testFileInfo{"new_path", 5, oldTs, nil}}, }, }, "one deleted file": { @@ -141,7 +141,7 @@ func TestFileWatchNewDeleteModified(t *testing.T) { }, nextFiles: map[string]os.FileInfo{}, expectedEvents: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpDelete, OldPath: "old_path", NewPath: "", Info: testFileInfo{"old_path", 5, oldTs, nil}}, + {Op: loginp.OpDelete, OldPath: "old_path", NewPath: "", Info: testFileInfo{"old_path", 5, oldTs, nil}}, }, }, "one modified file": { @@ -152,7 +152,7 @@ func TestFileWatchNewDeleteModified(t *testing.T) { "path": testFileInfo{"path", 10, newTs, nil}, }, expectedEvents: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpWrite, OldPath: "path", NewPath: "path", Info: testFileInfo{"path", 10, newTs, nil}}, + {Op: loginp.OpWrite, OldPath: "path", NewPath: "path", Info: testFileInfo{"path", 10, newTs, nil}}, }, }, "two modified files": { @@ -165,8 +165,8 @@ func TestFileWatchNewDeleteModified(t *testing.T) { "path2": testFileInfo{"path2", 10, newTs, nil}, }, expectedEvents: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpWrite, OldPath: "path1", NewPath: "path1", Info: testFileInfo{"path1", 10, newTs, nil}}, - loginp.FSEvent{Op: loginp.OpWrite, OldPath: "path2", NewPath: "path2", Info: testFileInfo{"path2", 10, newTs, nil}}, + {Op: loginp.OpWrite, OldPath: "path1", NewPath: "path1", Info: testFileInfo{"path1", 10, newTs, nil}}, + {Op: loginp.OpWrite, OldPath: "path2", NewPath: "path2", Info: testFileInfo{"path2", 10, newTs, nil}}, }, }, "one modified file, one new file": { @@ -178,8 +178,8 @@ func TestFileWatchNewDeleteModified(t *testing.T) { "path2": testFileInfo{"path2", 10, newTs, nil}, }, expectedEvents: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpWrite, OldPath: "path1", NewPath: "path1", Info: testFileInfo{"path1", 10, newTs, nil}}, - loginp.FSEvent{Op: loginp.OpCreate, OldPath: "", NewPath: "path2", Info: testFileInfo{"path2", 10, newTs, nil}}, + {Op: loginp.OpWrite, OldPath: "path1", NewPath: "path1", Info: testFileInfo{"path1", 10, newTs, nil}}, + {Op: loginp.OpCreate, OldPath: "", NewPath: "path2", Info: testFileInfo{"path2", 10, newTs, nil}}, }, }, "one new file, one deleted file": { @@ -190,8 +190,8 @@ func TestFileWatchNewDeleteModified(t *testing.T) { "path_new": testFileInfo{"path_new", 10, newTs, nil}, }, expectedEvents: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpDelete, OldPath: "path_deleted", NewPath: "", Info: testFileInfo{"path_deleted", 5, oldTs, nil}}, - loginp.FSEvent{Op: loginp.OpCreate, OldPath: "", NewPath: "path_new", Info: testFileInfo{"path_new", 10, newTs, nil}}, + {Op: loginp.OpDelete, OldPath: "path_deleted", NewPath: "", Info: testFileInfo{"path_deleted", 5, oldTs, nil}}, + {Op: loginp.OpCreate, OldPath: "", NewPath: "path_new", Info: testFileInfo{"path_new", 10, newTs, nil}}, }, }, } @@ -241,11 +241,3 @@ func (t testFileInfo) Mode() os.FileMode { return 0 } func (t testFileInfo) ModTime() time.Time { return t.time } func (t testFileInfo) IsDir() bool { return false } func (t testFileInfo) Sys() interface{} { return t.sys } - -func mustDuration(durStr string) time.Duration { - dur, err := time.ParseDuration(durStr) - if err != nil { - panic(err) - } - return dur -} diff --git a/filebeat/input/filestream/fswatch_test_non_windows.go b/filebeat/input/filestream/fswatch_test_non_windows.go index ec8045f7c533..20bb0ebede93 100644 --- a/filebeat/input/filestream/fswatch_test_non_windows.go +++ b/filebeat/input/filestream/fswatch_test_non_windows.go @@ -112,7 +112,7 @@ func TestFileScannerSymlinks(t *testing.T) { } files := fs.GetFiles() paths := make([]string, 0) - for p, _ := range files { + for p := range files { paths = append(paths, p) } assert.ElementsMatch(t, test.expectedFiles, paths) diff --git a/filebeat/input/filestream/identifier.go b/filebeat/input/filestream/identifier.go index 4e2e5643fdac..418953df244b 100644 --- a/filebeat/input/filestream/identifier.go +++ b/filebeat/input/filestream/identifier.go @@ -41,13 +41,11 @@ const ( identitySep = "::" ) -var ( - identifierFactories = map[string]identifierFactory{ - nativeName: newINodeDeviceIdentifier, - pathName: newPathIdentifier, - inodeMarkerName: newINodeMarkerIdentifier, - } -) +var identifierFactories = map[string]identifierFactory{ + nativeName: newINodeDeviceIdentifier, + pathName: newPathIdentifier, + inodeMarkerName: newINodeMarkerIdentifier, +} type identifierFactory func(*common.Config) (fileIdentifier, error) diff --git a/filebeat/input/filestream/internal/input-logfile/fswatch.go b/filebeat/input/filestream/internal/input-logfile/fswatch.go index 9982f370e4f9..4f8fffe67414 100644 --- a/filebeat/input/filestream/internal/input-logfile/fswatch.go +++ b/filebeat/input/filestream/internal/input-logfile/fswatch.go @@ -33,17 +33,15 @@ const ( OpArchived ) -var ( - operationNames = map[Operation]string{ - OpDone: "done", - OpCreate: "create", - OpWrite: "write", - OpDelete: "delete", - OpRename: "rename", - OpTruncate: "truncate", - OpArchived: "archive", - } -) +var operationNames = map[Operation]string{ + OpDone: "done", + OpCreate: "create", + OpWrite: "write", + OpDelete: "delete", + OpRename: "rename", + OpTruncate: "truncate", + OpArchived: "archive", +} // Operation describes what happened to a file. type Operation uint8 diff --git a/filebeat/input/filestream/internal/input-logfile/harvester_test.go b/filebeat/input/filestream/internal/input-logfile/harvester_test.go index fda9737487c5..b10a440abef4 100644 --- a/filebeat/input/filestream/internal/input-logfile/harvester_test.go +++ b/filebeat/input/filestream/internal/input-logfile/harvester_test.go @@ -94,7 +94,6 @@ func TestReaderGroup(t *testing.T) { ctx, cf, err = rg.newContext("test-id", context.Background()) requireGroupError(t, ctx, cf, err) }) - } func TestDefaultHarvesterGroup(t *testing.T) { diff --git a/filebeat/input/filestream/internal/input-logfile/manager.go b/filebeat/input/filestream/internal/input-logfile/manager.go index 2f5317270858..0e5aed17c358 100644 --- a/filebeat/input/filestream/internal/input-logfile/manager.go +++ b/filebeat/input/filestream/internal/input-logfile/manager.go @@ -81,7 +81,6 @@ type Source interface { Name() string } -var errNoSourceConfigured = errors.New("no source has been configured") var errNoInputRunner = errors.New("no input runner available") const globalInputID = ".global" diff --git a/filebeat/input/filestream/internal/input-logfile/manager_test.go b/filebeat/input/filestream/internal/input-logfile/manager_test.go index aa97b2b4dc35..7379f6841d83 100644 --- a/filebeat/input/filestream/internal/input-logfile/manager_test.go +++ b/filebeat/input/filestream/internal/input-logfile/manager_test.go @@ -41,8 +41,8 @@ func TestSourceIdentifier_ID(t *testing.T) { }{ "plugin with no user configured ID": { sources: []*testSource{ - &testSource{"unique_name"}, - &testSource{"another_unique_name"}, + {"unique_name"}, + {"another_unique_name"}, }, expectedSourceIDs: []string{ testPluginName + "::.global::unique_name", @@ -111,7 +111,6 @@ func TestSourceIdentifier_MachesInput(t *testing.T) { } func TestSourceIdentifier_NotMachesInput(t *testing.T) { - testCases := map[string]struct { userID string notMatchingIDs []string diff --git a/filebeat/input/filestream/internal/input-logfile/publish.go b/filebeat/input/filestream/internal/input-logfile/publish.go index 3272f2a73f9f..222d5ed95d80 100644 --- a/filebeat/input/filestream/internal/input-logfile/publish.go +++ b/filebeat/input/filestream/internal/input-logfile/publish.go @@ -54,7 +54,6 @@ type updateOp struct { // state updates to persist timestamp time.Time - ttl time.Duration delta interface{} } diff --git a/filebeat/input/filestream/internal/input-logfile/store.go b/filebeat/input/filestream/internal/input-logfile/store.go index 426234753442..ae6aa8758235 100644 --- a/filebeat/input/filestream/internal/input-logfile/store.go +++ b/filebeat/input/filestream/internal/input-logfile/store.go @@ -302,7 +302,6 @@ func (s *store) writeState(r *resource) { } else { r.stored = true } - } // resetCursor sets the cursor to the value in cur in the persistent store and @@ -366,7 +365,7 @@ func (s *store) UpdateTTL(resource *resource, ttl time.Duration) { // instances do not overwrite the removal of the entry resource.version++ // invalidate it after it has been persisted to make sure it cannot - //be overwritten in the persistent store + // be overwritten in the persistent store resource.invalid = true } } @@ -554,7 +553,6 @@ func readStates(log *logp.Logger, store *statestore.Store, prefix string) (*stat return true, nil }) - if err != nil { return nil, err } diff --git a/filebeat/input/filestream/internal/input-logfile/store_test.go b/filebeat/input/filestream/internal/input-logfile/store_test.go index ce05aad13e85..2330320cf668 100644 --- a/filebeat/input/filestream/internal/input-logfile/store_test.go +++ b/filebeat/input/filestream/internal/input-logfile/store_test.go @@ -319,7 +319,6 @@ func TestStore_ResetCursor(t *testing.T) { require.Equal(t, map[string]interface{}{"offset": int64(0)}, res.cursor) require.Equal(t, nil, res.pendingCursorValue) require.Equal(t, nil, res.pendingUpdate) - }) } @@ -330,11 +329,11 @@ type testMeta struct { func TestSourceStore_UpdateIdentifiers(t *testing.T) { t.Run("update identifiers when TTL is bigger than zero", func(t *testing.T) { backend := createSampleStore(t, map[string]state{ - "test::key1": state{ + "test::key1": { TTL: 60 * time.Second, Meta: testMeta{IdentifierName: "method"}, }, - "test::key2": state{ + "test::key2": { TTL: 0 * time.Second, Meta: testMeta{IdentifierName: "method"}, }, @@ -351,27 +350,25 @@ func TestSourceStore_UpdateIdentifiers(t *testing.T) { } if m.IdentifierName == "method" { return "test::key1::updated", testMeta{IdentifierName: "something"} - } return "", nil - }) var newState state s.persistentStore.Get("test::key1::updated", &newState) want := map[string]state{ - "test::key1": state{ + "test::key1": { Updated: s.Get("test::key1").internalState.Updated, TTL: 60 * time.Second, Meta: map[string]interface{}{"identifiername": "method"}, }, - "test::key2": state{ + "test::key2": { Updated: s.Get("test::key2").internalState.Updated, TTL: 0 * time.Second, Meta: map[string]interface{}{"identifiername": "method"}, }, - "test::key1::updated": state{ + "test::key1::updated": { Updated: newState.Updated, TTL: 60 * time.Second, Meta: map[string]interface{}{"identifiername": "something"}, @@ -385,10 +382,10 @@ func TestSourceStore_UpdateIdentifiers(t *testing.T) { func TestSourceStore_CleanIf(t *testing.T) { t.Run("entries are cleaned when funtion returns true", func(t *testing.T) { backend := createSampleStore(t, map[string]state{ - "test::key1": state{ + "test::key1": { TTL: 60 * time.Second, }, - "test::key2": state{ + "test::key2": { TTL: 0 * time.Second, }, }) @@ -401,11 +398,11 @@ func TestSourceStore_CleanIf(t *testing.T) { }) want := map[string]state{ - "test::key1": state{ + "test::key1": { Updated: s.Get("test::key1").internalState.Updated, TTL: 0 * time.Second, }, - "test::key2": state{ + "test::key2": { Updated: s.Get("test::key2").internalState.Updated, TTL: 0 * time.Second, }, @@ -417,10 +414,10 @@ func TestSourceStore_CleanIf(t *testing.T) { t.Run("entries are left alone when funtion returns false", func(t *testing.T) { backend := createSampleStore(t, map[string]state{ - "test::key1": state{ + "test::key1": { TTL: 60 * time.Second, }, - "test::key2": state{ + "test::key2": { TTL: 0 * time.Second, }, }) @@ -433,11 +430,11 @@ func TestSourceStore_CleanIf(t *testing.T) { }) want := map[string]state{ - "test::key1": state{ + "test::key1": { Updated: s.Get("test::key1").internalState.Updated, TTL: 60 * time.Second, }, - "test::key2": state{ + "test::key2": { Updated: s.Get("test::key2").internalState.Updated, TTL: 0 * time.Second, }, @@ -506,7 +503,6 @@ func (ts testStateStore) snapshot() map[string]state { states[key] = st return true, nil }) - if err != nil { panic("unexpected decode error from persistent test store") } @@ -558,15 +554,3 @@ func checkEqualStoreState(t *testing.T, want, got map[string]state) bool { } return true } - -// requireEqualStoreState compares 2 store snapshot tables for equality. The test -// fails with Fatalf if the state differ. -// -// Note: testify is too strict when comparing timestamp, better use checkEqualStoreState. -func requireEqualStoreState(t *testing.T, want, got map[string]state) bool { - if d := cmp.Diff(want, got); d != "" { - t.Fatalf("store state mismatch (-want +got):\n%s", d) - return false - } - return true -} diff --git a/filebeat/input/filestream/parsers_integration_test.go b/filebeat/input/filestream/parsers_integration_test.go index e652abb041d9..cdaadd0ac0d2 100644 --- a/filebeat/input/filestream/parsers_integration_test.go +++ b/filebeat/input/filestream/parsers_integration_test.go @@ -33,7 +33,7 @@ func TestParsersAgentLogs(t *testing.T) { "paths": []string{env.abspath(testlogName)}, "prospector.scanner.check_interval": "1ms", "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "ndjson": map[string]interface{}{ "message_key": "log", "overwrite_keys": true, @@ -68,7 +68,7 @@ func TestParsersDockerLogsFiltering(t *testing.T) { "paths": []string{env.abspath(testlogName)}, "prospector.scanner.check_interval": "1ms", "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "ndjson": map[string]interface{}{ "message_key": "log", "target": "", @@ -106,7 +106,7 @@ func TestParsersSimpleJSONOverwrite(t *testing.T) { "paths": []string{env.abspath(testlogName)}, "prospector.scanner.check_interval": "1ms", "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "ndjson": map[string]interface{}{ "message_key": "message", "target": "", @@ -141,7 +141,7 @@ func TestParsersTimestampInJSONMessage(t *testing.T) { "paths": []string{env.abspath(testlogName)}, "prospector.scanner.check_interval": "1ms", "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "ndjson": map[string]interface{}{ "target": "", "overwrite_keys": true, @@ -181,7 +181,7 @@ func TestParsersJavaElasticsearchLogs(t *testing.T) { "paths": []string{env.abspath(testlogName)}, "prospector.scanner.check_interval": "1ms", "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "multiline": map[string]interface{}{ "type": "pattern", "pattern": "^\\[", @@ -215,7 +215,7 @@ func TestParsersCStyleLog(t *testing.T) { "paths": []string{env.abspath(testlogName)}, "prospector.scanner.check_interval": "1ms", "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "multiline": map[string]interface{}{ "type": "pattern", "pattern": "\\\\$", @@ -255,7 +255,7 @@ func TestParsersRabbitMQMultilineLog(t *testing.T) { "paths": []string{env.abspath(testlogName)}, "prospector.scanner.check_interval": "1ms", "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "multiline": map[string]interface{}{ "type": "pattern", "pattern": "^=[A-Z]+", @@ -299,7 +299,7 @@ func TestParsersMultilineMaxLines(t *testing.T) { "paths": []string{env.abspath(testlogName)}, "prospector.scanner.check_interval": "1ms", "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "multiline": map[string]interface{}{ "type": "pattern", "pattern": "^\\[", @@ -342,7 +342,7 @@ func TestParsersMultilineTimeout(t *testing.T) { "paths": []string{env.abspath(testlogName)}, "prospector.scanner.check_interval": "1ms", "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "multiline": map[string]interface{}{ "type": "pattern", "pattern": "^\\[", @@ -383,7 +383,8 @@ func TestParsersMultilineTimeout(t *testing.T) { env.waitUntilEventCount(3) env.requireOffsetInRegistry(testlogName, len(testlines)+len(moreLines)) - env.requireEventsReceived([]string{`[2015] hello world + env.requireEventsReceived([]string{ + `[2015] hello world First Line Second Line`, ` This should not be third @@ -406,7 +407,7 @@ func TestParsersMultilineMaxBytes(t *testing.T) { "prospector.scanner.check_interval": "1ms", "message_max_bytes": 50, "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "multiline": map[string]interface{}{ "type": "pattern", "pattern": "^\\[", @@ -447,7 +448,7 @@ func TestParsersCloseTimeoutWithMultiline(t *testing.T) { "prospector.scanner.check_interval": "1ms", "close.reader.after_interval": "1s", "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "multiline": map[string]interface{}{ "type": "pattern", "pattern": "^\\[", @@ -487,7 +488,8 @@ func TestParsersCloseTimeoutWithMultiline(t *testing.T) { env.waitUntilEventCount(3) env.requireOffsetInRegistry(testlogName, len(testlines)+len(moreLines)) - env.requireEventsReceived([]string{`[2015] hello world + env.requireEventsReceived([]string{ + `[2015] hello world First Line Second Line`, ` This should not be third @@ -502,7 +504,6 @@ func TestParsersCloseTimeoutWithMultiline(t *testing.T) { // test_consecutive_newline from test_multiline.py func TestParsersConsecutiveNewline(t *testing.T) { - env := newInputTestingEnvironment(t) testlogName := "test.log" @@ -511,7 +512,7 @@ func TestParsersConsecutiveNewline(t *testing.T) { "prospector.scanner.check_interval": "1ms", "close.reader.after_interval": "1s", "parsers": []map[string]interface{}{ - map[string]interface{}{ + { "multiline": map[string]interface{}{ "type": "pattern", "pattern": "^\\[", diff --git a/filebeat/input/filestream/prospector.go b/filebeat/input/filestream/prospector.go index 8c7bf28f5e9c..6d1684f93b90 100644 --- a/filebeat/input/filestream/prospector.go +++ b/filebeat/input/filestream/prospector.go @@ -42,12 +42,10 @@ const ( prospectorDebugKey = "file_prospector" ) -var ( - ignoreInactiveSettings = map[string]ignoreInactiveType{ - ignoreInactiveSinceLastStartStr: IgnoreInactiveSinceLastStart, - ignoreInactiveSinceFirstStartStr: IgnoreInactiveSinceFirstStart, - } -) +var ignoreInactiveSettings = map[string]ignoreInactiveType{ + ignoreInactiveSinceLastStartStr: IgnoreInactiveSinceLastStart, + ignoreInactiveSinceFirstStartStr: IgnoreInactiveSinceFirstStart, +} // fileProspector implements the Prospector interface. // It contains a file scanner which returns file system events. @@ -149,7 +147,6 @@ func (p *fileProspector) onFSEvent( group loginp.HarvesterGroup, ignoreSince time.Time, ) { - switch event.Op { case loginp.OpCreate, loginp.OpWrite: if event.Op == loginp.OpCreate { diff --git a/filebeat/input/filestream/prospector_creator.go b/filebeat/input/filestream/prospector_creator.go index f792b075cf33..9457af104cf9 100644 --- a/filebeat/input/filestream/prospector_creator.go +++ b/filebeat/input/filestream/prospector_creator.go @@ -33,9 +33,7 @@ const ( copytruncateStrategy = "copytruncate" ) -var ( - experimentalWarning sync.Once -) +var experimentalWarning sync.Once func newProspector(config config) (loginp.Prospector, error) { filewatcher, err := newFileWatcher(config.Paths, config.FileWatcher) diff --git a/filebeat/input/filestream/prospector_test.go b/filebeat/input/filestream/prospector_test.go index 83dc2055df0c..fac311abb76f 100644 --- a/filebeat/input/filestream/prospector_test.go +++ b/filebeat/input/filestream/prospector_test.go @@ -90,7 +90,6 @@ func TestProspector_InitCleanIfRemoved(t *testing.T) { assert.ElementsMatch(t, testCase.expectedCleanedKeys, testStore.cleanedKeys) }) } - } func TestProspector_InitUpdateIdentifiers(t *testing.T) { @@ -157,7 +156,6 @@ func TestProspector_InitUpdateIdentifiers(t *testing.T) { assert.EqualValues(t, testCase.expectedUpdatedKeys, testStore.updatedKeys) }) } - } func TestProspectorNewAndUpdatedFiles(t *testing.T) { @@ -170,8 +168,8 @@ func TestProspectorNewAndUpdatedFiles(t *testing.T) { }{ "two new files": { events: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/file", Info: testFileInfo{}}, - loginp.FSEvent{Op: loginp.OpCreate, NewPath: "/path/to/other/file", Info: testFileInfo{}}, + {Op: loginp.OpCreate, NewPath: "/path/to/file", Info: testFileInfo{}}, + {Op: loginp.OpCreate, NewPath: "/path/to/other/file", Info: testFileInfo{}}, }, expectedEvents: []harvesterEvent{ harvesterStart("path::/path/to/file"), @@ -181,7 +179,7 @@ func TestProspectorNewAndUpdatedFiles(t *testing.T) { }, "one updated file": { events: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpWrite, NewPath: "/path/to/file", Info: testFileInfo{}}, + {Op: loginp.OpWrite, NewPath: "/path/to/file", Info: testFileInfo{}}, }, expectedEvents: []harvesterEvent{ harvesterStart("path::/path/to/file"), @@ -190,8 +188,8 @@ func TestProspectorNewAndUpdatedFiles(t *testing.T) { }, "one updated then truncated file": { events: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpWrite, NewPath: "/path/to/file", Info: testFileInfo{}}, - loginp.FSEvent{Op: loginp.OpTruncate, NewPath: "/path/to/file", Info: testFileInfo{}}, + {Op: loginp.OpWrite, NewPath: "/path/to/file", Info: testFileInfo{}}, + {Op: loginp.OpTruncate, NewPath: "/path/to/file", Info: testFileInfo{}}, }, expectedEvents: []harvesterEvent{ harvesterStart("path::/path/to/file"), @@ -201,12 +199,12 @@ func TestProspectorNewAndUpdatedFiles(t *testing.T) { }, "old files with ignore older configured": { events: []loginp.FSEvent{ - loginp.FSEvent{ + { Op: loginp.OpCreate, NewPath: "/path/to/file", Info: testFileInfo{"/path/to/file", 5, minuteAgo, nil}, }, - loginp.FSEvent{ + { Op: loginp.OpWrite, NewPath: "/path/to/other/file", Info: testFileInfo{"/path/to/other/file", 5, minuteAgo, nil}, @@ -219,12 +217,12 @@ func TestProspectorNewAndUpdatedFiles(t *testing.T) { }, "newer files with ignore older": { events: []loginp.FSEvent{ - loginp.FSEvent{ + { Op: loginp.OpCreate, NewPath: "/path/to/file", Info: testFileInfo{"/path/to/file", 5, minuteAgo, nil}, }, - loginp.FSEvent{ + { Op: loginp.OpWrite, NewPath: "/path/to/other/file", Info: testFileInfo{"/path/to/other/file", 5, minuteAgo, nil}, @@ -265,13 +263,13 @@ func TestProspectorDeletedFile(t *testing.T) { }{ "one deleted file without clean removed": { events: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpDelete, OldPath: "/path/to/file", Info: testFileInfo{}}, + {Op: loginp.OpDelete, OldPath: "/path/to/file", Info: testFileInfo{}}, }, cleanRemoved: false, }, "one deleted file with clean removed": { events: []loginp.FSEvent{ - loginp.FSEvent{Op: loginp.OpDelete, OldPath: "/path/to/file", Info: testFileInfo{}}, + {Op: loginp.OpDelete, OldPath: "/path/to/file", Info: testFileInfo{}}, }, cleanRemoved: true, }, @@ -299,7 +297,6 @@ func TestProspectorDeletedFile(t *testing.T) { assert.False(t, has) } else { assert.True(t, has) - } }) } @@ -314,7 +311,7 @@ func TestProspectorRenamedFile(t *testing.T) { }{ "one renamed file without rename tracker": { events: []loginp.FSEvent{ - loginp.FSEvent{ + { Op: loginp.OpRename, OldPath: "/old/path/to/file", NewPath: "/new/path/to/file", @@ -329,7 +326,7 @@ func TestProspectorRenamedFile(t *testing.T) { }, "one renamed file with rename tracker": { events: []loginp.FSEvent{ - loginp.FSEvent{ + { Op: loginp.OpRename, OldPath: "/old/path/to/file", NewPath: "/new/path/to/file", @@ -343,7 +340,7 @@ func TestProspectorRenamedFile(t *testing.T) { }, "one renamed file with rename tracker with close renamed": { events: []loginp.FSEvent{ - loginp.FSEvent{ + { Op: loginp.OpRename, OldPath: "/old/path/to/file", NewPath: "/new/path/to/file", @@ -384,7 +381,6 @@ func TestProspectorRenamedFile(t *testing.T) { } assert.Equal(t, test.expectedEvents, hg.events) - }) } } @@ -509,7 +505,6 @@ func (u *mockUnpackValue) UnpackCursorMeta(to interface{}) error { type mockProspectorCleaner struct { available map[string]loginp.Value cleanedKeys []string - newEntries map[string]fileMeta updatedKeys map[string]string } diff --git a/filebeat/input/input.go b/filebeat/input/input.go index 7870d5979dff..48bff03d6bec 100644 --- a/filebeat/input/input.go +++ b/filebeat/input/input.go @@ -29,9 +29,7 @@ import ( "github.com/elastic/beats/v7/libbeat/monitoring" ) -var ( - inputList = monitoring.NewUniqueList() -) +var inputList = monitoring.NewUniqueList() func init() { monitoring.NewFunc(monitoring.GetNamespace("state").GetRegistry(), "input", inputList.Report, monitoring.Report) diff --git a/filebeat/input/journald/config.go b/filebeat/input/journald/config.go index e2ea723e51ac..8e634d6939a6 100644 --- a/filebeat/input/journald/config.go +++ b/filebeat/input/journald/config.go @@ -33,11 +33,9 @@ import ( "github.com/elastic/beats/v7/libbeat/reader/parser" ) -var ( - // includeMatchesWarnOnce allow for a config deprecation warning to be - // logged only once if an old config format is detected. - includeMatchesWarnOnce sync.Once -) +// includeMatchesWarnOnce allow for a config deprecation warning to be +// logged only once if an old config format is detected. +var includeMatchesWarnOnce sync.Once // Config stores the options of a journald input. type config struct { diff --git a/filebeat/input/journald/environment_test.go b/filebeat/input/journald/environment_test.go index 5c05759b2c2f..11a482554039 100644 --- a/filebeat/input/journald/environment_test.go +++ b/filebeat/input/journald/environment_test.go @@ -123,7 +123,7 @@ func (e *inputTestingEnvironment) abspath(filename string) string { func (e *inputTestingEnvironment) mustWriteFile(filename string, lines []byte) { e.t.Helper() path := e.abspath(filename) - if err := os.WriteFile(path, lines, 0644); err != nil { + if err := os.WriteFile(path, lines, 0o644); err != nil { e.t.Fatalf("failed to write file '%s': %+v", path, err) } } @@ -246,7 +246,6 @@ func (pc *mockPipelineConnector) ConnectWith(config beat.ClientConfig) (beat.Cli pc.clients = append(pc.clients, c) return c, nil - } func (pc *mockPipelineConnector) cancelAllClients() { @@ -275,7 +274,6 @@ func newMockACKHandler(starter context.Context, blocking bool, config beat.Clien } return acker.Combine(blockingACKer(starter), config.ACKHandler) - } func blockingACKer(starter context.Context) beat.ACKer { diff --git a/filebeat/input/journald/input_filtering_test.go b/filebeat/input/journald/input_filtering_test.go index f1be6c8b37e2..3018133ab76b 100644 --- a/filebeat/input/journald/input_filtering_test.go +++ b/filebeat/input/journald/input_filtering_test.go @@ -164,7 +164,7 @@ func TestInputIncludeMatches(t *testing.T) { "and condition": { includeMatches: map[string]interface{}{ "and": []map[string]interface{}{ - map[string]interface{}{ + { "match": []string{ "syslog.facility=3", "message=6th line", @@ -179,7 +179,7 @@ func TestInputIncludeMatches(t *testing.T) { "or condition": { includeMatches: map[string]interface{}{ "or": []map[string]interface{}{ - map[string]interface{}{ + { "match": []string{ "message=5th line", "message=6th line", diff --git a/filebeat/input/journald/input_test.go b/filebeat/input/journald/input_test.go index 55d2e0112f96..f6578ccf01b7 100644 --- a/filebeat/input/journald/input_test.go +++ b/filebeat/input/journald/input_test.go @@ -31,7 +31,7 @@ import ( func TestInputFieldsTranslation(t *testing.T) { // A few random keys to verify - var keysToCheck = map[string]string{ + keysToCheck := map[string]string{ "systemd.user_unit": "log-service.service", "process.pid": "2084785", "systemd.transport": "stdout", diff --git a/filebeat/input/journald/pkg/journalfield/matcher.go b/filebeat/input/journald/pkg/journalfield/matcher.go index 49d4e98fe1a7..b15f35bf7b6c 100644 --- a/filebeat/input/journald/pkg/journalfield/matcher.go +++ b/filebeat/input/journald/pkg/journalfield/matcher.go @@ -165,22 +165,22 @@ func ApplyUnitMatchers(j journal, units []string) error { matchers := [][]Matcher{ // match for the messages of the service - []Matcher{ + { systemdUnit, }, // match for the coredumps of the service - []Matcher{ + { coreDumpMsgID, journaldUID, coredumpUnit, }, // match for messages about the service with PID value of 1 - []Matcher{ + { journaldPID, journaldUnit, }, // match for messages about the service from authorized daemons - []Matcher{ + { journaldUID, journaldObjectUnit, }, @@ -200,7 +200,6 @@ func ApplyUnitMatchers(j journal, units []string) error { } return nil - } // ApplyTransportMatcher adds matchers for the configured transports. @@ -221,7 +220,6 @@ func ApplyTransportMatcher(j journal, transports []string) error { return fmt.Errorf("error while adding %+v transport to matchers: %+v", transports, err) } return nil - } // ApplySyslogIdentifierMatcher adds syslog identifier filtering to the journal reader. diff --git a/filebeat/input/journald/pkg/journalread/mode.go b/filebeat/input/journald/pkg/journalread/mode.go index 3eff2d93c5d9..36132ffe11d6 100644 --- a/filebeat/input/journald/pkg/journalread/mode.go +++ b/filebeat/input/journald/pkg/journalread/mode.go @@ -17,10 +17,7 @@ package journalread -import ( - "errors" - "fmt" -) +import "fmt" // SeekMode is used by (*Reader).Seek to decide where to advance the read pointer to. type SeekMode uint @@ -42,8 +39,6 @@ var seekModes = map[string]SeekMode{ "cursor": SeekCursor, } -var errInvalidSeekFallback = errors.New("invalid setting for cursor_seek_fallback") - // Unpack validates and unpack "seek" config options. It returns an error if // the string is no valid seek mode. func (m *SeekMode) Unpack(value string) error { diff --git a/filebeat/input/journald/pkg/journalread/reader.go b/filebeat/input/journald/pkg/journalread/reader.go index ab359f141f4f..cb462c416fbf 100644 --- a/filebeat/input/journald/pkg/journalread/reader.go +++ b/filebeat/input/journald/pkg/journalread/reader.go @@ -50,11 +50,9 @@ type canceler interface { type journal interface { Close() error - Next() (uint64, error) Wait(time.Duration) int GetEntry() (*sdjournal.JournalEntry, error) - SeekHead() error SeekTail() error SeekCursor(string) error diff --git a/filebeat/input/kafka/config.go b/filebeat/input/kafka/config.go index 338182e460a7..2b81e2ee764c 100644 --- a/filebeat/input/kafka/config.go +++ b/filebeat/input/kafka/config.go @@ -166,8 +166,7 @@ func newSaramaConfig(config kafkaInputConfig) (*sarama.Config, error) { k.Consumer.Fetch.Default = config.Fetch.Default k.Consumer.Fetch.Max = config.Fetch.Max - k.Consumer.Group.Rebalance.Strategy = - config.Rebalance.Strategy.asSaramaStrategy() + k.Consumer.Group.Rebalance.Strategy = config.Rebalance.Strategy.asSaramaStrategy() k.Consumer.Group.Rebalance.Timeout = config.Rebalance.Timeout k.Consumer.Group.Rebalance.Retry.Backoff = config.Rebalance.RetryBackoff k.Consumer.Group.Rebalance.Retry.Max = config.Rebalance.MaxRetries diff --git a/filebeat/input/kafka/input.go b/filebeat/input/kafka/input.go index 6440dcf9d2a2..058d261c8557 100644 --- a/filebeat/input/kafka/input.go +++ b/filebeat/input/kafka/input.go @@ -251,12 +251,15 @@ type channelCtx struct { func doneChannelContext(ctx input.Context) context.Context { return channelCtx{ctx} } + func (c channelCtx) Deadline() (deadline time.Time, ok bool) { return } + func (c channelCtx) Done() <-chan struct{} { return c.ctx.Cancelation.Done() } + func (c channelCtx) Err() error { return c.ctx.Cancelation.Err() } @@ -276,7 +279,6 @@ type groupHandler struct { // ex. in this case are the azure fielsets where the events are found under the json object "records" expandEventListFromField string // TODO log *logp.Logger - reader reader.Reader } func (h *groupHandler) Setup(session sarama.ConsumerGroupSession) error { diff --git a/filebeat/input/kafka/kafka_integration_test.go b/filebeat/input/kafka/kafka_integration_test.go index b166f684259e..ae48223bb39a 100644 --- a/filebeat/input/kafka/kafka_integration_test.go +++ b/filebeat/input/kafka/kafka_integration_test.go @@ -66,14 +66,14 @@ func TestInput(t *testing.T) { // Send test messages to the topic for the input to read. messages := []testMessage{ - testMessage{message: "testing"}, - testMessage{ + {message: "testing"}, + { message: "stuff", headers: []sarama.RecordHeader{ recordHeader("X-Test-Header", "test header value"), }, }, - testMessage{ + { message: "things", headers: []sarama.RecordHeader{ recordHeader("keys and things", "3^3 = 27"), diff --git a/filebeat/input/log/harvester.go b/filebeat/input/log/harvester.go index 34bf1e221d6a..b835129bd255 100644 --- a/filebeat/input/log/harvester.go +++ b/filebeat/input/log/harvester.go @@ -129,7 +129,6 @@ func NewHarvester( publishState func(file.State) bool, outletFactory OutletFactory, ) (*Harvester, error) { - id, err := uuid.NewV4() if err != nil { return nil, err diff --git a/filebeat/input/log/input_test.go b/filebeat/input/log/input_test.go index 4741d7047d33..600ed3c420fa 100644 --- a/filebeat/input/log/input_test.go +++ b/filebeat/input/log/input_test.go @@ -140,7 +140,7 @@ func testInputLifecycle(t *testing.T, context input.Context, closer func(input.C } defer os.RemoveAll(tmpdir) logs := []byte("some log line\nother log line\n") - err = ioutil.WriteFile(path.Join(tmpdir, "some.log"), logs, 0644) + err = ioutil.WriteFile(path.Join(tmpdir, "some.log"), logs, 0o644) assert.NoError(t, err) // Setup the input diff --git a/filebeat/input/mqtt/client_mocked.go b/filebeat/input/mqtt/client_mocked.go index 20de98256654..ac1c2d79455c 100644 --- a/filebeat/input/mqtt/client_mocked.go +++ b/filebeat/input/mqtt/client_mocked.go @@ -35,7 +35,6 @@ type mockedMessage struct { retained bool topic string payload []byte - ack func() } var _ libmqtt.Message = new(mockedMessage) @@ -166,7 +165,7 @@ func (m *mockedClient) SubscribeMultiple(filters map[string]byte, callback libmq m.onMessageHandler = callback for _, msg := range m.messages { - var thatMsg = msg + thatMsg := msg go func() { m.onMessageHandler(m, &thatMsg) }() diff --git a/filebeat/input/syslog/config.go b/filebeat/input/syslog/config.go index b50db762d72e..a68b93f92c45 100644 --- a/filebeat/input/syslog/config.go +++ b/filebeat/input/syslog/config.go @@ -49,13 +49,11 @@ const ( syslogFormatAuto ) -var ( - syslogFormats = map[string]syslogFormat{ - "rfc3164": syslogFormatRFC3164, - "rfc5424": syslogFormatRFC5424, - "auto": syslogFormatAuto, - } -) +var syslogFormats = map[string]syslogFormat{ + "rfc3164": syslogFormatRFC3164, + "rfc5424": syslogFormatRFC5424, + "auto": syslogFormatAuto, +} var defaultConfig = config{ ForwarderConfig: harvester.ForwarderConfig{ diff --git a/filebeat/input/syslog/event.go b/filebeat/input/syslog/event.go index ef5008d850b9..89598a1ca852 100644 --- a/filebeat/input/syslog/event.go +++ b/filebeat/input/syslog/event.go @@ -23,8 +23,10 @@ import ( "time" ) -const severityMask = 7 -const facilityShift = 3 +const ( + severityMask = 7 + facilityShift = 3 +) var month = map[string]time.Month{ "Jan": time.January, @@ -60,9 +62,9 @@ var monthIndexed = []time.Month{ // event is a parsed syslog event, validation of the format is done at the parser level. type event struct { message string - hostname string //x + hostname string // x priority int - program string //x + program string // x pid int month time.Month day int diff --git a/filebeat/input/syslog/event_test.go b/filebeat/input/syslog/event_test.go index 137538939f38..01196db1fdd1 100644 --- a/filebeat/input/syslog/event_test.go +++ b/filebeat/input/syslog/event_test.go @@ -70,7 +70,7 @@ func TestDateParsing(t *testing.T) { e.SetMonth([]byte("Sept")) e.SetHour(itb(18)) e.SetMinute(itb(14)) - e.SetSecond(itb(04)) + e.SetSecond(itb(0o4)) e.SetNanosecond(itb(5555)) // Use google parser to compare. @@ -78,7 +78,7 @@ func TestDateParsing(t *testing.T) { t1 = t1.UTC() t2, _ := time.Parse(time.RFC3339, "2018-09-12T18:14:04.5555+07:00") t2 = t2.UTC() - alreadyutc := time.Date(2018, 9, 12, 18, 14, 04, 555500000, time.UTC) + alreadyutc := time.Date(2018, 9, 12, 18, 14, 0o4, 555500000, time.UTC) tests := []struct { name string @@ -115,7 +115,7 @@ func TestNanosecondParsing(t *testing.T) { e.SetMonth([]byte("Sept")) e.SetHour(itb(18)) e.SetMinute(itb(14)) - e.SetSecond(itb(04)) + e.SetSecond(itb(0o4)) // Use google parser to compare. dt := func(s string) int { diff --git a/filebeat/input/syslog/rfc5424_test.go b/filebeat/input/syslog/rfc5424_test.go index 17a0cee4d050..9a48826c45c6 100644 --- a/filebeat/input/syslog/rfc5424_test.go +++ b/filebeat/input/syslog/rfc5424_test.go @@ -27,16 +27,21 @@ import ( const BOM = "\xEF\xBB\xBF" -const VersionTestTemplate = `<34>%d 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - ` + BOM + `'su root' failed for lonvick on /dev/pts/8` -const PriorityTestTemplate = `<%d>1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - ` + BOM + `'su root' failed for lonvick on /dev/pts/8` +const ( + VersionTestTemplate = `<34>%d 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - ` + BOM + `'su root' failed for lonvick on /dev/pts/8` + PriorityTestTemplate = `<%d>1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - ` + BOM + `'su root' failed for lonvick on /dev/pts/8` +) // https://tools.ietf.org/html/rfc5424#section-6.5 const RfcDoc65Example1 = `<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - ` + BOM + `'su root' failed for lonvick on /dev/pts/8` -const RfcDoc65Example2 = `<165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc 8710 - - %% It's time to make the do-nuts.` -const RfcDoc65Example3 = `<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"] ` + BOM + `An application event log entry...` -const RfcDoc65Example4 = `<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"][examplePriority@32473 class="high"]` -const RfcDoc65Example4WithoutSD = `<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 ` -const MESSAGE = `An application event log entry...` + +const ( + RfcDoc65Example2 = `<165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc 8710 - - %% It's time to make the do-nuts.` + RfcDoc65Example3 = `<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"] ` + BOM + `An application event log entry...` + RfcDoc65Example4 = `<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"][examplePriority@32473 class="high"]` + RfcDoc65Example4WithoutSD = `<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 ` + MESSAGE = `An application event log entry...` +) func getTestEvent() event { return event{ @@ -79,8 +84,9 @@ func runTests(rules []testRule, t *testing.T) { }) } } + func TestRfc5424ParseHeader(t *testing.T) { - var tests = []testRule{{ + tests := []testRule{{ title: "RfcDoc 6.5 Example1", log: []byte(RfcDoc65Example1), syslog: getTestEvent(), @@ -127,6 +133,7 @@ func CreateStructuredDataWithMsg(msg string, data EventData) event { data: data, } } + func CreateStructuredData(data EventData) event { return CreateStructuredDataWithMsg(MESSAGE, data) } @@ -150,7 +157,7 @@ func CreateParseFailTest(title string, log string, syslog event) testRule { } func TestRfc5424ParseStructuredData(t *testing.T) { - var tests = []testRule{ + tests := []testRule{ CreateTest("RfcDoc65Example3", RfcDoc65Example3, CreateStructuredData(EventData{ @@ -233,7 +240,7 @@ func TestRfc5424ParseStructuredData(t *testing.T) { } func createVersionTestRule(v int, success bool) testRule { - var rule = testRule{ + rule := testRule{ title: fmt.Sprintf("versionTest v:%d", v), log: []byte(fmt.Sprintf(VersionTestTemplate, v)), syslog: event{ @@ -251,7 +258,8 @@ func createVersionTestRule(v int, success bool) testRule { second: 15, nanosecond: 3000000, message: "'su root' failed for lonvick on /dev/pts/8", - }} + }, + } if !success { rule.isFailed = true @@ -262,7 +270,7 @@ func createVersionTestRule(v int, success bool) testRule { } func createPriorityTestRule(v int, success bool) testRule { - var rule = testRule{ + rule := testRule{ title: fmt.Sprintf("priorityTest v:%d", v), log: []byte(fmt.Sprintf(PriorityTestTemplate, v)), syslog: event{ diff --git a/filebeat/input/tcp/input.go b/filebeat/input/tcp/input.go index 865eff3d0f81..fbf3f286ca60 100644 --- a/filebeat/input/tcp/input.go +++ b/filebeat/input/tcp/input.go @@ -55,7 +55,6 @@ func NewInput( connector channel.Connector, context input.Context, ) (input.Input, error) { - out, err := connector.Connect(cfg) if err != nil { return nil, err diff --git a/filebeat/input/udp/input.go b/filebeat/input/udp/input.go index fe211537b0b4..56941a501a60 100644 --- a/filebeat/input/udp/input.go +++ b/filebeat/input/udp/input.go @@ -52,7 +52,6 @@ func NewInput( outlet channel.Connector, context input.Context, ) (input.Input, error) { - out, err := outlet.Connect(cfg) if err != nil { return nil, err diff --git a/filebeat/input/v2/compat/composed_test.go b/filebeat/input/v2/compat/composed_test.go index b2ae6c3cb46c..51c4bba63dde 100644 --- a/filebeat/input/v2/compat/composed_test.go +++ b/filebeat/input/v2/compat/composed_test.go @@ -78,7 +78,6 @@ func TestCombine_CheckConfig(t *testing.T) { } }) } - } func TestCombine_Create(t *testing.T) { diff --git a/filebeat/input/v2/error.go b/filebeat/input/v2/error.go index 4fe7a6ffa49f..eeab5a2a115a 100644 --- a/filebeat/input/v2/error.go +++ b/filebeat/input/v2/error.go @@ -58,15 +58,6 @@ var ErrPluginWithoutName = errors.New("the plugin has no name") // error because there is no existing plugin that can create the input. func IsUnknownInputError(err error) bool { return errors.Is(err, ErrUnknownInput) } -func failedInputName(err error) string { - switch e := err.(type) { - case *LoadError: - return e.Name - default: - return "" - } -} - // Unwrap returns the reason if present func (e *LoadError) Unwrap() error { return e.Reason } diff --git a/filebeat/input/v2/input-cursor/manager.go b/filebeat/input/v2/input-cursor/manager.go index 8f70e17c2b23..b52d12f0e873 100644 --- a/filebeat/input/v2/input-cursor/manager.go +++ b/filebeat/input/v2/input-cursor/manager.go @@ -76,8 +76,10 @@ type Source interface { Name() string } -var errNoSourceConfigured = errors.New("no source has been configured") -var errNoInputRunner = errors.New("no input runner available") +var ( + errNoSourceConfigured = errors.New("no source has been configured") + errNoInputRunner = errors.New("no input runner available") +) // StateStore interface and configurations used to give the Manager access to the persistent store. type StateStore interface { diff --git a/filebeat/input/v2/input-cursor/publish.go b/filebeat/input/v2/input-cursor/publish.go index 64096951132a..923c2124a616 100644 --- a/filebeat/input/v2/input-cursor/publish.go +++ b/filebeat/input/v2/input-cursor/publish.go @@ -55,7 +55,6 @@ type updateOp struct { // state updates to persist timestamp time.Time - ttl time.Duration delta interface{} } diff --git a/filebeat/input/v2/input-cursor/store.go b/filebeat/input/v2/input-cursor/store.go index 66d5b4509363..1417c658d383 100644 --- a/filebeat/input/v2/input-cursor/store.go +++ b/filebeat/input/v2/input-cursor/store.go @@ -316,7 +316,6 @@ func readStates(log *logp.Logger, store *statestore.Store, prefix string) (*stat return true, nil }) - if err != nil { return nil, err } diff --git a/filebeat/input/v2/input-cursor/store_test.go b/filebeat/input/v2/input-cursor/store_test.go index 2fa3f6eaa3e8..6c75b9917e6c 100644 --- a/filebeat/input/v2/input-cursor/store_test.go +++ b/filebeat/input/v2/input-cursor/store_test.go @@ -285,7 +285,6 @@ func (ts testStateStore) snapshot() map[string]state { states[key] = st return true, nil }) - if err != nil { panic("unexpected decode error from persistent test store") } @@ -337,15 +336,3 @@ func checkEqualStoreState(t *testing.T, want, got map[string]state) bool { } return true } - -// requireEqualStoreState compares 2 store snapshot tables for equality. The test -// fails with Fatalf if the state differ. -// -// Note: testify is too strict when comparing timestamp, better use checkEqualStoreState. -func requireEqualStoreState(t *testing.T, want, got map[string]state) bool { - if d := cmp.Diff(want, got); d != "" { - t.Fatalf("store state mismatch (-want +got):\n%s", d) - return false - } - return true -} diff --git a/filebeat/input/v2/internal/inputest/inputest.go b/filebeat/input/v2/internal/inputest/inputest.go index 1fe3ac4ef498..a03ab01b0e10 100644 --- a/filebeat/input/v2/internal/inputest/inputest.go +++ b/filebeat/input/v2/internal/inputest/inputest.go @@ -19,7 +19,6 @@ package inputest import ( "errors" - "testing" v2 "github.com/elastic/beats/v7/filebeat/input/v2" "github.com/elastic/beats/v7/libbeat/beat" @@ -47,13 +46,6 @@ type MockInput struct { OnRun func(v2.Context, beat.PipelineConnector) error } -func makeConfigFakeInput(prototype MockInput) func(*common.Config) (v2.Input, error) { - return func(cfg *common.Config) (v2.Input, error) { - tmp := prototype - return &tmp, nil - } -} - // Init returns nil if OnInit is not set. Otherwise the return value of OnInit is returned. func (m *MockInputManager) Init(_ unison.Group, mode v2.Mode) error { if m.OnInit != nil { @@ -112,15 +104,3 @@ func SinglePlugin(name string, manager v2.InputManager) []v2.Plugin { Manager: manager, }} } - -func expectError(t *testing.T, err error) { - if err == nil { - t.Errorf("expected error") - } -} - -func expectNoError(t *testing.T, err error) { - if err != nil { - t.Errorf("unexpected error: %v", err) - } -} diff --git a/filebeat/input/v2/loader_test.go b/filebeat/input/v2/loader_test.go index 72f8013c4dbc..0ac2e789f7f8 100644 --- a/filebeat/input/v2/loader_test.go +++ b/filebeat/input/v2/loader_test.go @@ -187,6 +187,7 @@ func (b loaderConfig) MustNewLoader() *Loader { } return l } + func (b loaderConfig) NewLoader() (*Loader, error) { return NewLoader(logp.NewLogger("test"), b.Plugins, b.TypeField, b.DefaultType) } diff --git a/filebeat/input/v2/util_test.go b/filebeat/input/v2/util_test.go index 6fbe55b99d18..8aea84920683 100644 --- a/filebeat/input/v2/util_test.go +++ b/filebeat/input/v2/util_test.go @@ -65,6 +65,7 @@ func (f *fakeInput) Test(ctx TestContext) error { } return nil } + func (f *fakeInput) Run(ctx Context, pipeline beat.PipelineConnector) error { if f.OnRun != nil { return f.OnRun(ctx, pipeline) diff --git a/filebeat/inputsource/common/dgram/handler.go b/filebeat/inputsource/common/dgram/handler.go index a9fa50d8f194..0faeafef6ab7 100644 --- a/filebeat/inputsource/common/dgram/handler.go +++ b/filebeat/inputsource/common/dgram/handler.go @@ -48,7 +48,7 @@ func DatagramReaderFactory( for ctx.Err() == nil { buffer := make([]byte, config.MaxMessageSize) - //conn.SetDeadline(time.Now().Add(config.Timeout)) + // conn.SetDeadline(time.Now().Add(config.Timeout)) // If you are using Windows and you are using a fixed buffer and you get a datagram which // is bigger than the specified size of the buffer, it will return an `err` and the buffer will diff --git a/filebeat/inputsource/common/streaming/handler.go b/filebeat/inputsource/common/streaming/handler.go index 69ae5aedc9c5..d9a05592be2d 100644 --- a/filebeat/inputsource/common/streaming/handler.go +++ b/filebeat/inputsource/common/streaming/handler.go @@ -56,7 +56,7 @@ func SplitHandlerFactory(family inputsource.Family, logger *logp.Logger, metadat buf := bufio.NewReader(r) scanner := bufio.NewScanner(buf) scanner.Split(splitFunc) - //16 is ratio of MaxScanTokenSize/startBufSize + // 16 is ratio of MaxScanTokenSize/startBufSize buffer := make([]byte, maxMessageSize/16) scanner.Buffer(buffer, int(maxMessageSize)) for { diff --git a/filebeat/inputsource/common/streaming/scan.go b/filebeat/inputsource/common/streaming/scan.go index 5b826e735928..5931b4e0af64 100644 --- a/filebeat/inputsource/common/streaming/scan.go +++ b/filebeat/inputsource/common/streaming/scan.go @@ -42,7 +42,7 @@ func FactoryDelimiter(delimiter []byte) bufio.SplitFunc { func dropDelimiter(data []byte, delimiter []byte) []byte { if len(data) > len(delimiter) && - bytes.Equal(data[len(data)-len(delimiter):len(data)], delimiter) { + bytes.Equal(data[len(data)-len(delimiter):], delimiter) { return data[0 : len(data)-len(delimiter)] } return data @@ -74,7 +74,7 @@ func FactoryRFC6587Framing(delimiter []byte) bufio.SplitFunc { return end, data[i+1 : end], nil } } - //request more data + // request more data return 0, nil, nil } if i := bytes.Index(data, delimiter); i >= 0 { diff --git a/filebeat/inputsource/tcp/handler.go b/filebeat/inputsource/tcp/handler.go index 838fe476a81d..f783e1cec2aa 100644 --- a/filebeat/inputsource/tcp/handler.go +++ b/filebeat/inputsource/tcp/handler.go @@ -51,7 +51,7 @@ func extractCertificate(certificates []*x509.Certificate) []string { strCertificate := make([]string, len(certificates)) for idx, c := range certificates { // Ignore errors here, problematics cert have failed - //the handshake at this point. + // the handshake at this point. b, _ := x509.MarshalPKIXPublicKey(c.PublicKey) strCertificate[idx] = string(b) } diff --git a/filebeat/inputsource/udp/server_test.go b/filebeat/inputsource/udp/server_test.go index 0434c836ae64..efad27ea0b5a 100644 --- a/filebeat/inputsource/udp/server_test.go +++ b/filebeat/inputsource/udp/server_test.go @@ -28,9 +28,11 @@ import ( "github.com/elastic/beats/v7/filebeat/inputsource" ) -const maxMessageSize = 20 -const maxSocketSize = 0 -const timeout = time.Second * 15 +const ( + maxMessageSize = 20 + maxSocketSize = 0 + timeout = time.Second * 15 +) type info struct { message []byte diff --git a/filebeat/inputsource/unix/config.go b/filebeat/inputsource/unix/config.go index 7b4dfa746128..5d227284e21a 100644 --- a/filebeat/inputsource/unix/config.go +++ b/filebeat/inputsource/unix/config.go @@ -67,7 +67,6 @@ func (c *Config) Validate() error { return fmt.Errorf("line_delimiter cannot be empty when using stream socket") } return nil - } func (s *SocketType) Unpack(value string) error { diff --git a/filebeat/inputsource/unix/server_test.go b/filebeat/inputsource/unix/server_test.go index 460b85b8b1ea..d7b3a61f4df8 100644 --- a/filebeat/inputsource/unix/server_test.go +++ b/filebeat/inputsource/unix/server_test.go @@ -251,7 +251,7 @@ func TestSocketOwnershipAndMode(t *testing.T) { info, err := file.Lstat(path) require.NoError(t, err) require.NotEqual(t, 0, info.Mode()&os.ModeSocket) - require.Equal(t, os.FileMode(0740), info.Mode().Perm()) + require.Equal(t, os.FileMode(0o740), info.Mode().Perm()) gid, err := info.GID() require.NoError(t, err) require.Equal(t, group.Gid, strconv.Itoa(gid)) @@ -310,7 +310,7 @@ func TestReceiveNewEventsConcurrently(t *testing.T) { return } - for socketType, _ := range socketTypes { + for socketType := range socketTypes { if runtime.GOOS == "darwin" && socketType == "datagram" { t.Skip("test is only supported on linux. See https://github.com/elastic/beats/issues/22775") return diff --git a/filebeat/inputsource/unix/socket.go b/filebeat/inputsource/unix/socket.go index 576dedad5645..a09129eb4172 100644 --- a/filebeat/inputsource/unix/socket.go +++ b/filebeat/inputsource/unix/socket.go @@ -88,7 +88,7 @@ func parseFileMode(mode string) (os.FileMode, error) { if err != nil { return 0, err } - if parsed > 0777 { + if parsed > 0o777 { return 0, errors.New("invalid file mode") } return os.FileMode(parsed), nil diff --git a/filebeat/main_test.go b/filebeat/main_test.go index d55a1cc9a7f8..2b4f0b39e710 100644 --- a/filebeat/main_test.go +++ b/filebeat/main_test.go @@ -30,8 +30,10 @@ import ( "github.com/elastic/beats/v7/libbeat/tests/system/template" ) -var systemTest *bool -var fbCommand *cmd.BeatsRootCmd +var ( + systemTest *bool + fbCommand *cmd.BeatsRootCmd +) func init() { testing.Init() diff --git a/filebeat/processor/add_kubernetes_metadata/matchers.go b/filebeat/processor/add_kubernetes_metadata/matchers.go index 7e7996fede72..72ffd15ba7dd 100644 --- a/filebeat/processor/add_kubernetes_metadata/matchers.go +++ b/filebeat/processor/add_kubernetes_metadata/matchers.go @@ -32,15 +32,17 @@ func init() { add_kubernetes_metadata.Indexing.AddMatcher(LogPathMatcherName, newLogsPathMatcher) cfg := common.NewConfig() - //Add a container indexer config by default. + // Add a container indexer config by default. add_kubernetes_metadata.Indexing.AddDefaultIndexerConfig(add_kubernetes_metadata.ContainerIndexerName, *cfg) - //Add a log path matcher which can extract container ID from the "source" field. + // Add a log path matcher which can extract container ID from the "source" field. add_kubernetes_metadata.Indexing.AddDefaultMatcherConfig(LogPathMatcherName, *cfg) } -const LogPathMatcherName = "logs_path" -const pathSeparator = string(os.PathSeparator) +const ( + LogPathMatcherName = "logs_path" + pathSeparator = string(os.PathSeparator) +) type LogPathMatcher struct { LogsPath string diff --git a/filebeat/processor/add_kubernetes_metadata/matchers_test.go b/filebeat/processor/add_kubernetes_metadata/matchers_test.go index 27e376c88161..24a5259f4f5c 100644 --- a/filebeat/processor/add_kubernetes_metadata/matchers_test.go +++ b/filebeat/processor/add_kubernetes_metadata/matchers_test.go @@ -152,7 +152,7 @@ func executeTest(t *testing.T, cfgLogsPath string, source string, expectedResult } func executeTestWithResourceType(t *testing.T, cfgLogsPath string, cfgResourceType string, source string, expectedResult string) { - var testConfig = common.NewConfig() + testConfig := common.NewConfig() if cfgLogsPath != "" { testConfig.SetString("logs_path", -1, cfgLogsPath) } diff --git a/filebeat/registrar/migrate.go b/filebeat/registrar/migrate.go index 39b63636e3bd..9cfeba1aab92 100644 --- a/filebeat/registrar/migrate.go +++ b/filebeat/registrar/migrate.go @@ -161,7 +161,7 @@ func (m *Migrator) updateToVersion0(regHome, migrateFile string) error { func initVersion0Registry(regHome string, perm os.FileMode) error { if !isDir(regHome) { logp.Info("No registry home found. Create: %v", regHome) - if err := os.MkdirAll(regHome, 0750); err != nil { + if err := os.MkdirAll(regHome, 0o750); err != nil { return errors.Wrapf(err, "failed to create registry dir '%v'", regHome) } } @@ -249,21 +249,6 @@ func (m *Migrator) updateToVersion1(regHome string) error { return nil } -func writeMeta(path string, version string, perm os.FileMode) error { - logp.Info("Write registry meta file with version: %v", version) - doc := struct{ Version string }{version} - body, err := json.Marshal(doc) - if err != nil { - panic(err) // must not fail - } - - if err = safeWriteFile(path+".tmp", body, perm); err != nil { - return errors.Wrap(err, "failed writing registry meta.json") - } - - return helper.SafeFileRotate(path, path+".tmp") -} - func readVersion(regHome, migrateFile string) (registryVersion, error) { if isFile(migrateFile) { return legacyVersion, nil diff --git a/filebeat/registrar/migrate_bench_test.go b/filebeat/registrar/migrate_bench_test.go index b5edd8122bd1..da26890e8961 100644 --- a/filebeat/registrar/migrate_bench_test.go +++ b/filebeat/registrar/migrate_bench_test.go @@ -84,7 +84,7 @@ func BenchmarkMigration0To1(b *testing.B) { migrator := &Migrator{ dataPath: dataHome, - permissions: 0600, + permissions: 0o600, } b.StartTimer() @@ -116,7 +116,7 @@ func tempDir(t testing.TB) string { } func mkDir(t testing.TB, path string) { - if err := os.MkdirAll(path, 0700); err != nil { + if err := os.MkdirAll(path, 0o700); err != nil { t.Fatal(err) } } @@ -135,7 +135,7 @@ func clearDir(t testing.TB, path string) { func writeFile(t testing.TB, path string, contents []byte) { t.Helper() - err := ioutil.WriteFile(path, contents, 0600) + err := ioutil.WriteFile(path, contents, 0o600) if err != nil { t.Fatal(err) } diff --git a/filebeat/registrar/registrar.go b/filebeat/registrar/registrar.go index 27c292886cad..9a6cccabaa4c 100644 --- a/filebeat/registrar/registrar.go +++ b/filebeat/registrar/registrar.go @@ -209,7 +209,6 @@ func (r *Registrar) commitStateUpdates() { r.out.Published(r.bufferedStateUpdates) } r.bufferedStateUpdates = 0 - } // onEvents processes events received from the publisher pipeline @@ -290,7 +289,6 @@ func readStatesFrom(store *statestore.Store) ([]file.State, error) { states = append(states, st) return true, nil }) - if err != nil { return nil, err } diff --git a/filebeat/scripts/mage/package.go b/filebeat/scripts/mage/package.go index da0036d31da6..eaf84cb98569 100644 --- a/filebeat/scripts/mage/package.go +++ b/filebeat/scripts/mage/package.go @@ -36,13 +36,13 @@ func CustomizePackaging() { var ( moduleTarget = "module" module = devtools.PackageFile{ - Mode: 0644, + Mode: 0o644, Source: dirModuleGenerated, } modulesDTarget = "modules.d" modulesD = devtools.PackageFile{ - Mode: 0644, + Mode: 0o644, Source: dirModulesDGenerated, Config: true, Modules: true, @@ -101,8 +101,8 @@ func prepareModulePackaging(files ...struct{ Src, Dst string }) error { err := (&devtools.CopyTask{ Source: copyAction.Src, Dest: copyAction.Dst, - Mode: 0644, - DirMode: 0755, + Mode: 0o644, + DirMode: 0o755, Exclude: []string{ "/_meta", "/test", diff --git a/filebeat/scripts/tester/main.go b/filebeat/scripts/tester/main.go index 6da063e6204a..41a197ce3f01 100644 --- a/filebeat/scripts/tester/main.go +++ b/filebeat/scripts/tester/main.go @@ -120,6 +120,7 @@ func main() { } } } + func getLogsFromFile(logfile string, conf *logReaderConfig) ([]string, error) { f, err := os.Open(logfile) if err != nil { @@ -226,7 +227,6 @@ func getPipelinePath(path, modulesPath string) ([]string, error) { } return paths, nil - } func isPipelineFileExtension(path string) bool { diff --git a/x-pack/filebeat/input/awscloudwatch/cloudwatch.go b/x-pack/filebeat/input/awscloudwatch/cloudwatch.go index 29c119117a09..5e300a20425b 100644 --- a/x-pack/filebeat/input/awscloudwatch/cloudwatch.go +++ b/x-pack/filebeat/input/awscloudwatch/cloudwatch.go @@ -28,7 +28,6 @@ type cloudwatchPoller struct { logStreamPrefix string startTime int64 endTime int64 - prevEndTime int64 workerSem *awscommon.Sem log *logp.Logger metrics *inputMetrics diff --git a/x-pack/filebeat/input/awscloudwatch/input_integration_test.go b/x-pack/filebeat/input/awscloudwatch/input_integration_test.go index 633a0ddcada9..a6d17d647f2b 100644 --- a/x-pack/filebeat/input/awscloudwatch/input_integration_test.go +++ b/x-pack/filebeat/input/awscloudwatch/input_integration_test.go @@ -47,14 +47,12 @@ const ( logGroupNamePrefix = "filebeat-log-group-integtest-" ) -var ( - cloudwatchConfig = common.MapStr{ - "start_position": "beginning", - "scan_frequency": 10 * time.Second, - "api_timeout": 120 * time.Second, - "number_of_workers": 1, - } -) +var cloudwatchConfig = common.MapStr{ + "start_position": "beginning", + "scan_frequency": 10 * time.Second, + "api_timeout": 120 * time.Second, + "number_of_workers": 1, +} type terraformOutputData struct { AWSRegion string `yaml:"aws_region"` diff --git a/x-pack/filebeat/input/awscloudwatch/input_test.go b/x-pack/filebeat/input/awscloudwatch/input_test.go index c094a1cddb5a..1e298a1d0676 100644 --- a/x-pack/filebeat/input/awscloudwatch/input_test.go +++ b/x-pack/filebeat/input/awscloudwatch/input_test.go @@ -126,10 +126,6 @@ type MockCloudwatchlogsClient struct { cloudwatchlogsiface.ClientAPI } -var ( - mockSvc = &MockCloudwatchlogsClient{} -) - func (m *MockCloudwatchlogsClient) FilterLogEventsRequest(input *cloudwatchlogs.FilterLogEventsInput) cloudwatchlogs.FilterLogEventsRequest { events := []cloudwatchlogs.FilteredLogEvent{ { diff --git a/x-pack/filebeat/input/awss3/input.go b/x-pack/filebeat/input/awss3/input.go index e1558b552a06..f86bd2c94efa 100644 --- a/x-pack/filebeat/input/awss3/input.go +++ b/x-pack/filebeat/input/awss3/input.go @@ -293,7 +293,7 @@ func getProviderFromDomain(endpoint string, ProviderOverride string) string { return "aws" } // List of popular S3 SaaS providers - var providers = map[string]string{ + providers := map[string]string{ "amazonaws.com": "aws", "c2s.sgov.gov": "aws", "c2s.ic.gov": "aws", diff --git a/x-pack/filebeat/input/awss3/input_benchmark_test.go b/x-pack/filebeat/input/awss3/input_benchmark_test.go index ec7068bb733f..eebc057df671 100644 --- a/x-pack/filebeat/input/awss3/input_benchmark_test.go +++ b/x-pack/filebeat/input/awss3/input_benchmark_test.go @@ -31,8 +31,10 @@ import ( awscommon "github.com/elastic/beats/v7/x-pack/libbeat/common/aws" ) -const cloudtrailTestFile = "testdata/aws-cloudtrail.json.gz" -const totalListingObjects = 10000 +const ( + cloudtrailTestFile = "testdata/aws-cloudtrail.json.gz" + totalListingObjects = 10000 +) type constantSQS struct { msgs []sqs.Message @@ -316,7 +318,6 @@ func benchmarkInputS3(t *testing.T, numberOfWorkers int) testing.BenchmarkResult b.ReportMetric(float64(metrics.s3ObjectsAckedTotal.Get()), "objects_acked") b.ReportMetric(float64(metrics.s3ObjectsAckedTotal.Get())/elapsed.Seconds(), "objects_acked_per_sec") - }) } diff --git a/x-pack/filebeat/input/awss3/s3.go b/x-pack/filebeat/input/awss3/s3.go index aa6e7be80127..56977c5a5ede 100644 --- a/x-pack/filebeat/input/awss3/s3.go +++ b/x-pack/filebeat/input/awss3/s3.go @@ -38,6 +38,7 @@ type s3ObjectPayload struct { s3ObjectInfo s3ObjectInfo s3ObjectEvent s3EventV2 } + type s3Poller struct { numberOfWorkers int bucket string diff --git a/x-pack/filebeat/input/awss3/s3_objects.go b/x-pack/filebeat/input/awss3/s3_objects.go index f2cad6615679..726619945bf1 100644 --- a/x-pack/filebeat/input/awss3/s3_objects.go +++ b/x-pack/filebeat/input/awss3/s3_objects.go @@ -171,7 +171,6 @@ func (p *s3ObjectProcessor) ProcessS3Object() error { // close the returned reader. func (p *s3ObjectProcessor) download() (contentType string, metadata map[string]interface{}, body io.ReadCloser, err error) { resp, err := p.s3.GetObject(p.ctx, p.s3Obj.S3.Bucket.Name, p.s3Obj.S3.Object.Key) - if err != nil { return "", nil, nil, err } @@ -337,7 +336,8 @@ func (p *s3ObjectProcessor) createEvent(message string, offset int64) beat.Event "s3": common.MapStr{ "bucket": common.MapStr{ "name": p.s3Obj.S3.Bucket.Name, - "arn": p.s3Obj.S3.Bucket.ARN}, + "arn": p.s3Obj.S3.Bucket.ARN, + }, "object": common.MapStr{ "key": p.s3Obj.S3.Object.Key, }, diff --git a/x-pack/filebeat/input/awss3/script_session_test.go b/x-pack/filebeat/input/awss3/script_session_test.go index 4cad65b03fda..01ac848d4174 100644 --- a/x-pack/filebeat/input/awss3/script_session_test.go +++ b/x-pack/filebeat/input/awss3/script_session_test.go @@ -27,9 +27,10 @@ func TestSessionScriptParams(t *testing.T) { }) t.Run("register required for params", func(t *testing.T) { - _, err := newScriptFromConfig(log, &scriptConfig{Source: header + footer, Params: map[string]interface{}{ - "p1": 42, - }, + _, err := newScriptFromConfig(log, &scriptConfig{ + Source: header + footer, Params: map[string]interface{}{ + "p1": 42, + }, }) if assert.Error(t, err) { assert.Contains(t, err.Error(), "params were provided") diff --git a/x-pack/filebeat/input/awss3/state_test.go b/x-pack/filebeat/input/awss3/state_test.go index b304d74920fc..24a5e9d81b4e 100644 --- a/x-pack/filebeat/input/awss3/state_test.go +++ b/x-pack/filebeat/input/awss3/state_test.go @@ -21,13 +21,13 @@ func TestStateIsEqual(t *testing.T) { tests := map[string]stateTestCase{ "two states pointing to the same key with same etag and same last modified not stored": { [2]state{ - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag", LastModified: lastModifed, }, - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag", @@ -38,14 +38,14 @@ func TestStateIsEqual(t *testing.T) { }, "two states pointing to the same key with same etag and same last modified stored": { [2]state{ - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag", LastModified: lastModifed, Stored: true, }, - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag", @@ -56,14 +56,14 @@ func TestStateIsEqual(t *testing.T) { }, "two states pointing to the same key with same etag and same last modified error": { [2]state{ - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag", LastModified: lastModifed, Error: true, }, - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag", @@ -74,13 +74,13 @@ func TestStateIsEqual(t *testing.T) { }, "two states pointing to the same key with different etag and same last modified": { [2]state{ - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag1", LastModified: lastModifed, }, - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag2", @@ -91,13 +91,13 @@ func TestStateIsEqual(t *testing.T) { }, "two states pointing to the same key with same etag and different last modified": { [2]state{ - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag", LastModified: time.Now(), }, - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag", @@ -108,13 +108,13 @@ func TestStateIsEqual(t *testing.T) { }, "two states pointing to different key": { [2]state{ - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag", LastModified: lastModifed, }, - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/2", Etag: "etag", @@ -125,13 +125,13 @@ func TestStateIsEqual(t *testing.T) { }, "two states pointing to different bucket": { [2]state{ - state{ + { Bucket: "bucket b", Key: "/key/to/this/file/1", Etag: "etag", LastModified: lastModifed, }, - state{ + { Bucket: "bucket a", Key: "/key/to/this/file/1", Etag: "etag", diff --git a/x-pack/filebeat/input/awss3/states.go b/x-pack/filebeat/input/awss3/states.go index 4aa858e572f8..3d19d0c4a227 100644 --- a/x-pack/filebeat/input/awss3/states.go +++ b/x-pack/filebeat/input/awss3/states.go @@ -289,7 +289,6 @@ func (s *states) readStatesFrom(store *statestore.Store) error { states = append(states, st) return true, nil }) - if err != nil { return err } diff --git a/x-pack/filebeat/input/awss3/states_test.go b/x-pack/filebeat/input/awss3/states_test.go index c99e7c0889b3..4f2b5bd1872b 100644 --- a/x-pack/filebeat/input/awss3/states_test.go +++ b/x-pack/filebeat/input/awss3/states_test.go @@ -27,7 +27,7 @@ func TestStatesDelete(t *testing.T) { expected []state } - lastModified := time.Date(2021, time.July, 22, 18, 38, 00, 0, time.UTC) + lastModified := time.Date(2021, time.July, 22, 18, 38, 0o0, 0, time.UTC) tests := map[string]stateTestCase{ "delete empty states": { states: func() *states { diff --git a/x-pack/filebeat/input/azureeventhub/config.go b/x-pack/filebeat/input/azureeventhub/config.go index 354b2cfb0b5b..82c683c2df23 100644 --- a/x-pack/filebeat/input/azureeventhub/config.go +++ b/x-pack/filebeat/input/azureeventhub/config.go @@ -40,7 +40,6 @@ func (conf *azureInputConfig) Validate() error { } if conf.SAContainer == "" { conf.SAContainer = fmt.Sprintf("%s-%s", ephContainerName, conf.EventHubName) - } err := storageContainerValidate(conf.SAContainer) if err != nil { diff --git a/x-pack/filebeat/input/azureeventhub/config_test.go b/x-pack/filebeat/input/azureeventhub/config_test.go index 8ba1b9f2aae1..be1cf092771f 100644 --- a/x-pack/filebeat/input/azureeventhub/config_test.go +++ b/x-pack/filebeat/input/azureeventhub/config_test.go @@ -12,7 +12,7 @@ import ( ) func TestStorageContainerValidate(t *testing.T) { - var tests = []struct { + tests := []struct { input string errIsNil bool }{ diff --git a/x-pack/filebeat/input/azureeventhub/eph_test.go b/x-pack/filebeat/input/azureeventhub/eph_test.go index 946e85c710a8..609e3a1f94a9 100644 --- a/x-pack/filebeat/input/azureeventhub/eph_test.go +++ b/x-pack/filebeat/input/azureeventhub/eph_test.go @@ -15,15 +15,13 @@ import ( "github.com/stretchr/testify/assert" ) -var ( - invalidConfig = azureInputConfig{ - SAKey: "invalid_key", - SAName: "storage", - SAContainer: ephContainerName, - ConnectionString: "invalid_connection_string", - ConsumerGroup: "$Default", - } -) +var invalidConfig = azureInputConfig{ + SAKey: "invalid_key", + SAName: "storage", + SAContainer: ephContainerName, + ConnectionString: "invalid_connection_string", + ConsumerGroup: "$Default", +} func TestRunWithEPH(t *testing.T) { input := azureInput{config: invalidConfig} diff --git a/x-pack/filebeat/input/azureeventhub/input.go b/x-pack/filebeat/input/azureeventhub/input.go index 2b60a8a1abe7..7d70bffddde3 100644 --- a/x-pack/filebeat/input/azureeventhub/input.go +++ b/x-pack/filebeat/input/azureeventhub/input.go @@ -44,7 +44,6 @@ type azureInput struct { workerWg sync.WaitGroup // waits on worker goroutine. processor *eph.EventProcessorHost // eph will be assigned if users have enabled the option hub *eventhub.Hub // hub will be assigned - ackChannel chan int } const ( diff --git a/x-pack/filebeat/input/azureeventhub/input_test.go b/x-pack/filebeat/input/azureeventhub/input_test.go index 797a54876d4f..c4dec83d61c8 100644 --- a/x-pack/filebeat/input/azureeventhub/input_test.go +++ b/x-pack/filebeat/input/azureeventhub/input_test.go @@ -24,15 +24,13 @@ import ( "github.com/elastic/beats/v7/libbeat/common" ) -var ( - config = azureInputConfig{ - SAKey: "", - SAName: "", - SAContainer: ephContainerName, - ConnectionString: "", - ConsumerGroup: "", - } -) +var config = azureInputConfig{ + SAKey: "", + SAName: "", + SAContainer: ephContainerName, + ConnectionString: "", + ConsumerGroup: "", +} func TestProcessEvents(t *testing.T) { // Stub outlet for receiving events generated by the input. @@ -83,7 +81,8 @@ func TestParseMultipleMessages(t *testing.T) { msgs := []string{ fmt.Sprintf("{\"test\":\"this is some message\",\"time\":\"2019-12-17T13:43:44.4946995Z\"}"), fmt.Sprintf("{\"test\":\"this is 2nd message\",\"time\":\"2019-12-17T13:43:44.4946995Z\"}"), - fmt.Sprintf("{\"test\":\"this is 3rd message\",\"time\":\"2019-12-17T13:43:44.4946995Z\"}")} + fmt.Sprintf("{\"test\":\"this is 3rd message\",\"time\":\"2019-12-17T13:43:44.4946995Z\"}"), + } input := azureInput{log: logp.NewLogger(fmt.Sprintf("%s test for input", inputName))} messages := input.parseMultipleMessages([]byte(msg)) assert.NotNil(t, messages) @@ -165,6 +164,7 @@ func newStubOutlet(stub *stubOutleter) (channel.Outleter, error) { Processing: beat.ProcessingConfig{}, }) } + func (o *stubOutleter) Close() error { o.Lock() defer o.Unlock() diff --git a/x-pack/filebeat/input/http_endpoint/handler.go b/x-pack/filebeat/input/http_endpoint/handler.go index 43e383d03159..daae3a27e8e1 100644 --- a/x-pack/filebeat/input/http_endpoint/handler.go +++ b/x-pack/filebeat/input/http_endpoint/handler.go @@ -103,7 +103,6 @@ func httpReadJSON(body io.Reader) (objs []common.MapStr, rawMessages []json.RawM return nil, nil, http.StatusBadRequest, err } return obj, rawMessage, http.StatusOK, err - } func decodeJSON(body io.Reader) (objs []common.MapStr, rawMessages []json.RawMessage, err error) { diff --git a/x-pack/filebeat/input/http_endpoint/input.go b/x-pack/filebeat/input/http_endpoint/input.go index e697d5f14412..c568172cc4e8 100644 --- a/x-pack/filebeat/input/http_endpoint/input.go +++ b/x-pack/filebeat/input/http_endpoint/input.go @@ -115,7 +115,7 @@ func (e *httpEndpoint) Run(ctx v2.Context, publisher stateless.Publisher) error var err error if server.TLSConfig != nil { log.Infof("Starting HTTPS server on %s", server.Addr) - //certificate is already loaded. That's why the parameters are empty + // certificate is already loaded. That's why the parameters are empty err = server.ListenAndServeTLS("", "") } else { log.Infof("Starting HTTP server on %s", server.Addr) diff --git a/x-pack/filebeat/input/httpjson/config_test.go b/x-pack/filebeat/input/httpjson/config_test.go index 71ee7edb2465..a7d9c17466a1 100644 --- a/x-pack/filebeat/input/httpjson/config_test.go +++ b/x-pack/filebeat/input/httpjson/config_test.go @@ -39,7 +39,7 @@ func TestIsEnabled(t *testing.T) { t.Fatal("OAuth2 should be enabled by default") } - var enabled = false + enabled := false oauth2.Enabled = &enabled assert.False(t, oauth2.isEnabled()) @@ -69,19 +69,19 @@ func TestGetTokenURLWithAzure(t *testing.T) { } func TestGetEndpointParams(t *testing.T) { - var expected = map[string][]string{"foo": {"bar"}} + expected := map[string][]string{"foo": {"bar"}} oauth2 := oAuth2Config{EndpointParams: map[string][]string{"foo": {"bar"}}} assert.Equal(t, expected, oauth2.getEndpointParams()) } func TestGetEndpointParamsWithAzure(t *testing.T) { - var expectedWithoutResource = map[string][]string{"foo": {"bar"}} + expectedWithoutResource := map[string][]string{"foo": {"bar"}} oauth2 := oAuth2Config{Provider: "azure", EndpointParams: map[string][]string{"foo": {"bar"}}} assert.Equal(t, expectedWithoutResource, oauth2.getEndpointParams()) oauth2.AzureResource = "baz" - var expectedWithResource = map[string][]string{"foo": {"bar"}, "resource": {"baz"}} + expectedWithResource := map[string][]string{"foo": {"bar"}, "resource": {"baz"}} assert.Equal(t, expectedWithResource, oauth2.getEndpointParams()) } diff --git a/x-pack/filebeat/input/httpjson/transform_test.go b/x-pack/filebeat/input/httpjson/transform_test.go index cbe90614a8f7..7f4ec145bfa4 100644 --- a/x-pack/filebeat/input/httpjson/transform_test.go +++ b/x-pack/filebeat/input/httpjson/transform_test.go @@ -122,7 +122,6 @@ func (fakeTransform) transformName() string { return "fake" } func TestNewBasicTransformsFromConfig(t *testing.T) { fakeConstr := func(*common.Config, *logp.Logger) (transform, error) { - return fakeTransform{}, nil } diff --git a/x-pack/filebeat/input/httpjson/value_tpl.go b/x-pack/filebeat/input/httpjson/value_tpl.go index d2786b4ce76f..b2231ca42574 100644 --- a/x-pack/filebeat/input/httpjson/value_tpl.go +++ b/x-pack/filebeat/input/httpjson/value_tpl.go @@ -120,21 +120,19 @@ func (t *valueTpl) Execute(trCtx *transformContext, tr transformable, defaultVal return val, nil } -var ( - predefinedLayouts = map[string]string{ - "ANSIC": time.ANSIC, - "UnixDate": time.UnixDate, - "RubyDate": time.RubyDate, - "RFC822": time.RFC822, - "RFC822Z": time.RFC822Z, - "RFC850": time.RFC850, - "RFC1123": time.RFC1123, - "RFC1123Z": time.RFC1123Z, - "RFC3339": time.RFC3339, - "RFC3339Nano": time.RFC3339Nano, - "Kitchen": time.Kitchen, - } -) +var predefinedLayouts = map[string]string{ + "ANSIC": time.ANSIC, + "UnixDate": time.UnixDate, + "RubyDate": time.RubyDate, + "RFC822": time.RFC822, + "RFC822Z": time.RFC822Z, + "RFC850": time.RFC850, + "RFC1123": time.RFC1123, + "RFC1123Z": time.RFC1123Z, + "RFC3339": time.RFC3339, + "RFC3339Nano": time.RFC3339Nano, + "Kitchen": time.Kitchen, +} func now(add ...time.Duration) time.Time { now := timeNow().UTC() diff --git a/x-pack/filebeat/input/netflow/case.go b/x-pack/filebeat/input/netflow/case.go index cfe5e8fbfa14..fefd2ab307c2 100644 --- a/x-pack/filebeat/input/netflow/case.go +++ b/x-pack/filebeat/input/netflow/case.go @@ -16,7 +16,6 @@ import ( var fieldNameConverter = caseConverter{ conversion: map[string]string{ // Special handled fields - // VRFname should be VRFName "VRFname": "vrf_name", }, diff --git a/x-pack/filebeat/input/netflow/convert.go b/x-pack/filebeat/input/netflow/convert.go index 2f10b33c2382..bb445968569c 100644 --- a/x-pack/filebeat/input/netflow/convert.go +++ b/x-pack/filebeat/input/netflow/convert.go @@ -23,21 +23,6 @@ import ( "github.com/elastic/beats/v7/x-pack/filebeat/input/netflow/decoder/record" ) -var ( - // RFC 1918 - privateIPv4 = []net.IPNet{ - {IP: net.IPv4(10, 0, 0, 0), Mask: net.IPv4Mask(255, 0, 0, 0)}, - {IP: net.IPv4(172, 16, 0, 0), Mask: net.IPv4Mask(255, 240, 0, 0)}, - {IP: net.IPv4(192, 168, 0, 0), Mask: net.IPv4Mask(255, 255, 0, 0)}, - } - - // RFC 4193 - privateIPv6 = net.IPNet{ - IP: net.IP{0xfd, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - Mask: net.IPMask{0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - } -) - func toBeatEvent(flow record.Record, internalNetworks []string) (event beat.Event) { switch flow.Type { case record.Flow: diff --git a/x-pack/filebeat/input/netflow/decoder/decoder.go b/x-pack/filebeat/input/netflow/decoder/decoder.go index 4f8d178df5c5..993c373c8813 100644 --- a/x-pack/filebeat/input/netflow/decoder/decoder.go +++ b/x-pack/filebeat/input/netflow/decoder/decoder.go @@ -27,7 +27,6 @@ type Decoder struct { protos map[uint16]protocol.Protocol started bool logger log.Logger - config config.Config } // NewDecoder returns a new NetFlow decoder configured using the passed diff --git a/x-pack/filebeat/input/netflow/decoder/fields/field_test.go b/x-pack/filebeat/input/netflow/decoder/fields/field_test.go index 883a0c6903b8..343d2c688c24 100644 --- a/x-pack/filebeat/input/netflow/decoder/fields/field_test.go +++ b/x-pack/filebeat/input/netflow/decoder/fields/field_test.go @@ -45,7 +45,6 @@ func TestFieldDict_Merge(t *testing.T) { if !checkContains(t, f, c) { t.FailNow() } - } func checkContains(t testing.TB, dest FieldDict, contains FieldDict) bool { diff --git a/x-pack/filebeat/input/netflow/decoder/fields/types_test.go b/x-pack/filebeat/input/netflow/decoder/fields/types_test.go index ffe56c831dd4..11997de14530 100644 --- a/x-pack/filebeat/input/netflow/decoder/fields/types_test.go +++ b/x-pack/filebeat/input/netflow/decoder/fields/types_test.go @@ -1105,7 +1105,8 @@ func TestACLID(t *testing.T) { bytes: []byte{ 0x10, 0x21, 0x32, 0x43, 0x54, 0x65, 0x76, 0x87, - 0x98, 0xA9, 0xBA, 0xCD}, + 0x98, 0xA9, 0xBA, 0xCD, + }, value: "10213243-54657687-98a9bacd", }, { @@ -1113,7 +1114,8 @@ func TestACLID(t *testing.T) { bytes: []byte{ 0x10, 0x21, 0x32, 0x43, 0x54, 0x65, 0x76, 0x87, - 0x98, 0xA9, 0xBA}, + 0x98, 0xA9, 0xBA, + }, err: true, }, { @@ -1122,7 +1124,8 @@ func TestACLID(t *testing.T) { 0x10, 0x21, 0x32, 0x43, 0x54, 0x65, 0x76, 0x87, 0x98, 0xA9, 0xBA, 0xCD, - 0xDF}, + 0xDF, + }, err: true, }, }) diff --git a/x-pack/filebeat/input/netflow/decoder/protocol/protocol.go b/x-pack/filebeat/input/netflow/decoder/protocol/protocol.go index 3ae756eb140e..452a79b4d25f 100644 --- a/x-pack/filebeat/input/netflow/decoder/protocol/protocol.go +++ b/x-pack/filebeat/input/netflow/decoder/protocol/protocol.go @@ -13,7 +13,6 @@ import ( // Protocol is the interface that NetFlow protocol parsers must conform to. type Protocol interface { - // Version returns the NetFlow version that this protocol implements. // The version number in packet headers is compared with this value to // select the appropriate protocol parser. diff --git a/x-pack/filebeat/input/netflow/decoder/template/template.go b/x-pack/filebeat/input/netflow/decoder/template/template.go index 8709ca8766e1..0dc207a241a0 100644 --- a/x-pack/filebeat/input/netflow/decoder/template/template.go +++ b/x-pack/filebeat/input/netflow/decoder/template/template.go @@ -19,9 +19,7 @@ const ( VariableLength uint16 = 0xffff ) -var ( - ErrEmptyTemplate = errors.New("empty template") -) +var ErrEmptyTemplate = errors.New("empty template") type Template struct { ID uint16 diff --git a/x-pack/filebeat/input/netflow/decoder/v9/session_test.go b/x-pack/filebeat/input/netflow/decoder/v9/session_test.go index 63bbf3314aa8..1631c7b3036a 100644 --- a/x-pack/filebeat/input/netflow/decoder/v9/session_test.go +++ b/x-pack/filebeat/input/netflow/decoder/v9/session_test.go @@ -56,7 +56,6 @@ func TestSessionMap_GetOrCreate(t *testing.T) { s2b := sm.GetOrCreate(makeSessionKey(t, "127.0.0.1:1235", 43)) assert.NotNil(t, s2b) assert.False(t, s2 == s2b) - }) t.Run("parallel", func(t *testing.T) { // Goroutines should observe the same session when created in parallel diff --git a/x-pack/filebeat/input/netflow/decoder/v9/v9.go b/x-pack/filebeat/input/netflow/decoder/v9/v9.go index 30cb1405f39c..22c4cf78b60d 100644 --- a/x-pack/filebeat/input/netflow/decoder/v9/v9.go +++ b/x-pack/filebeat/input/netflow/decoder/v9/v9.go @@ -119,8 +119,8 @@ func (p *NetflowV9Protocol) OnPacket(buf *bytes.Buffer, source net.Addr) (flows func (p *NetflowV9Protocol) parseSet( setID uint16, session *SessionState, - buf *bytes.Buffer) (flows []record.Record, err error) { - + buf *bytes.Buffer) (flows []record.Record, err error, +) { if setID >= 256 { // Flow of Options record, lookup template and generate flows if template := session.GetTemplate(setID); template != nil { diff --git a/x-pack/filebeat/input/netflow/decoder/v9/v9_test.go b/x-pack/filebeat/input/netflow/decoder/v9/v9_test.go index 007f006ac13f..5776620c80d8 100644 --- a/x-pack/filebeat/input/netflow/decoder/v9/v9_test.go +++ b/x-pack/filebeat/input/netflow/decoder/v9/v9_test.go @@ -153,7 +153,7 @@ func TestSessionReset(t *testing.T) { flowsPacket := []uint16{ // Header // Version, Count, Uptime, Ts, SeqNo, Source - 9, 1, 11, 11, 22, 22, 00, 33, 0, 1234, + 9, 1, 11, 11, 22, 22, 0o0, 33, 0, 1234, // Set #1 (template) 999, 16, /*len of set*/ 1, 1, diff --git a/x-pack/filebeat/input/netflow/netflow_test.go b/x-pack/filebeat/input/netflow/netflow_test.go index caaa438ebf36..b567d67bc431 100644 --- a/x-pack/filebeat/input/netflow/netflow_test.go +++ b/x-pack/filebeat/input/netflow/netflow_test.go @@ -79,11 +79,11 @@ func TestPCAPFiles(t *testing.T) { t.Fatal(err) } - if err = os.MkdirAll(goldenDir, 0755); err != nil { + if err = os.MkdirAll(goldenDir, 0o755); err != nil { t.Fatal(err) } - err = ioutil.WriteFile(goldenName, data, 0644) + err = ioutil.WriteFile(goldenName, data, 0o644) if err != nil { t.Fatal(err) } @@ -111,11 +111,11 @@ func TestDatFiles(t *testing.T) { t.Fatal(err) } - if err = os.MkdirAll(goldenDir, 0755); err != nil { + if err = os.MkdirAll(goldenDir, 0o755); err != nil { t.Fatal(err) } - err = ioutil.WriteFile(goldenName, data, 0644) + err = ioutil.WriteFile(goldenName, data, 0o644) if err != nil { t.Fatal(err) } diff --git a/x-pack/filebeat/input/o365audit/config.go b/x-pack/filebeat/input/o365audit/config.go index 97402971e38d..1251ebe731d2 100644 --- a/x-pack/filebeat/input/o365audit/config.go +++ b/x-pack/filebeat/input/o365audit/config.go @@ -94,7 +94,6 @@ type APIConfig struct { func defaultConfig() Config { return Config{ - // All documented content types. ContentType: []string{ "Audit.AzureActiveDirectory", diff --git a/x-pack/filebeat/input/o365audit/dates.go b/x-pack/filebeat/input/o365audit/dates.go index 848df7a0c228..30f58d11e01a 100644 --- a/x-pack/filebeat/input/o365audit/dates.go +++ b/x-pack/filebeat/input/o365audit/dates.go @@ -19,9 +19,7 @@ const ( timeDay = time.Hour * 24 ) -var ( - errTypeCastFailed = errors.New("key is not expected type") -) +var errTypeCastFailed = errors.New("key is not expected type") // Date formats used in the JSON objects returned by the API. // This is just a safeguard in case the date format used by the API is diff --git a/x-pack/filebeat/input/o365audit/poll/poll.go b/x-pack/filebeat/input/o365audit/poll/poll.go index e68f0f54c8f8..c7e5e36135cf 100644 --- a/x-pack/filebeat/input/o365audit/poll/poll.go +++ b/x-pack/filebeat/input/o365audit/poll/poll.go @@ -75,6 +75,7 @@ func (r *Poller) Run(item Transaction) error { } return nil } + func (r *Poller) fetch(item Transaction) error { return r.fetchWithDelay(item, r.interval) } diff --git a/x-pack/filebeat/main_test.go b/x-pack/filebeat/main_test.go index 6dc51ffe5751..3d5424c30884 100644 --- a/x-pack/filebeat/main_test.go +++ b/x-pack/filebeat/main_test.go @@ -14,8 +14,10 @@ import ( fbcmd "github.com/elastic/beats/v7/x-pack/filebeat/cmd" ) -var systemTest *bool -var fbCommand *cmd.BeatsRootCmd +var ( + systemTest *bool + fbCommand *cmd.BeatsRootCmd +) func init() { testing.Init() diff --git a/x-pack/filebeat/processors/add_nomad_metadata/matchers.go b/x-pack/filebeat/processors/add_nomad_metadata/matchers.go index 187645d15604..8fd2f99a97b7 100644 --- a/x-pack/filebeat/processors/add_nomad_metadata/matchers.go +++ b/x-pack/filebeat/processors/add_nomad_metadata/matchers.go @@ -17,8 +17,11 @@ import ( // LogPathMatcherName is the name of LogPathMatcher const LogPathMatcherName = "logs_path" -const pathSeparator = string(os.PathSeparator) -const allocIDRegex = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}" + +const ( + pathSeparator = string(os.PathSeparator) + allocIDRegex = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}" +) // const allocIDTypeRegex = "([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}).*(stdout|stderr)" @@ -26,11 +29,11 @@ func init() { add_nomad_metadata.Indexing.AddMatcher(LogPathMatcherName, newLogsPathMatcher) cfg := common.NewConfig() - //Add a container indexer config by default. + // Add a container indexer config by default. add_nomad_metadata.Indexing.AddDefaultIndexerConfig(add_nomad_metadata.AllocationNameIndexerName, *cfg) add_nomad_metadata.Indexing.AddDefaultIndexerConfig(add_nomad_metadata.AllocationUUIDIndexerName, *cfg) - //Add a log path matcher which can extract container ID from the "source" field. + // Add a log path matcher which can extract container ID from the "source" field. add_nomad_metadata.Indexing.AddDefaultMatcherConfig(LogPathMatcherName, *cfg) } diff --git a/x-pack/filebeat/processors/add_nomad_metadata/matchers_test.go b/x-pack/filebeat/processors/add_nomad_metadata/matchers_test.go index 1a084f8362ab..0022eac2e351 100644 --- a/x-pack/filebeat/processors/add_nomad_metadata/matchers_test.go +++ b/x-pack/filebeat/processors/add_nomad_metadata/matchers_test.go @@ -41,7 +41,7 @@ func TestLogsPathMatcherWithAllocation(t *testing.T) { } func executeTest(t *testing.T, cfgLogsPath string, source string, expectedResult string) { - var cfg = common.NewConfig() + cfg := common.NewConfig() if cfgLogsPath != "" { cfg.SetString("logs_path", -1, cfgLogsPath) } diff --git a/x-pack/filebeat/processors/decode_cef/cef/cef_test.go b/x-pack/filebeat/processors/decode_cef/cef/cef_test.go index 51f3c937ebf0..747cddc62dbb 100644 --- a/x-pack/filebeat/processors/decode_cef/cef/cef_test.go +++ b/x-pack/filebeat/processors/decode_cef/cef/cef_test.go @@ -86,7 +86,7 @@ func TestGenerateFuzzCorpus(t *testing.T) { h.Write([]byte(m)) name := hex.EncodeToString(h.Sum(nil)) - ioutil.WriteFile(filepath.Join("fuzz/corpus", name), []byte(m), 0644) + ioutil.WriteFile(filepath.Join("fuzz/corpus", name), []byte(m), 0o644) } } @@ -433,6 +433,7 @@ func StringField(v string) *Field { return &Field{String: v, Type: StringType, I func IntegerField(v int32) *Field { return &Field{String: strconv.Itoa(int(v)), Type: IntegerType, Interface: v} } + func LongField(v int64) *Field { return &Field{String: strconv.Itoa(int(v)), Type: LongType, Interface: v} } diff --git a/x-pack/filebeat/processors/decode_cef/cef/cmd/cef2json/cef2json.go b/x-pack/filebeat/processors/decode_cef/cef/cmd/cef2json/cef2json.go index 30b40bf5fbbb..c15942c198cf 100644 --- a/x-pack/filebeat/processors/decode_cef/cef/cmd/cef2json/cef2json.go +++ b/x-pack/filebeat/processors/decode_cef/cef/cmd/cef2json/cef2json.go @@ -16,9 +16,7 @@ import ( "github.com/elastic/beats/v7/x-pack/filebeat/processors/decode_cef/cef" ) -var ( - fullExtensionNames bool -) +var fullExtensionNames bool func init() { flag.BoolVar(&fullExtensionNames, "full", true, "Use full extension key names.") diff --git a/x-pack/filebeat/processors/decode_cef/cef/types_test.go b/x-pack/filebeat/processors/decode_cef/cef/types_test.go index feb788e24fbc..c70b1c07ecaa 100644 --- a/x-pack/filebeat/processors/decode_cef/cef/types_test.go +++ b/x-pack/filebeat/processors/decode_cef/cef/types_test.go @@ -13,7 +13,7 @@ import ( ) func TestToTimestamp(t *testing.T) { - var times = []string{ + times := []string{ // Unix epoch in milliseconds. "1322004689000", @@ -81,7 +81,7 @@ func TestToTimestampWithTimezone(t *testing.T) { } func TestToMACAddress(t *testing.T) { - var macs = []string{ + macs := []string{ // EUI-48 (with and without separators). "00:0D:60:AF:1B:61", "00-0D-60-AF-1B-61", diff --git a/x-pack/filebeat/processors/decode_cef/decode_cef_test.go b/x-pack/filebeat/processors/decode_cef/decode_cef_test.go index 710bb894064d..bb9e8ba95b06 100644 --- a/x-pack/filebeat/processors/decode_cef/decode_cef_test.go +++ b/x-pack/filebeat/processors/decode_cef/decode_cef_test.go @@ -28,7 +28,7 @@ func TestProcessorRun(t *testing.T) { fields common.MapStr } - var testCases = map[string]testCase{ + testCases := map[string]testCase{ "custom_target_root": { config: func() config { c := defaultConfig() @@ -251,7 +251,7 @@ func readGoldenJSON(t testing.TB, source string) []common.MapStr { func writeGoldenJSON(t testing.TB, source string, events []common.MapStr) { dest := source + ".golden.json" - f, err := os.OpenFile(dest, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + f, err := os.OpenFile(dest, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644) if err != nil { t.Fatal(err) }