Skip to content

Commit

Permalink
chore: Don't use all default exclude patterns for golangci-lint (infl…
Browse files Browse the repository at this point in the history
…uxdata#12969)

Co-authored-by: Pawel Zak <Pawel Zak>
  • Loading branch information
zak-pawel authored Mar 29, 2023
1 parent 0129abb commit 9608d11
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 55 deletions.
24 changes: 23 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,25 @@ issues:
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

# List of regexps of issue texts to exclude.
#
# But independently of this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`.
# To list all excluded by default patterns execute `golangci-lint run --help`
#
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
exclude:
- don't use an underscore in package name #revive:var-naming
# revive:var-naming
- don't use an underscore in package name
# EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
- Unhandled error in call to function ((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv)
# EXC0013 revive: Annoying issue about not having a comment. The rare codebase has such comments
- package comment should be of the form "(.+)...
# EXC0015 revive: Annoying issue about not having a comment. The rare codebase has such comments
- should have a package comment

# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: plugins/parsers/influx
linters:
Expand All @@ -215,6 +231,12 @@ issues:
- path: cmd/telegraf/(main|printer).go
text: "unhandled-error: Unhandled error in call to function outputBuffer.Write"

# Independently of option `exclude` we use default exclude patterns,
# it can be disabled by this option.
# To list all excluded by default patterns execute `golangci-lint run --help`.
# Default: true.
exclude-use-default: false

# output configuration options
output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
Expand Down
1 change: 0 additions & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,6 @@ func (a *Agent) push(
select {
case <-time.After(until):
aggregator.Push(acc)
break
case <-ctx.Done():
aggregator.Push(acc)
return
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (c *CiscoTelemetryMDT) Start(acc telegraf.Accumulator) error {
var opts []grpc.ServerOption
tlsConfig, err := c.ServerConfig.TLSConfig()
if err != nil {
c.listener.Close() //nolint:revive // we cannot do anything if the closing fails
c.listener.Close()
return err
} else if tlsConfig != nil {
opts = append(opts, grpc.Creds(credentials.NewTLS(tlsConfig)))
Expand Down Expand Up @@ -210,7 +210,7 @@ func (c *CiscoTelemetryMDT) Start(acc telegraf.Accumulator) error {
}()

default:
c.listener.Close() //nolint:revive // we cannot do anything if the closing fails
c.listener.Close()
return fmt.Errorf("invalid Cisco MDT transport: %s", c.Transport)
}

Expand Down Expand Up @@ -731,7 +731,7 @@ func (c *CiscoTelemetryMDT) Stop() {
c.grpcServer.Stop()
}
if c.listener != nil {
c.listener.Close() //nolint:revive // we cannot do anything if the closing fails
c.listener.Close()
}
c.wg.Wait()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func (cms *CloudWatchMetricStreams) authenticateIfSet(handler http.HandlerFunc,
// Stop cleans up all resources
func (cms *CloudWatchMetricStreams) Stop() {
if cms.listener != nil {
cms.listener.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
cms.listener.Close()
}
cms.wg.Wait()
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/dcos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (c *ClusterClient) doGet(ctx context.Context, address string, v interface{}
return err
}
defer func() {
resp.Body.Close() //nolint:revive // we cannot do anything if the closing fails
resp.Body.Close()
<-c.semaphore
}()

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/diskio/diskio_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func setupNullDisk(t *testing.T, s *DiskIO, devName string) func() {

cleanFunc := func() {
ic.udevDataPath = origUdevPath
os.Remove(td.Name()) //nolint:revive // we cannot do anything if file cannot be removed
os.Remove(td.Name())
}

ic.udevDataPath = td.Name()
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/http_listener_v2/http_listener_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (h *HTTPListenerV2) createHTTPServer() *http.Server {
// Stop cleans up all resources
func (h *HTTPListenerV2) Stop() {
if h.listener != nil {
h.listener.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
h.listener.Close()
}
h.wg.Wait()
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/jenkins/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *client) doGet(ctx context.Context, url string, v interface{}) error {
return err
}
defer func() {
resp.Body.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
resp.Body.Close()
<-c.semaphore
}()
// Clear invalid token if unauthorized
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/mesos/mesos.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ func (m *Mesos) gatherMainMetrics(u *url.URL, role Role, acc telegraf.Accumulato
}

data, err := io.ReadAll(resp.Body)
resp.Body.Close() //nolint:revive // ignore the returned error to not shadow the initial one
resp.Body.Close()
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/nsq_consumer/nsq_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ func (n *mockNSQD) handle(conn net.Conn) {
}

exit:
n.tcpListener.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
conn.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
n.tcpListener.Close()
conn.Close()
}

func framedResponse(frameType int32, data []byte) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/passenger/passenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func fakePassengerStatus(stat string) (string, error) {
}

func teardown(tempFilePath string) {
os.Remove(tempFilePath) //nolint:revive // ignore the returned error as we want to remove the file and ignore missing file errors
os.Remove(tempFilePath)
}

func Test_Invalid_Passenger_Status_Cli(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/phpfpm/child.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) {
httpReq.Body = body
c.handler.ServeHTTP(r, httpReq)
}
r.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
r.Close()
c.mu.Lock()
delete(c.requests, req.reqID)
c.mu.Unlock()
Expand All @@ -292,10 +292,10 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) {
// can properly cut off the client sending all the data.
// For now just bound it a little and
io.CopyN(io.Discard, body, 100<<20) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
body.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
body.Close()

if !req.keepConn {
c.conn.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
c.conn.Close()
}
}

Expand All @@ -306,7 +306,7 @@ func (c *child) cleanUp() {
if req.pw != nil {
// race with call to Close in c.serveRequest doesn't matter because
// Pipe(Reader|Writer).Close are idempotent
req.pw.CloseWithError(ErrConnClosed) //nolint:revive // Ignore the returned error as we continue in the loop anyway
req.pw.CloseWithError(ErrConnClosed)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/phpfpm/fcgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ type bufWriter struct {

func (w *bufWriter) Close() error {
if err := w.Writer.Flush(); err != nil {
w.closer.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
w.closer.Close()
return err
}
return w.closer.Close()
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/postgresql/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (p *Service) Start(telegraf.Accumulator) (err error) {

// Stop stops the services and closes any necessary channels and connections
func (p *Service) Stop() {
p.DB.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
p.DB.Close()
}

var kvMatcher, _ = regexp.Compile(`(password|sslcert|sslkey|sslmode|sslrootcert)=\S+ ?`)
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/powerdns/powerdns_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s statServer) serverSocket(l net.Listener) {
data := buf[:n]
if string(data) == "show * \n" {
c.Write([]byte(metrics)) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
c.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
c.Close()
}
}(conn)
}
Expand Down
24 changes: 12 additions & 12 deletions plugins/inputs/powerdns_recursor/powerdns_recursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ func TestV1PowerdnsRecursorGeneratesMetrics(t *testing.T) {
wg.Add(1)
go func() {
defer func() {
socket.Close() //nolint:revive // ignore the returned error as we need to remove the socket file anyway
os.Remove(controlSocket) //nolint:revive // ignore the returned error as we want to remove the file and ignore no-such-file errors
socket.Close()
os.Remove(controlSocket)
wg.Done()
}()

for {
buf := make([]byte, 1024)
n, remote, err := socket.ReadFromUnix(buf)
if err != nil {
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
socket.Close()
return
}

data := buf[:n]
if string(data) == "get-all\n" {
socket.WriteToUnix([]byte(metrics), remote) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
socket.Close()
}

time.Sleep(100 * time.Millisecond)
Expand Down Expand Up @@ -167,31 +167,31 @@ func TestV2PowerdnsRecursorGeneratesMetrics(t *testing.T) {
wg.Add(1)
go func() {
defer func() {
socket.Close() //nolint:revive // ignore the returned error as we need to remove the socket file anyway
os.Remove(controlSocket) //nolint:revive // ignore the returned error as we want to remove the file and ignore no-such-file errors
socket.Close()
os.Remove(controlSocket)
wg.Done()
}()

for {
status := make([]byte, 4)
n, _, err := socket.ReadFromUnix(status)
if err != nil || n != 4 {
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
socket.Close()
return
}

buf := make([]byte, 1024)
n, remote, err := socket.ReadFromUnix(buf)
if err != nil {
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
socket.Close()
return
}

data := buf[:n]
if string(data) == "get-all" {
socket.WriteToUnix([]byte{0, 0, 0, 0}, remote) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
socket.WriteToUnix([]byte(metrics), remote) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
socket.Close()
}

time.Sleep(100 * time.Millisecond)
Expand Down Expand Up @@ -229,8 +229,8 @@ func TestV3PowerdnsRecursorGeneratesMetrics(t *testing.T) {
wg.Add(1)
go func() {
defer func() {
socket.Close() //nolint:revive // ignore the returned error as we need to remove the socket file anyway
os.Remove(controlSocket) //nolint:revive // ignore the returned error as we want to remove the file and ignore no-such-file errors
socket.Close()
os.Remove(controlSocket)
wg.Done()
}()

Expand Down Expand Up @@ -262,7 +262,7 @@ func TestV3PowerdnsRecursorGeneratesMetrics(t *testing.T) {
metrics := []byte(metrics)
writeNativeUIntToConn(conn, uint(len(metrics))) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
conn.Write(metrics) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
socket.Close()
}

time.Sleep(100 * time.Millisecond)
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/sflow/sflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *SFlow) Gather(_ telegraf.Accumulator) error {

func (s *SFlow) Stop() {
if s.closer != nil {
s.closer.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
s.closer.Close()
}
s.wg.Wait()
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ func (s *Statsd) handler(conn *net.TCPConn, id string) {
// connection cleanup function
defer func() {
s.wg.Done()
conn.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
conn.Close()

// Add one connection potential back to channel when this one closes
s.accept <- true
Expand Down Expand Up @@ -920,7 +920,7 @@ func (s *Statsd) handler(conn *net.TCPConn, id string) {

// refuser refuses a TCP connection
func (s *Statsd) refuser(conn *net.TCPConn) {
conn.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
conn.Close()
s.Log.Infof("Refused TCP Connection from %s", conn.RemoteAddr())
s.Log.Warn("Maximum TCP Connections reached, you may want to adjust max_tcp_connections")
}
Expand All @@ -945,11 +945,11 @@ func (s *Statsd) Stop() {
close(s.done)
if s.isUDP() {
if s.UDPlistener != nil {
s.UDPlistener.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
s.UDPlistener.Close()
}
} else {
if s.TCPlistener != nil {
s.TCPlistener.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
s.TCPlistener.Close()
}

// Close all open TCP connections
Expand All @@ -963,7 +963,7 @@ func (s *Statsd) Stop() {
}
s.cleanup.Unlock()
for _, conn := range conns {
conn.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
conn.Close()
}
}
s.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/suricata/suricata.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *Suricata) Start(acc telegraf.Accumulator) error {
// Stop causes the plugin to cease collecting JSON data from the socket provided
// to Suricata.
func (s *Suricata) Stop() {
s.inputListener.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
s.inputListener.Close()
if s.cancel != nil {
s.cancel()
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/synproxy/synproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestSynproxyFileInvalidHex(t *testing.T) {
func TestNoSynproxyFile(t *testing.T) {
tmpfile := makeFakeSynproxyFile([]byte(synproxyFileNormal))
// Remove file to generate "no such file" error
os.Remove(tmpfile) //nolint:revive // Ignore errors if file does not yet exist
os.Remove(tmpfile)

k := Synproxy{
statFile: tmpfile,
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *Syslog) Start(acc telegraf.Accumulator) error {
}

if scheme == "unix" || scheme == "unixpacket" || scheme == "unixgram" {
os.Remove(s.Address) //nolint:revive // Accept success and failure in case the file does not exist
os.Remove(s.Address)
}

if s.isStream {
Expand Down Expand Up @@ -139,7 +139,7 @@ func (s *Syslog) Stop() {
defer s.mu.Unlock()

if s.Closer != nil {
s.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
s.Close()
}
s.wg.Wait()
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func (s *Syslog) removeConnection(c net.Conn) {
func (s *Syslog) handle(conn net.Conn, acc telegraf.Accumulator) {
defer func() {
s.removeConnection(conn)
conn.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
conn.Close()
}()

var p syslog.Parser
Expand Down Expand Up @@ -416,7 +416,7 @@ type unixCloser struct {

func (uc unixCloser) Close() error {
err := uc.closer.Close()
os.Remove(uc.path) //nolint:revive // Accept success and failure in case the file does not exist
os.Remove(uc.path)
return err
}

Expand Down
Loading

0 comments on commit 9608d11

Please sign in to comment.