chore: Don't use all default exclude patterns for golangci-lint (#12969)

Co-authored-by: Pawel Zak <Pawel Zak>
This commit is contained in:
Paweł Żak 2023-03-29 09:50:00 +02:00 committed by GitHub
parent 0129abbd1e
commit 9608d118bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 76 additions and 55 deletions

View File

@ -201,9 +201,25 @@ issues:
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3. # Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0 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: 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: exclude-rules:
- path: plugins/parsers/influx - path: plugins/parsers/influx
linters: linters:
@ -215,6 +231,12 @@ issues:
- path: cmd/telegraf/(main|printer).go - path: cmd/telegraf/(main|printer).go
text: "unhandled-error: Unhandled error in call to function outputBuffer.Write" 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 configuration options
output: output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions # Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions

View File

@ -767,7 +767,6 @@ func (a *Agent) push(
select { select {
case <-time.After(until): case <-time.After(until):
aggregator.Push(acc) aggregator.Push(acc)
break
case <-ctx.Done(): case <-ctx.Done():
aggregator.Push(acc) aggregator.Push(acc)
return return

View File

@ -179,7 +179,7 @@ func (c *CiscoTelemetryMDT) Start(acc telegraf.Accumulator) error {
var opts []grpc.ServerOption var opts []grpc.ServerOption
tlsConfig, err := c.ServerConfig.TLSConfig() tlsConfig, err := c.ServerConfig.TLSConfig()
if err != nil { if err != nil {
c.listener.Close() //nolint:revive // we cannot do anything if the closing fails c.listener.Close()
return err return err
} else if tlsConfig != nil { } else if tlsConfig != nil {
opts = append(opts, grpc.Creds(credentials.NewTLS(tlsConfig))) opts = append(opts, grpc.Creds(credentials.NewTLS(tlsConfig)))
@ -210,7 +210,7 @@ func (c *CiscoTelemetryMDT) Start(acc telegraf.Accumulator) error {
}() }()
default: 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) return fmt.Errorf("invalid Cisco MDT transport: %s", c.Transport)
} }
@ -731,7 +731,7 @@ func (c *CiscoTelemetryMDT) Stop() {
c.grpcServer.Stop() c.grpcServer.Stop()
} }
if c.listener != nil { if c.listener != nil {
c.listener.Close() //nolint:revive // we cannot do anything if the closing fails c.listener.Close()
} }
c.wg.Wait() c.wg.Wait()
} }

View File

@ -392,7 +392,7 @@ func (cms *CloudWatchMetricStreams) authenticateIfSet(handler http.HandlerFunc,
// Stop cleans up all resources // Stop cleans up all resources
func (cms *CloudWatchMetricStreams) Stop() { func (cms *CloudWatchMetricStreams) Stop() {
if cms.listener != nil { 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() cms.wg.Wait()
} }

View File

@ -292,7 +292,7 @@ func (c *ClusterClient) doGet(ctx context.Context, address string, v interface{}
return err return err
} }
defer func() { defer func() {
resp.Body.Close() //nolint:revive // we cannot do anything if the closing fails resp.Body.Close()
<-c.semaphore <-c.semaphore
}() }()

View File

@ -37,7 +37,7 @@ func setupNullDisk(t *testing.T, s *DiskIO, devName string) func() {
cleanFunc := func() { cleanFunc := func() {
ic.udevDataPath = origUdevPath 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() ic.udevDataPath = td.Name()

View File

@ -137,7 +137,7 @@ func (h *HTTPListenerV2) createHTTPServer() *http.Server {
// Stop cleans up all resources // Stop cleans up all resources
func (h *HTTPListenerV2) Stop() { func (h *HTTPListenerV2) Stop() {
if h.listener != nil { 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() h.wg.Wait()
} }

View File

@ -69,7 +69,7 @@ func (c *client) doGet(ctx context.Context, url string, v interface{}) error {
return err return err
} }
defer func() { defer func() {
resp.Body.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway resp.Body.Close()
<-c.semaphore <-c.semaphore
}() }()
// Clear invalid token if unauthorized // Clear invalid token if unauthorized

View File

@ -514,7 +514,7 @@ func (m *Mesos) gatherMainMetrics(u *url.URL, role Role, acc telegraf.Accumulato
} }
data, err := io.ReadAll(resp.Body) 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 { if err != nil {
return err return err
} }

View File

@ -220,8 +220,8 @@ func (n *mockNSQD) handle(conn net.Conn) {
} }
exit: exit:
n.tcpListener.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway n.tcpListener.Close()
conn.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway conn.Close()
} }
func framedResponse(frameType int32, data []byte) ([]byte, error) { func framedResponse(frameType int32, data []byte) ([]byte, error) {

View File

@ -34,7 +34,7 @@ func fakePassengerStatus(stat string) (string, error) {
} }
func teardown(tempFilePath string) { 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) { func Test_Invalid_Passenger_Status_Cli(t *testing.T) {

View File

@ -276,7 +276,7 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) {
httpReq.Body = body httpReq.Body = body
c.handler.ServeHTTP(r, httpReq) 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() c.mu.Lock()
delete(c.requests, req.reqID) delete(c.requests, req.reqID)
c.mu.Unlock() c.mu.Unlock()
@ -292,10 +292,10 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) {
// can properly cut off the client sending all the data. // can properly cut off the client sending all the data.
// For now just bound it a little and // 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 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 { if !req.keepConn {
c.conn.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway c.conn.Close()
} }
} }
@ -306,7 +306,7 @@ func (c *child) cleanUp() {
if req.pw != nil { if req.pw != nil {
// race with call to Close in c.serveRequest doesn't matter because // race with call to Close in c.serveRequest doesn't matter because
// Pipe(Reader|Writer).Close are idempotent // 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)
} }
} }
} }

