From 81f80e62afc74650b054a73ab08234ee12c670d3 Mon Sep 17 00:00:00 2001 From: JustWPH Date: Tue, 16 Mar 2021 21:50:47 +0800 Subject: [PATCH] fix golang ci yaml and improve makefile (#61) * fix golang ci yaml and improve makefile --- .golangci.yml | 21 +++++++++-- Makefile | 6 +++- operator/builtin/input/file/config_test.go | 17 ++++----- operator/builtin/input/file/file.go | 35 +++++++++---------- operator/builtin/input/file/file_test.go | 3 +- .../builtin/input/file/fingerprint_test.go | 2 -- .../builtin/input/file/line_splitter_test.go | 4 +-- operator/builtin/input/syslog/syslog.go | 7 ++-- operator/builtin/input/syslog/syslog_test.go | 12 +++---- operator/builtin/input/tcp/tcp.go | 2 +- operator/builtin/input/tcp/tcp_test.go | 2 -- operator/builtin/input/windows/security.go | 4 +-- .../builtin/input/windows/security_test.go | 10 ------ operator/builtin/parser/json/json_test.go | 1 - .../builtin/parser/severity/severity_test.go | 8 ++--- operator/builtin/parser/syslog/data.go | 13 ++++--- operator/builtin/parser/syslog/syslog.go | 7 ++-- operator/builtin/parser/syslog/syslog_test.go | 6 ++-- operator/builtin/parser/time/time_test.go | 6 +--- operator/builtin/parser/uri/uri.go | 23 ++++++------ .../builtin/transformer/noop/noop_test.go | 11 ------ .../transformer/recombine/recombine.go | 2 +- .../restructure/restructure_test.go | 22 ++---------- .../builtin/transformer/router/router_test.go | 4 +-- 24 files changed, 93 insertions(+), 135 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 49d84028b140..735a2840a9bb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,11 +1,18 @@ --- +run: + issues-exit-code: 1 + tests: true + skip-dirs: + skip-dirs-use-default: false + skip-files: linters: + disable: + - errcheck enable: + - gofmt - bodyclose - goconst - gocritic - - goimports - - maligned - misspell - nakedret - prealloc @@ -14,5 +21,13 @@ linters: - whitespace - ineffassign linters-settings: + gci: + local-prefixes: github.com/open-telemetry/opentelemetry-log-collection goconst: - min-occurrences: 5 \ No newline at end of file + min-occurrences: 5 +issues: + exclude-rules: + - path: operator/builtin/input/windows/xml\.go + linters: + - unused + - deadcode \ No newline at end of file diff --git a/Makefile b/Makefile index 406739c7b6d7..a5f21e44f818 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,11 @@ listmod: .PHONY: lint lint: - golangci-lint run ./... + golangci-lint run --allow-parallel-runners ./... + +.PHONY: lint-fix +lint-fix: + golangci-lint run --fix --allow-parallel-runners ./... .PHONY: vet vet: diff --git a/operator/builtin/input/file/config_test.go b/operator/builtin/input/file/config_test.go index fc443bb9d92e..1e6464d3a855 100644 --- a/operator/builtin/input/file/config_test.go +++ b/operator/builtin/input/file/config_test.go @@ -339,8 +339,7 @@ func TestConfig(t *testing.T) { false, func() *InputConfig { cfg := defaultCfg() - var newMulti *MultilineConfig - newMulti = new(MultilineConfig) + newMulti := new(MultilineConfig) newMulti.LineStartPattern = "Start" cfg.Multiline = newMulti return cfg @@ -351,8 +350,7 @@ func TestConfig(t *testing.T) { false, func() *InputConfig { cfg := defaultCfg() - var newMulti *MultilineConfig - newMulti = new(MultilineConfig) + newMulti := new(MultilineConfig) newMulti.LineStartPattern = "%" cfg.Multiline = newMulti return cfg @@ -363,8 +361,7 @@ func TestConfig(t *testing.T) { false, func() *InputConfig { cfg := defaultCfg() - var newMulti *MultilineConfig - newMulti = new(MultilineConfig) + newMulti := new(MultilineConfig) newMulti.LineEndPattern = "Start" cfg.Multiline = newMulti return cfg @@ -375,8 +372,7 @@ func TestConfig(t *testing.T) { false, func() *InputConfig { cfg := defaultCfg() - var newMulti *MultilineConfig - newMulti = new(MultilineConfig) + newMulti := new(MultilineConfig) newMulti.LineEndPattern = "%" cfg.Multiline = newMulti return cfg @@ -468,7 +464,7 @@ func TestConfig(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - cfgFromYaml, yamlErr := configFromFileViaYaml(t, path.Join(".", "testdata", fmt.Sprintf("%s.yaml", tc.name))) + cfgFromYaml, yamlErr := configFromFileViaYaml(path.Join(".", "testdata", fmt.Sprintf("%s.yaml", tc.name))) cfgFromMapstructure, mapErr := configFromFileViaMapstructure(path.Join(".", "testdata", fmt.Sprintf("%s.yaml", tc.name))) if tc.expectErr { require.Error(t, yamlErr) @@ -483,7 +479,7 @@ func TestConfig(t *testing.T) { } } -func configFromFileViaYaml(t *testing.T, file string) (*InputConfig, error) { +func configFromFileViaYaml(file string) (*InputConfig, error) { bytes, err := ioutil.ReadFile(file) if err != nil { return nil, fmt.Errorf("could not find config file: %s", err) @@ -520,7 +516,6 @@ func configFromFileViaMapstructure(file string) (*InputConfig, error) { return nil, err } return cfg, nil - } func defaultCfg() *InputConfig { diff --git a/operator/builtin/input/file/file.go b/operator/builtin/input/file/file.go index 9214731e0445..6582f142885d 100644 --- a/operator/builtin/input/file/file.go +++ b/operator/builtin/input/file/file.go @@ -57,7 +57,6 @@ type InputOperator struct { encoding encoding.Encoding wg sync.WaitGroup - readerWg sync.WaitGroup firstCheck bool cancel context.CancelFunc } @@ -111,25 +110,26 @@ func (f *InputOperator) startPoller(ctx context.Context) { // poll checks all the watched paths for new entries func (f *InputOperator) poll(ctx context.Context) { - var matches []string if len(f.queuedMatches) > f.MaxConcurrentFiles { matches, f.queuedMatches = f.queuedMatches[:f.MaxConcurrentFiles], f.queuedMatches[f.MaxConcurrentFiles:] - } else if len(f.queuedMatches) > 0 { - matches, f.queuedMatches = f.queuedMatches, make([]string, 0) } else { - // Increment the generation on all known readers - // This is done here because the next generation is about to start - for i := 0; i < len(f.knownFiles); i++ { - f.knownFiles[i].generation++ - } + if len(f.queuedMatches) > 0 { + matches, f.queuedMatches = f.queuedMatches, make([]string, 0) + } else { + // Increment the generation on all known readers + // This is done here because the next generation is about to start + for i := 0; i < len(f.knownFiles); i++ { + f.knownFiles[i].generation++ + } - // Get the list of paths on disk - matches = getMatches(f.Include, f.Exclude) - if f.firstCheck && len(matches) == 0 { - f.Warnw("no files match the configured include patterns", "include", f.Include) - } else if len(matches) > f.MaxConcurrentFiles { - matches, f.queuedMatches = matches[:f.MaxConcurrentFiles], matches[f.MaxConcurrentFiles:] + // Get the list of paths on disk + matches = getMatches(f.Include, f.Exclude) + if f.firstCheck && len(matches) == 0 { + f.Warnw("no files match the configured include patterns", "include", f.Include) + } else if len(matches) > f.MaxConcurrentFiles { + matches, f.queuedMatches = matches[:f.MaxConcurrentFiles], matches[f.MaxConcurrentFiles:] + } } } @@ -229,7 +229,6 @@ OUTER: // Empty file, don't read it until we can compare its fingerprint fps = append(fps[:i], fps[i+1:]...) filesCopy = append(filesCopy[:i], filesCopy[i+1:]...) - } for j := 0; j < len(fps); j++ { @@ -267,9 +266,7 @@ OUTER: // before clearing out readers that have existed for 3 generations. func (f *InputOperator) saveCurrent(readers []*Reader) { // Add readers from the current, completed poll interval to the list of known files - for _, reader := range readers { - f.knownFiles = append(f.knownFiles, reader) - } + f.knownFiles = append(f.knownFiles, readers...) // Clear out old readers. They are sorted such that they are oldest first, // so we can just find the first reader whose generation is less than our diff --git a/operator/builtin/input/file/file_test.go b/operator/builtin/input/file/file_test.go index a67bea8f8e2b..de8dea41b4cc 100644 --- a/operator/builtin/input/file/file_test.go +++ b/operator/builtin/input/file/file_test.go @@ -134,7 +134,7 @@ func TestBuild(t *testing.T) { }{ { "Basic", - func(f *InputConfig) { return }, + func(f *InputConfig) {}, require.NoError, func(t *testing.T, f *InputOperator) { require.Equal(t, f.OutputOperators[0], fakeOutput) @@ -802,7 +802,6 @@ func (rt rotationTest) run(tc rotationTest, copyTruncate, sequential bool) func( } func TestRotation(t *testing.T) { - cases := []rotationTest{ { name: "NoRotation", diff --git a/operator/builtin/input/file/fingerprint_test.go b/operator/builtin/input/file/fingerprint_test.go index 51e84311e2ce..4ead95c900e5 100644 --- a/operator/builtin/input/file/fingerprint_test.go +++ b/operator/builtin/input/file/fingerprint_test.go @@ -23,7 +23,6 @@ import ( ) func TestNewFingerprintDoesNotModifyOffset(t *testing.T) { - fingerprint := "this is the fingerprint" next := "this comes after the fingerprint and is substantially longer than the fingerprint" extra := "fin" @@ -61,7 +60,6 @@ func TestNewFingerprintDoesNotModifyOffset(t *testing.T) { } func TestNewFingerprint(t *testing.T) { - cases := []struct { name string fingerprintSize int diff --git a/operator/builtin/input/file/line_splitter_test.go b/operator/builtin/input/file/line_splitter_test.go index e2d75a21be06..1031b5c8578b 100644 --- a/operator/builtin/input/file/line_splitter_test.go +++ b/operator/builtin/input/file/line_splitter_test.go @@ -151,14 +151,14 @@ func TestLineStartSplitFunc(t *testing.T) { data := []byte(`LOGSTART`) t.Run("NotAtEOF", func(t *testing.T) { - advance, token, err := splitFunc(data[:], false) + advance, token, err := splitFunc(data, false) require.NoError(t, err) require.Equal(t, 0, advance) require.Nil(t, token) }) t.Run("AtEOF", func(t *testing.T) { - advance, token, err := splitFunc(data[:], true) + advance, token, err := splitFunc(data, true) require.NoError(t, err) require.Equal(t, 0, advance) require.Nil(t, token) diff --git a/operator/builtin/input/syslog/syslog.go b/operator/builtin/input/syslog/syslog.go index e96c5c7a2aa9..7c668938c561 100644 --- a/operator/builtin/input/syslog/syslog.go +++ b/operator/builtin/input/syslog/syslog.go @@ -87,15 +87,14 @@ func (c *SyslogInputConfig) UnmarshalYAML(unmarshal func(interface{}) error) err } c.SyslogParserConfig = *parserCfg - base := &BaseSyslogInputConfig{ - } - err = unmarshal(base) + base := &BaseSyslogInputConfig{} + err = unmarshal(base) if err != nil { return err } c.InputConfig = base.InputConfig - c.Tcp= base.Tcp + c.Tcp = base.Tcp c.Udp = base.Udp return nil } diff --git a/operator/builtin/input/syslog/syslog_test.go b/operator/builtin/input/syslog/syslog_test.go index 1c01def2414e..8b9fb72197f6 100644 --- a/operator/builtin/input/syslog/syslog_test.go +++ b/operator/builtin/input/syslog/syslog_test.go @@ -71,10 +71,9 @@ func SyslogInputTest(t *testing.T, cfg *SyslogInputConfig, tc syslog.Case) { require.NoError(t, err) } - switch tc.InputRecord.(type) { - case string: - _, err = conn.Write([]byte(tc.InputRecord.(string))) - case []byte: + if v, ok := tc.InputRecord.(string); ok { + _, err = conn.Write([]byte(v)) + } else { _, err = conn.Write(tc.InputRecord.([]byte)) } @@ -121,7 +120,7 @@ udp: var cfg SyslogInputConfig err := yaml.Unmarshal([]byte(base), &cfg) require.NoError(t, err) - require.Equal(t, "rfc5424", cfg.Protocol) + require.Equal(t, syslog.RFC5424, cfg.Protocol) require.Equal(t, "localhost:1234", cfg.Udp.ListenAddress) base = `type: syslog_input @@ -133,8 +132,7 @@ tcp: ` err = yaml.Unmarshal([]byte(base), &cfg) require.NoError(t, err) - require.Equal(t, "rfc5424", cfg.Protocol) + require.Equal(t, syslog.RFC5424, cfg.Protocol) require.Equal(t, "localhost:1234", cfg.Tcp.ListenAddress) require.Equal(t, "/tmp/test.ca", cfg.Tcp.TLS.CAFile) - } diff --git a/operator/builtin/input/tcp/tcp.go b/operator/builtin/input/tcp/tcp.go index d4fa2e730dbd..7bcb4fd9e4c9 100644 --- a/operator/builtin/input/tcp/tcp.go +++ b/operator/builtin/input/tcp/tcp.go @@ -136,7 +136,7 @@ func (t *TCPInput) configureListener() error { return nil } - t.tls.Time = func() time.Time { return time.Now() } + t.tls.Time = time.Now t.tls.Rand = rand.Reader listener, err := tls.Listen("tcp", t.address, t.tls) diff --git a/operator/builtin/input/tcp/tcp_test.go b/operator/builtin/input/tcp/tcp_test.go index fa6b5b7ff3c3..0da1b6de09fc 100644 --- a/operator/builtin/input/tcp/tcp_test.go +++ b/operator/builtin/input/tcp/tcp_test.go @@ -132,7 +132,6 @@ func tcpInputTest(input []byte, expected []string) func(t *testing.T) { func tlsTCPInputTest(input []byte, expected []string) func(t *testing.T) { return func(t *testing.T) { - f, err := os.Create("test.crt") require.NoError(t, err) defer f.Close() @@ -335,5 +334,4 @@ func createTlsConfig(cert string, key string) *helper.TLSServerConfig { KeyFile: key, }, }) - } diff --git a/operator/builtin/input/windows/security.go b/operator/builtin/input/windows/security.go index b83ca20428bd..6a9b0f6f365b 100644 --- a/operator/builtin/input/windows/security.go +++ b/operator/builtin/input/windows/security.go @@ -19,8 +19,8 @@ import ( ) func parseSecurity(message string) (string, map[string]interface{}) { - - subject, details := message, map[string]interface{}{} + var subject string + details := map[string]interface{}{} mp := newMessageProcessor(message) diff --git a/operator/builtin/input/windows/security_test.go b/operator/builtin/input/windows/security_test.go index a008d309051e..ad36330fb360 100644 --- a/operator/builtin/input/windows/security_test.go +++ b/operator/builtin/input/windows/security_test.go @@ -24,7 +24,6 @@ import ( ) func TestParseSecurity(t *testing.T) { - testCases := []string{ "account_name_changed", "audit_settings_changed", @@ -51,7 +50,6 @@ func TestParseSecurity(t *testing.T) { for _, tc := range testCases { t.Run(tc, func(t *testing.T) { - testDir := filepath.Join("testdata", "security", tc) messageBytes, err := ioutil.ReadFile(filepath.Join(testDir, "message.in")) require.NoError(t, err, "problem reading input file") @@ -77,11 +75,3 @@ func TestParseSecurity(t *testing.T) { }) } } - -// Use this to initialize test results from a WEL security message -// make sure to validate manually! -func initTestResult(testDir, message string, details map[string]interface{}) { - ioutil.WriteFile(filepath.Join(testDir, "message.out"), []byte(message), 0644) - bytes, _ := json.MarshalIndent(details, "", " ") - ioutil.WriteFile(filepath.Join(testDir, "details.out"), bytes, 0644) -} diff --git a/operator/builtin/parser/json/json_test.go b/operator/builtin/parser/json/json_test.go index 2c1e47dc0335..675cb83aa032 100644 --- a/operator/builtin/parser/json/json_test.go +++ b/operator/builtin/parser/json/json_test.go @@ -154,7 +154,6 @@ func TestJSONParser(t *testing.T) { } func TestJSONParserWithEmbeddedTimeParser(t *testing.T) { - testTime := time.Unix(1136214245, 0) cases := []struct { diff --git a/operator/builtin/parser/severity/severity_test.go b/operator/builtin/parser/severity/severity_test.go index d14e344f537e..270d0bc7da38 100644 --- a/operator/builtin/parser/severity/severity_test.go +++ b/operator/builtin/parser/severity/severity_test.go @@ -38,7 +38,6 @@ type severityTestCase struct { } func TestSeverityParser(t *testing.T) { - testCases := []severityTestCase{ { name: "unknown", @@ -304,17 +303,16 @@ func TestSeverityParser(t *testing.T) { t.Run(tc.name, func(t *testing.T) { rootCfg := parseSeverityTestConfig(rootField, tc.mappingSet, tc.mapping) rootEntry := makeTestEntry(rootField, tc.sample) - t.Run("root", runSeverityParseTest(t, rootCfg, rootEntry, tc.buildErr, tc.parseErr, tc.expected)) + t.Run("root", runSeverityParseTest(rootCfg, rootEntry, tc.buildErr, tc.parseErr, tc.expected)) nonRootCfg := parseSeverityTestConfig(someField, tc.mappingSet, tc.mapping) nonRootEntry := makeTestEntry(someField, tc.sample) - t.Run("non-root", runSeverityParseTest(t, nonRootCfg, nonRootEntry, tc.buildErr, tc.parseErr, tc.expected)) + t.Run("non-root", runSeverityParseTest(nonRootCfg, nonRootEntry, tc.buildErr, tc.parseErr, tc.expected)) }) } } -func runSeverityParseTest(t *testing.T, cfg *SeverityParserConfig, ent *entry.Entry, buildErr bool, parseErr bool, expected entry.Severity) func(*testing.T) { - +func runSeverityParseTest(cfg *SeverityParserConfig, ent *entry.Entry, buildErr bool, parseErr bool, expected entry.Severity) func(*testing.T) { return func(t *testing.T) { buildContext := testutil.NewBuildContext(t) diff --git a/operator/builtin/parser/syslog/data.go b/operator/builtin/parser/syslog/data.go index 9a1a7b5d3ff4..462db168207c 100644 --- a/operator/builtin/parser/syslog/data.go +++ b/operator/builtin/parser/syslog/data.go @@ -58,7 +58,7 @@ func CreateCases(basicConfig func() *SyslogParserConfig) ([]Case, error) { "RFC3164", func() *SyslogParserConfig { cfg := basicConfig() - cfg.Protocol = "rfc3164" + cfg.Protocol = RFC3164 cfg.Location = location["utc"].String() return cfg }(), @@ -78,7 +78,7 @@ func CreateCases(basicConfig func() *SyslogParserConfig) ([]Case, error) { "RFC3164Detroit", func() *SyslogParserConfig { cfg := basicConfig() - cfg.Protocol = "rfc3164" + cfg.Protocol = RFC3164 cfg.Location = location["detroit"].String() return cfg }(), @@ -98,7 +98,7 @@ func CreateCases(basicConfig func() *SyslogParserConfig) ([]Case, error) { "RFC3164Athens", func() *SyslogParserConfig { cfg := basicConfig() - cfg.Protocol = "rfc3164" + cfg.Protocol = RFC3164 cfg.Location = location["athens"].String() return cfg }(), @@ -118,7 +118,7 @@ func CreateCases(basicConfig func() *SyslogParserConfig) ([]Case, error) { "RFC3164Bytes", func() *SyslogParserConfig { cfg := basicConfig() - cfg.Protocol = "rfc3164" + cfg.Protocol = RFC3164 return cfg }(), []byte("<34>Jan 12 06:30:00 1.2.3.4 apache_server: test message"), @@ -137,7 +137,7 @@ func CreateCases(basicConfig func() *SyslogParserConfig) ([]Case, error) { "RFC5424", func() *SyslogParserConfig { cfg := basicConfig() - cfg.Protocol = "rfc5424" + cfg.Protocol = RFC5424 return cfg }(), `<86>1 2015-08-05T21:58:59.693Z 192.168.2.132 SecureAuth0 23108 ID52020 [SecureAuth@27389 UserHostAddress="192.168.2.132" Realm="SecureAuth0" UserID="Tester2" PEN="27389"] Found the user for retrieving user's profile`, @@ -167,7 +167,7 @@ func CreateCases(basicConfig func() *SyslogParserConfig) ([]Case, error) { "RFC5424LongSDName", func() *SyslogParserConfig { cfg := basicConfig() - cfg.Protocol = "rfc5424" + cfg.Protocol = RFC5424 return cfg }(), `<86>1 2015-08-05T21:58:59.693Z 192.168.2.132 SecureAuth0 23108 ID52020 [verylongsdnamethatisgreaterthan32bytes@12345 UserHostAddress="192.168.2.132"] my message`, @@ -193,5 +193,4 @@ func CreateCases(basicConfig func() *SyslogParserConfig) ([]Case, error) { } return cases, nil - } diff --git a/operator/builtin/parser/syslog/syslog.go b/operator/builtin/parser/syslog/syslog.go index b05205ca769f..bf71f53761cb 100644 --- a/operator/builtin/parser/syslog/syslog.go +++ b/operator/builtin/parser/syslog/syslog.go @@ -27,6 +27,9 @@ import ( "github.com/open-telemetry/opentelemetry-log-collection/operator/helper" ) +const RFC3164 = "rfc3164" +const RFC5424 = "rfc5424" + func init() { operator.Register("syslog_parser", func() operator.Builder { return NewSyslogParserConfig("") }) } @@ -85,9 +88,9 @@ func (c SyslogParserConfig) Build(context operator.BuildContext) ([]operator.Ope func buildMachine(protocol string, location *time.Location) (sl.Machine, error) { switch protocol { - case "rfc3164": + case RFC3164: return rfc3164.NewMachine(rfc3164.WithLocaleTimezone(location)), nil - case "rfc5424": + case RFC5424: return rfc5424.NewMachine(), nil default: return nil, fmt.Errorf("invalid protocol %s", protocol) diff --git a/operator/builtin/parser/syslog/syslog_test.go b/operator/builtin/parser/syslog/syslog_test.go index ec8db7dc3858..02cd573ae7a0 100644 --- a/operator/builtin/parser/syslog/syslog_test.go +++ b/operator/builtin/parser/syslog/syslog_test.go @@ -68,7 +68,7 @@ func TestSyslogParser(t *testing.T) { func TestSyslogParserConfig(t *testing.T) { expect := NewSyslogParserConfig("test") - expect.Protocol = "rfc3164" + expect.Protocol = RFC3164 expect.ParseFrom = entry.NewRecordField("from") expect.ParseTo = entry.NewRecordField("to") @@ -76,7 +76,7 @@ func TestSyslogParserConfig(t *testing.T) { input := map[string]interface{}{ "id": "test", "type": "syslog_parser", - "protocol": "rfc3164", + "protocol": RFC3164, "parse_from": "$.from", "parse_to": "$.to", "on_error": "send", @@ -92,7 +92,7 @@ func TestSyslogParserConfig(t *testing.T) { type: syslog_parser id: test on_error: "send" -protocol: "rfc3164" +protocol: rfc3164 parse_from: $.from parse_to: $.to` var actual SyslogParserConfig diff --git a/operator/builtin/parser/time/time_test.go b/operator/builtin/parser/time/time_test.go index ae31a5360389..6c946b6b4bcc 100644 --- a/operator/builtin/parser/time/time_test.go +++ b/operator/builtin/parser/time/time_test.go @@ -35,7 +35,6 @@ func TestIsZero(t *testing.T) { } func TestTimeParser(t *testing.T) { - // Mountain Standard Time mst, err := time.LoadLocation("MST") require.NoError(t, err) @@ -166,7 +165,6 @@ func TestTimeParser(t *testing.T) { } func TestTimeEpochs(t *testing.T) { - testCases := []struct { name string sample interface{} @@ -328,7 +326,6 @@ func TestTimeEpochs(t *testing.T) { } func TestTimeErrors(t *testing.T) { - testCases := []struct { name string sample interface{} @@ -400,8 +397,7 @@ func runTimeParseTest(t *testing.T, cfg *TimeParserConfig, ent *entry.Entry, bui return runLossyTimeParseTest(t, cfg, ent, buildErr, parseErr, expected, time.Duration(0)) } -func runLossyTimeParseTest(t *testing.T, cfg *TimeParserConfig, ent *entry.Entry, buildErr bool, parseErr bool, expected time.Time, maxLoss time.Duration) func(*testing.T) { - +func runLossyTimeParseTest(_ *testing.T, cfg *TimeParserConfig, ent *entry.Entry, buildErr bool, parseErr bool, expected time.Time, maxLoss time.Duration) func(*testing.T) { return func(t *testing.T) { buildContext := testutil.NewBuildContext(t) diff --git a/operator/builtin/parser/uri/uri.go b/operator/builtin/parser/uri/uri.go index e7da028cca64..3a438497c613 100644 --- a/operator/builtin/parser/uri/uri.go +++ b/operator/builtin/parser/uri/uri.go @@ -130,21 +130,21 @@ func urlToMap(p *url.URL, m map[string]interface{}) map[string]interface{} { // queryToMap converts a query string url.Values to a map. func queryToMap(query url.Values, m map[string]interface{}) map[string]interface{} { // no-op if query is empty, do not create the key m["query"] - if len(query) <= 0 { + if len(query) == 0 { return m } /* 'parameter' will represent url.Values - map[string]interface{}{ - "parameter-a": []interface{}{ - "a", - "b", - }, - "parameter-b": []interface{}{ - "x", - "y", - }, - } + map[string]interface{}{ + "parameter-a": []interface{}{ + "a", + "b", + }, + "parameter-b": []interface{}{ + "x", + "y", + }, + } */ parameters := map[string]interface{}{} for param, values := range query { @@ -154,7 +154,6 @@ func queryToMap(query url.Values, m map[string]interface{}) map[string]interface return m } - // queryParamValuesToMap takes query string parameter values and // returns an []interface populated with the values func queryParamValuesToMap(values []string) []interface{} { diff --git a/operator/builtin/transformer/noop/noop_test.go b/operator/builtin/transformer/noop/noop_test.go index 6a1f255ad09c..1eb3bd568ff4 100644 --- a/operator/builtin/transformer/noop/noop_test.go +++ b/operator/builtin/transformer/noop/noop_test.go @@ -24,17 +24,6 @@ import ( "github.com/stretchr/testify/require" ) -func NewTestConfig(t *testing.T) (*operator.Config, error) { - json := `{ - "type": "noop", - "id": "test_id", - "output": "test_output" - }` - config := &operator.Config{} - err := config.UnmarshalJSON([]byte(json)) - return config, err -} - func TestBuildValid(t *testing.T) { cfg := NewNoopOperatorConfig("test") ops, err := cfg.Build(testutil.NewBuildContext(t)) diff --git a/operator/builtin/transformer/recombine/recombine.go b/operator/builtin/transformer/recombine/recombine.go index 36579066c05e..c2f5bfdd1d06 100644 --- a/operator/builtin/transformer/recombine/recombine.go +++ b/operator/builtin/transformer/recombine/recombine.go @@ -194,7 +194,7 @@ func (r *RecombineOperator) matchIndicatesLast() bool { } // addToBatch adds the current entry to the current batch of entries that will be combined -func (r *RecombineOperator) addToBatch(ctx context.Context, e *entry.Entry) { +func (r *RecombineOperator) addToBatch(_ context.Context, e *entry.Entry) { if len(r.batch) >= r.maxBatchSize { r.Error("Batch size exceeds max batch size. Flushing logs that have not been recombined") r.flushUncombined(context.Background()) diff --git a/operator/builtin/transformer/restructure/restructure_test.go b/operator/builtin/transformer/restructure/restructure_test.go index 8cf719427160..4ac414f4baff 100644 --- a/operator/builtin/transformer/restructure/restructure_test.go +++ b/operator/builtin/transformer/restructure/restructure_test.go @@ -28,27 +28,9 @@ import ( "github.com/open-telemetry/opentelemetry-log-collection/operator/helper" "github.com/open-telemetry/opentelemetry-log-collection/testutil" "github.com/stretchr/testify/require" - "go.uber.org/zap" yaml "gopkg.in/yaml.v2" ) -func NewFakeRestructureOperator() (*RestructureOperator, *testutil.Operator) { - mock := testutil.Operator{} - logger, _ := zap.NewProduction() - return &RestructureOperator{ - TransformerOperator: helper.TransformerOperator{ - WriterOperator: helper.WriterOperator{ - BasicOperator: helper.BasicOperator{ - OperatorID: "test", - OperatorType: "restructure", - SugaredLogger: logger.Sugar(), - }, - OutputOperators: []operator.Operator{&mock}, - }, - }, - }, &mock -} - func TestRestructureOperator(t *testing.T) { os.Setenv("TEST_RESTRUCTURE_PLUGIN_ENV", "foo") defer os.Unsetenv("TEST_RESTRUCTURE_PLUGIN_ENV") @@ -360,7 +342,7 @@ ops: }] }` - expected := operator.Config(operator.Config{ + expected := operator.Config{ Builder: &RestructureOperatorConfig{ TransformerConfig: helper.TransformerConfig{ WriterConfig: helper.WriterConfig{ @@ -408,7 +390,7 @@ ops: }}, }, }, - }) + } var unmarshalledYAML operator.Config err := yaml.UnmarshalStrict([]byte(configYAML), &unmarshalledYAML) diff --git a/operator/builtin/transformer/router/router_test.go b/operator/builtin/transformer/router/router_test.go index 3b98a6fe8530..9f3740cbaec8 100644 --- a/operator/builtin/transformer/router/router_test.go +++ b/operator/builtin/transformer/router/router_test.go @@ -205,7 +205,7 @@ func TestRouterOperator(t *testing.T) { mock1 := testutil.NewMockOperator("$.output1") mock1.On("Process", mock.Anything, mock.Anything).Return(nil).Run(func(args mock.Arguments) { - results["output1"] = results["output1"] + 1 + results["output1"]++ if entry, ok := args[1].(*entry.Entry); ok { attributes = entry.Attributes } @@ -213,7 +213,7 @@ func TestRouterOperator(t *testing.T) { mock2 := testutil.NewMockOperator("$.output2") mock2.On("Process", mock.Anything, mock.Anything).Return(nil).Run(func(args mock.Arguments) { - results["output2"] = results["output2"] + 1 + results["output2"]++ if entry, ok := args[1].(*entry.Entry); ok { attributes = entry.Attributes }