Skip to content

Commit

Permalink
chore: fix linter findings for nolintlint part 1 (influxdata#12427)
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel authored Jan 25, 2023
1 parent bd77a42 commit d9d9cd4
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 77 deletions.
4 changes: 1 addition & 3 deletions internal/snmp/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func GetIndex(mibPrefix string, node gosmi.SmiNode) (col []string, tagOids map[s

// mimcks grabbing INDEX {} that is returned from snmptranslate -Td MibName
for _, index := range node.GetIndex() {
//nolint:staticcheck //assaignment to nil map to keep backwards compatibilty
tagOids[mibPrefix+index.Name] = struct{}{}
}

Expand Down Expand Up @@ -247,8 +246,7 @@ func SnmpTranslateCall(oid string) (mibName string, oidNum string, oidText strin
out, err = gosmi.GetNodeByOID(types.OidMustFromString(oid))
oidNum = oid
// ensure modules are loaded or node will be empty (might not error)
// do not return the err as the oid is numeric and telegraf can continue
//nolint:nilerr
//nolint:nilerr // do not return the err as the oid is numeric and telegraf can continue
if err != nil || out.Name == "iso" {
return oid, oid, oid, oid, out, nil
}
Expand Down
3 changes: 2 additions & 1 deletion metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type Field struct {
// Metric is the type of data that is processed by Telegraf. Input plugins,
// and to a lesser degree, Processor and Aggregator plugins create new Metrics
// and Output plugins write them.
// nolint:interfacebloat // conditionally allow to contain more methods
//
//nolint:interfacebloat // conditionally allow to contain more methods
type Metric interface {
// Name is the primary identifier for the Metric and corresponds to the
// measurement in the InfluxDB data model.
Expand Down
1 change: 0 additions & 1 deletion plugins/common/opcua/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ func (o *OpcUAClient) Disconnect(ctx context.Context) error {
case "opc.tcp":
o.State = Disconnected
// We can't do anything about failing to close a connection
//nolint:errcheck,revive
err := o.Client.CloseWithContext(ctx)
o.Client = nil
return err
Expand Down
16 changes: 4 additions & 12 deletions plugins/common/opcua/input/input_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,11 @@ func newMP(n *NodeMetricMapping) metricParts {
var sb strings.Builder
for i, key := range keys {
if i != 0 {
// Writes to a string-builder will always succeed
//nolint:errcheck,revive
sb.WriteString(", ")
sb.WriteString(", ") //nolint:revive // writes to a string-builder will always succeed
}
// Writes to a string-builder will always succeed
//nolint:errcheck,revive
sb.WriteString(key)
// Writes to a string-builder will always succeed
//nolint:errcheck,revive
sb.WriteString("=")
// Writes to a string-builder will always succeed
//nolint:errcheck,revive
sb.WriteString(n.MetricTags[key])
sb.WriteString(key) //nolint:revive // writes to a string-builder will always succeed
sb.WriteString("=") //nolint:revive // writes to a string-builder will always succeed
sb.WriteString(n.MetricTags[key]) //nolint:revive // writes to a string-builder will always succeed
}
x := metricParts{
metricName: n.metricName,
Expand Down
8 changes: 2 additions & 6 deletions plugins/inputs/burrow/burrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func getHTTPServer() *httptest.Server {
body, code := getResponseJSON(r.RequestURI)
w.WriteHeader(code)
w.Header().Set("Content-Type", "application/json")
// Ignore the returned error as the test will fail anyway
//nolint:errcheck,revive
w.Write(body)
w.Write(body) //nolint:errcheck,revive // ignore the returned error as the test will fail anyway
}))
}

Expand All @@ -63,9 +61,7 @@ func getHTTPServerBasicAuth() *httptest.Server {
body, code := getResponseJSON(r.RequestURI)
w.WriteHeader(code)
w.Header().Set("Content-Type", "application/json")
// Ignore the returned error as the test will fail anyway
//nolint:errcheck,revive
w.Write(body)
w.Write(body) //nolint:errcheck,revive // ignore the returned error as the test will fail anyway
}))
}

Expand Down
6 changes: 2 additions & 4 deletions plugins/inputs/ceph/ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,9 @@ func (m *metric) name() string {
buf := bytes.Buffer{}
for i := len(m.pathStack) - 1; i >= 0; i-- {
if buf.Len() > 0 {
//nolint:errcheck,revive // should never return an error
buf.WriteString(".")
buf.WriteString(".") //nolint:revive // should never return an error
}
//nolint:errcheck,revive // should never return an error
buf.WriteString(m.pathStack[i])
buf.WriteString(m.pathStack[i]) //nolint:revive // should never return an error
}
return buf.String()
}
Expand Down
10 changes: 3 additions & 7 deletions plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ func (c *CiscoTelemetryMDT) Start(acc telegraf.Accumulator) error {
var opts []grpc.ServerOption
tlsConfig, err := c.ServerConfig.TLSConfig()
if err != nil {
//nolint:errcheck,revive // we cannot do anything if the closing fails
c.listener.Close()
c.listener.Close() //nolint:revive // we cannot do anything if the closing fails
return err
} else if tlsConfig != nil {
opts = append(opts, grpc.Creds(credentials.NewTLS(tlsConfig)))
Expand Down Expand Up @@ -210,8 +209,7 @@ func (c *CiscoTelemetryMDT) Start(acc telegraf.Accumulator) error {
}()

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

Expand Down Expand Up @@ -724,12 +722,10 @@ func (c *CiscoTelemetryMDT) Address() net.Addr {
func (c *CiscoTelemetryMDT) Stop() {
if c.grpcServer != nil {
// Stop server and terminate all running dialout routines
//nolint:errcheck,revive // we cannot do anything if the stopping fails
c.grpcServer.Stop()
}
if c.listener != nil {
//nolint:errcheck,revive // we cannot do anything if the closing fails
c.listener.Close()
c.listener.Close() //nolint:revive // we cannot do anything if the closing fails
}
c.wg.Wait()
}
Expand Down
3 changes: 1 addition & 2 deletions plugins/inputs/cloud_pubsub_push/cloud_pubsub_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ func TestServeHTTP(t *testing.T) {
defer wg.Done()
for m := range d {
ro.AddMetric(m)
//nolint:errcheck,revive // test will fail anyway if the write fails
ro.Write()
ro.Write() //nolint:errcheck // test will fail anyway if the write fails
}
}(dst)

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

Expand Down
5 changes: 1 addition & 4 deletions plugins/inputs/directory_monitor/directory_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ func (monitor *DirectoryMonitor) Gather(_ telegraf.Accumulator) error {

stat, err := times.Stat(path)
if err != nil {
// Don't stop traversing if there is an eror
return nil //nolint:nilerr
return nil //nolint:nilerr // don't stop traversing if there is an error
}

timeThresholdExceeded := time.Since(stat.AccessTime()) >= time.Duration(monitor.DirectoryDurationThreshold)
Expand All @@ -105,7 +104,6 @@ func (monitor *DirectoryMonitor) Gather(_ telegraf.Accumulator) error {
})
// We've been cancelled via Stop().
if err == io.EOF {
//nolint:nilerr // context cancelation is not an error
return nil
}
if err != nil {
Expand All @@ -126,7 +124,6 @@ func (monitor *DirectoryMonitor) Gather(_ telegraf.Accumulator) error {
err := processFile(path)
// We've been cancelled via Stop().
if err == io.EOF {
//nolint:nilerr // context cancelation is not an error
return nil
}
}
Expand Down
9 changes: 3 additions & 6 deletions plugins/inputs/diskio/diskio_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,10 @@ func (d *DiskIO) diskInfo(devName string) (map[string]string, error) {
}
if l[:2] == "S:" {
if devlinks.Len() > 0 {
//nolint:errcheck,revive // this will never fail
devlinks.WriteString(" ")
devlinks.WriteString(" ") //nolint:revive // this will never fail
}
//nolint:errcheck,revive // this will never fail
devlinks.WriteString("/dev/")
//nolint:errcheck,revive // this will never fail
devlinks.WriteString(l[2:])
devlinks.WriteString("/dev/") //nolint:revive // this will never fail
devlinks.WriteString(l[2:]) //nolint:revive // this will never fail
continue
}
if l[:2] != "E:" {
Expand Down
3 changes: 1 addition & 2 deletions plugins/inputs/diskio/diskio_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ func setupNullDisk(t *testing.T, s *DiskIO, devName string) func() {

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

ic.udevDataPath = td.Name()
Expand Down
9 changes: 3 additions & 6 deletions plugins/inputs/docker_log/docker_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,9 @@ func tailMultiplexed(
}()

_, err := stdcopy.StdCopy(outWriter, errWriter, src)
//nolint:errcheck,revive // we cannot do anything if the closing fails
outWriter.Close()
//nolint:errcheck,revive // we cannot do anything if the closing fails
errWriter.Close()
//nolint:errcheck,revive // we cannot do anything if the closing fails
src.Close()
outWriter.Close() //nolint:revive // we cannot do anything if the closing fails
errWriter.Close() //nolint:revive // we cannot do anything if the closing fails
src.Close() //nolint:revive // we cannot do anything if the closing fails
wg.Wait()
return err
}
Expand Down
3 changes: 1 addition & 2 deletions plugins/inputs/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func (c CommandRunner) truncate(buf bytes.Buffer) bytes.Buffer {
buf.Truncate(i)
}
if didTruncate {
//nolint:errcheck,revive // Will always return nil or panic
buf.WriteString("...")
buf.WriteString("...") //nolint:revive // will always return nil or panic
}
return buf
}
Expand Down
4 changes: 1 addition & 3 deletions plugins/inputs/http_listener_v2/http_listener_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ func (h *HTTPListenerV2) createHTTPServer() *http.Server {
// Stop cleans up all resources
func (h *HTTPListenerV2) Stop() {
if h.listener != nil {
// Ignore the returned error as we cannot do anything about it anyway
//nolint:errcheck,revive
h.listener.Close()
h.listener.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
}
h.wg.Wait()
}
Expand Down
6 changes: 2 additions & 4 deletions plugins/inputs/http_response/http_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func setUpTestMux() http.Handler {
fmt.Fprintf(w, "hit the good page!")
})
mux.HandleFunc("/invalidUTF8", func(w http.ResponseWriter, req *http.Request) {
//nolint:errcheck,revive
w.Write([]byte{0xff, 0xfe, 0xfd})
w.Write([]byte{0xff, 0xfe, 0xfd}) //nolint:errcheck,revive // ignore the returned error as the test will fail anyway
})
mux.HandleFunc("/noheader", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hit the good page!")
Expand All @@ -120,8 +119,7 @@ func setUpTestMux() http.Handler {
})
mux.HandleFunc("/musthaveabody", func(w http.ResponseWriter, req *http.Request) {
body, err := io.ReadAll(req.Body)
//nolint:errcheck,revive
req.Body.Close()
defer req.Body.Close()
if err != nil {
http.Error(w, "couldn't read request body", http.StatusBadRequest)
return
Expand Down
4 changes: 1 addition & 3 deletions plugins/inputs/jenkins/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ func (c *client) doGet(ctx context.Context, url string, v interface{}) error {
return err
}
defer func() {
// Ignore the returned error as we cannot do anything about it anyway
//nolint:errcheck,revive
resp.Body.Close()
resp.Body.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
<-c.semaphore
}()
// Clear invalid token if unauthorized
Expand Down
5 changes: 2 additions & 3 deletions plugins/inputs/jenkins/jenkins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ func (h mockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
return
}
// Ignore the returned error as the tests will fail anyway
//nolint:errcheck,revive
w.Write(b)

w.Write(b) //nolint:errcheck,revive // ignore the returned error as the tests will fail anyway
}

func TestGatherNodeData(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ func TestMain(m *testing.M) {
grpcServer := grpc.NewServer(opts...)
telemetry.RegisterOpenConfigTelemetryServer(grpcServer, newServer())
go func() {
// Ignore the returned error as the tests will fail anyway
//nolint:errcheck,revive
grpcServer.Serve(lis)
grpcServer.Serve(lis) //nolint:errcheck // ignore the returned error as the tests will fail anyway
}()
defer grpcServer.Stop()
os.Exit(m.Run())
Expand Down

0 comments on commit d9d9cd4

Please sign in to comment.