View File

@ -229,7 +229,7 @@ type bufWriter struct {
func (w *bufWriter) Close() error { func (w *bufWriter) Close() error {
if err := w.Writer.Flush(); err != nil { 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 err
} }
return w.closer.Close() return w.closer.Close()

View File

@ -143,7 +143,7 @@ func (p *Service) Start(telegraf.Accumulator) (err error) {
// Stop stops the services and closes any necessary channels and connections // Stop stops the services and closes any necessary channels and connections
func (p *Service) Stop() { 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+ ?`) var kvMatcher, _ = regexp.Compile(`(password|sslcert|sslkey|sslmode|sslrootcert)=\S+ ?`)

View File

@ -29,7 +29,7 @@ func (s statServer) serverSocket(l net.Listener) {
data := buf[:n] data := buf[:n]
if string(data) == "show * \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.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) }(conn)
} }

View File

@ -112,8 +112,8 @@ func TestV1PowerdnsRecursorGeneratesMetrics(t *testing.T) {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer func() { defer func() {
socket.Close() //nolint:revive // ignore the returned error as we need to remove the socket file anyway socket.Close()
os.Remove(controlSocket) //nolint:revive // ignore the returned error as we want to remove the file and ignore no-such-file errors os.Remove(controlSocket)
wg.Done() wg.Done()
}() }()
@ -121,14 +121,14 @@ func TestV1PowerdnsRecursorGeneratesMetrics(t *testing.T) {
buf := make([]byte, 1024) buf := make([]byte, 1024)
n, remote, err := socket.ReadFromUnix(buf) n, remote, err := socket.ReadFromUnix(buf)
if err != nil { if err != nil {
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway socket.Close()
return return
} }
data := buf[:n] data := buf[:n]
if string(data) == "get-all\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.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) time.Sleep(100 * time.Millisecond)
@ -167,8 +167,8 @@ func TestV2PowerdnsRecursorGeneratesMetrics(t *testing.T) {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer func() { defer func() {
socket.Close() //nolint:revive // ignore the returned error as we need to remove the socket file anyway socket.Close()
os.Remove(controlSocket) //nolint:revive // ignore the returned error as we want to remove the file and ignore no-such-file errors os.Remove(controlSocket)
wg.Done() wg.Done()
}() }()
@ -176,14 +176,14 @@ func TestV2PowerdnsRecursorGeneratesMetrics(t *testing.T) {
status := make([]byte, 4) status := make([]byte, 4)
n, _, err := socket.ReadFromUnix(status) n, _, err := socket.ReadFromUnix(status)
if err != nil || n != 4 { if err != nil || n != 4 {
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway socket.Close()
return return
} }
buf := make([]byte, 1024) buf := make([]byte, 1024)
n, remote, err := socket.ReadFromUnix(buf) n, remote, err := socket.ReadFromUnix(buf)
if err != nil { if err != nil {
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway socket.Close()
return return
} }
@ -191,7 +191,7 @@ func TestV2PowerdnsRecursorGeneratesMetrics(t *testing.T) {
if string(data) == "get-all" { 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{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.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) time.Sleep(100 * time.Millisecond)
@ -229,8 +229,8 @@ func TestV3PowerdnsRecursorGeneratesMetrics(t *testing.T) {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer func() { defer func() {
socket.Close() //nolint:revive // ignore the returned error as we need to remove the socket file anyway socket.Close()
os.Remove(controlSocket) //nolint:revive // ignore the returned error as we want to remove the file and ignore no-such-file errors os.Remove(controlSocket)
wg.Done() wg.Done()
}() }()
@ -262,7 +262,7 @@ func TestV3PowerdnsRecursorGeneratesMetrics(t *testing.T) {
metrics := []byte(metrics) metrics := []byte(metrics)
writeNativeUIntToConn(conn, uint(len(metrics))) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway 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 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) time.Sleep(100 * time.Millisecond)

View File

@ -90,7 +90,7 @@ func (s *SFlow) Gather(_ telegraf.Accumulator) error {
func (s *SFlow) Stop() { func (s *SFlow) Stop() {
if s.closer != nil { 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() s.wg.Wait()
} }

View File

@ -868,7 +868,7 @@ func (s *Statsd) handler(conn *net.TCPConn, id string) {
// connection cleanup function // connection cleanup function
defer func() { defer func() {
s.wg.Done() 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 // Add one connection potential back to channel when this one closes
s.accept <- true s.accept <- true
@ -920,7 +920,7 @@ func (s *Statsd) handler(conn *net.TCPConn, id string) {
// refuser refuses a TCP connection // refuser refuses a TCP connection
func (s *Statsd) refuser(conn *net.TCPConn) { 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.Infof("Refused TCP Connection from %s", conn.RemoteAddr())
s.Log.Warn("Maximum TCP Connections reached, you may want to adjust max_tcp_connections") s.Log.Warn("Maximum TCP Connections reached, you may want to adjust max_tcp_connections")
} }
@ -945,11 +945,11 @@ func (s *Statsd) Stop() {
close(s.done) close(s.done)
if s.isUDP() { if s.isUDP() {
if s.UDPlistener != nil { 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 { } else {
if s.TCPlistener != nil { 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 // Close all open TCP connections
@ -963,7 +963,7 @@ func (s *Statsd) Stop() {
} }
s.cleanup.Unlock() s.cleanup.Unlock()
for _, conn := range conns { for _, conn := range conns {
conn.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway conn.Close()
} }
} }
s.Unlock() s.Unlock()

View File

@ -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 // Stop causes the plugin to cease collecting JSON data from the socket provided
// to Suricata. // to Suricata.
func (s *Suricata) Stop() { 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 { if s.cancel != nil {
s.cancel() s.cancel()
} }

View File

@ -58,7 +58,7 @@ func TestSynproxyFileInvalidHex(t *testing.T) {
func TestNoSynproxyFile(t *testing.T) { func TestNoSynproxyFile(t *testing.T) {
tmpfile := makeFakeSynproxyFile([]byte(synproxyFileNormal)) tmpfile := makeFakeSynproxyFile([]byte(synproxyFileNormal))
// Remove file to generate "no such file" error // 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{ k := Synproxy{
statFile: tmpfile, statFile: tmpfile,

View File

@ -97,7 +97,7 @@ func (s *Syslog) Start(acc telegraf.Accumulator) error {
} }
if scheme == "unix" || scheme == "unixpacket" || scheme == "unixgram" { 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 { if s.isStream {
@ -139,7 +139,7 @@ func (s *Syslog) Stop() {
defer s.mu.Unlock() defer s.mu.Unlock()
if s.Closer != nil { 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() s.wg.Wait()
} }
@ -265,7 +265,7 @@ func (s *Syslog) removeConnection(c net.Conn) {
func (s *Syslog) handle(conn net.Conn, acc telegraf.Accumulator) { func (s *Syslog) handle(conn net.Conn, acc telegraf.Accumulator) {
defer func() { defer func() {
s.removeConnection(conn) 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 var p syslog.Parser
@ -416,7 +416,7 @@ type unixCloser struct {
func (uc unixCloser) Close() error { func (uc unixCloser) Close() error {
err := uc.closer.Close() 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 return err
} }

View File

@ -106,7 +106,7 @@ func formatUptime(uptime uint64) string {
minutes %= 60 minutes %= 60
fmt.Fprintf(w, "%2d:%02d", hours, minutes) fmt.Fprintf(w, "%2d:%02d", hours, minutes)
w.Flush() //nolint:revive // This will always succeed, so skip checking the error w.Flush()
return buf.String() return buf.String()
} }

View File

@ -128,7 +128,7 @@ func (t *TCPListener) Stop() {
defer t.Unlock() defer t.Unlock()
close(t.done) close(t.done)
t.listener.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway t.listener.Close()
// Close all open TCP connections // Close all open TCP connections
// - get all conns from the t.conns map and put into slice // - get all conns from the t.conns map and put into slice
@ -141,7 +141,7 @@ func (t *TCPListener) Stop() {
} }
t.cleanup.Unlock() t.cleanup.Unlock()
for _, conn := range conns { for _, conn := range conns {
conn.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway conn.Close()
} }
t.wg.Wait() t.wg.Wait()
@ -194,7 +194,7 @@ func (t *TCPListener) refuser(conn *net.TCPConn) {
" reached, closing.\nYou may want to increase max_tcp_connections in"+ " reached, closing.\nYou may want to increase max_tcp_connections in"+
" the Telegraf tcp listener configuration.\n", t.MaxTCPConnections) " the Telegraf tcp listener configuration.\n", t.MaxTCPConnections)
conn.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway conn.Close()
t.Log.Infof("Refused TCP Connection from %s", conn.RemoteAddr()) t.Log.Infof("Refused TCP Connection from %s", conn.RemoteAddr())
t.Log.Warn("Maximum TCP Connections reached, you may want to adjust max_tcp_connections") t.Log.Warn("Maximum TCP Connections reached, you may want to adjust max_tcp_connections")
} }

View File

@ -121,7 +121,7 @@ func (u *UDPListener) Stop() {
defer u.Unlock() defer u.Unlock()
close(u.done) close(u.done)
u.wg.Wait() u.wg.Wait()
u.listener.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway u.listener.Close()
close(u.in) close(u.in)
u.Log.Infof("Stopped service on %q", u.ServiceAddress) u.Log.Infof("Stopped service on %q", u.ServiceAddress)
} }

View File

@ -109,6 +109,6 @@ func (wb *Webhooks) Start(acc telegraf.Accumulator) error {
} }
func (wb *Webhooks) Stop() { func (wb *Webhooks) Stop() {
wb.srv.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway wb.srv.Close()
wb.Log.Infof("Stopping the Webhooks service") wb.Log.Infof("Stopping the Webhooks service")
} }

View File

@ -82,7 +82,7 @@ func (r *Riemann) Write(metrics []telegraf.Metric) error {
} }
if err := r.client.SendMulti(events); err != nil { if err := r.client.SendMulti(events); err != nil {
r.Close() //nolint:revive // There is another error which will be returned here r.Close()
return fmt.Errorf("failed to send riemann message: %w", err) return fmt.Errorf("failed to send riemann message: %w", err)
} }
return nil return nil

View File

@ -76,7 +76,7 @@ func (r *Riemann) Write(metrics []telegraf.Metric) error {
var senderr = r.client.SendMulti(events) var senderr = r.client.SendMulti(events)
if senderr != nil { if senderr != nil {
r.Close() //nolint:revive // There is another error which will be returned here r.Close()
return fmt.Errorf("failed to send riemann message (will try to reconnect): %w", senderr) return fmt.Errorf("failed to send riemann message (will try to reconnect): %w", senderr)
} }

View File

@ -123,7 +123,7 @@ func (sw *SocketWriter) Write(metrics []telegraf.Metric) error {
var netErr net.Error var netErr net.Error
if errors.As(err, &netErr) { if errors.As(err, &netErr) {
// permanent error. close the connection // permanent error. close the connection
sw.Close() //nolint:revive // There is another error which will be returned here sw.Close()
sw.Conn = nil sw.Conn = nil
return fmt.Errorf("closing connection: %w", netErr) return fmt.Errorf("closing connection: %w", netErr)
} }

View File

@ -123,7 +123,7 @@ func (s *Syslog) Write(metrics []telegraf.Metric) (err error) {
if _, err = s.Conn.Write(msgBytesWithFraming); err != nil { if _, err = s.Conn.Write(msgBytesWithFraming); err != nil {
var netErr net.Error var netErr net.Error
if errors.As(err, &netErr) { if errors.As(err, &netErr) {
s.Close() //nolint:revive // There is another error which will be returned here s.Close()
s.Conn = nil s.Conn = nil
return fmt.Errorf("closing connection: %w", netErr) return fmt.Errorf("closing connection: %w", netErr)
} }