chore: fix linter findings for nolintlint part 1 (#12427)
This commit is contained in:
parent
bd77a425ba
commit
d9d9cd4c0b
|
|
@ -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
|
// mimcks grabbing INDEX {} that is returned from snmptranslate -Td MibName
|
||||||
for _, index := range node.GetIndex() {
|
for _, index := range node.GetIndex() {
|
||||||
//nolint:staticcheck //assaignment to nil map to keep backwards compatibilty
|
|
||||||
tagOids[mibPrefix+index.Name] = struct{}{}
|
tagOids[mibPrefix+index.Name] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -247,8 +246,7 @@ func SnmpTranslateCall(oid string) (mibName string, oidNum string, oidText strin
|
||||||
out, err = gosmi.GetNodeByOID(types.OidMustFromString(oid))
|
out, err = gosmi.GetNodeByOID(types.OidMustFromString(oid))
|
||||||
oidNum = oid
|
oidNum = oid
|
||||||
// ensure modules are loaded or node will be empty (might not error)
|
// 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 // do not return the err as the oid is numeric and telegraf can continue
|
||||||
//nolint:nilerr
|
|
||||||
if err != nil || out.Name == "iso" {
|
if err != nil || out.Name == "iso" {
|
||||||
return oid, oid, oid, oid, out, nil
|
return oid, oid, oid, oid, out, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,8 @@ type Field struct {
|
||||||
// Metric is the type of data that is processed by Telegraf. Input plugins,
|
// 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 to a lesser degree, Processor and Aggregator plugins create new Metrics
|
||||||
// and Output plugins write them.
|
// and Output plugins write them.
|
||||||
// nolint:interfacebloat // conditionally allow to contain more methods
|
//
|
||||||
|
//nolint:interfacebloat // conditionally allow to contain more methods
|
||||||
type Metric interface {
|
type Metric interface {
|
||||||
// Name is the primary identifier for the Metric and corresponds to the
|
// Name is the primary identifier for the Metric and corresponds to the
|
||||||
// measurement in the InfluxDB data model.
|
// measurement in the InfluxDB data model.
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,6 @@ func (o *OpcUAClient) Disconnect(ctx context.Context) error {
|
||||||
case "opc.tcp":
|
case "opc.tcp":
|
||||||
o.State = Disconnected
|
o.State = Disconnected
|
||||||
// We can't do anything about failing to close a connection
|
// We can't do anything about failing to close a connection
|
||||||
//nolint:errcheck,revive
|
|
||||||
err := o.Client.CloseWithContext(ctx)
|
err := o.Client.CloseWithContext(ctx)
|
||||||
o.Client = nil
|
o.Client = nil
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -198,19 +198,11 @@ func newMP(n *NodeMetricMapping) metricParts {
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
// Writes to a string-builder will always succeed
|
sb.WriteString(", ") //nolint:revive // writes to a string-builder will always succeed
|
||||||
//nolint:errcheck,revive
|
|
||||||
sb.WriteString(", ")
|
|
||||||
}
|
}
|
||||||
// Writes to a string-builder will always succeed
|
sb.WriteString(key) //nolint:revive // writes to a string-builder will always succeed
|
||||||
//nolint:errcheck,revive
|
sb.WriteString("=") //nolint:revive // writes to a string-builder will always succeed
|
||||||
sb.WriteString(key)
|
sb.WriteString(n.MetricTags[key]) //nolint:revive // writes to a string-builder will always succeed
|
||||||
// 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])
|
|
||||||
}
|
}
|
||||||
x := metricParts{
|
x := metricParts{
|
||||||
metricName: n.metricName,
|
metricName: n.metricName,
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,7 @@ func getHTTPServer() *httptest.Server {
|
||||||
body, code := getResponseJSON(r.RequestURI)
|
body, code := getResponseJSON(r.RequestURI)
|
||||||
w.WriteHeader(code)
|
w.WriteHeader(code)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
// Ignore the returned error as the test will fail anyway
|
w.Write(body) //nolint:errcheck,revive // ignore the returned error as the test will fail anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
w.Write(body)
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,9 +61,7 @@ func getHTTPServerBasicAuth() *httptest.Server {
|
||||||
body, code := getResponseJSON(r.RequestURI)
|
body, code := getResponseJSON(r.RequestURI)
|
||||||
w.WriteHeader(code)
|
w.WriteHeader(code)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
// Ignore the returned error as the test will fail anyway
|
w.Write(body) //nolint:errcheck,revive // ignore the returned error as the test will fail anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
w.Write(body)
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -222,11 +222,9 @@ func (m *metric) name() string {
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
for i := len(m.pathStack) - 1; i >= 0; i-- {
|
for i := len(m.pathStack) - 1; i >= 0; i-- {
|
||||||
if buf.Len() > 0 {
|
if buf.Len() > 0 {
|
||||||
//nolint:errcheck,revive // should never return an error
|
buf.WriteString(".") //nolint:revive // should never return an error
|
||||||
buf.WriteString(".")
|
|
||||||
}
|
}
|
||||||
//nolint:errcheck,revive // should never return an error
|
buf.WriteString(m.pathStack[i]) //nolint:revive // should never return an error
|
||||||
buf.WriteString(m.pathStack[i])
|
|
||||||
}
|
}
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -178,8 +178,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 {
|
||||||
//nolint:errcheck,revive // we cannot do anything if the closing fails
|
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,8 +209,7 @@ func (c *CiscoTelemetryMDT) Start(acc telegraf.Accumulator) error {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
//nolint:errcheck,revive // we cannot do anything if the closing fails
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -724,12 +722,10 @@ func (c *CiscoTelemetryMDT) Address() net.Addr {
|
||||||
func (c *CiscoTelemetryMDT) Stop() {
|
func (c *CiscoTelemetryMDT) Stop() {
|
||||||
if c.grpcServer != nil {
|
if c.grpcServer != nil {
|
||||||
// Stop server and terminate all running dialout routines
|
// Stop server and terminate all running dialout routines
|
||||||
//nolint:errcheck,revive // we cannot do anything if the stopping fails
|
|
||||||
c.grpcServer.Stop()
|
c.grpcServer.Stop()
|
||||||
}
|
}
|
||||||
if c.listener != nil {
|
if c.listener != nil {
|
||||||
//nolint:errcheck,revive // we cannot do anything if the closing fails
|
c.listener.Close() //nolint:revive // we cannot do anything if the closing fails
|
||||||
c.listener.Close()
|
|
||||||
}
|
}
|
||||||
c.wg.Wait()
|
c.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -194,8 +194,7 @@ func TestServeHTTP(t *testing.T) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for m := range d {
|
for m := range d {
|
||||||
ro.AddMetric(m)
|
ro.AddMetric(m)
|
||||||
//nolint:errcheck,revive // test will fail anyway if the write fails
|
ro.Write() //nolint:errcheck // test will fail anyway if the write fails
|
||||||
ro.Write()
|
|
||||||
}
|
}
|
||||||
}(dst)
|
}(dst)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -392,9 +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 {
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
cms.listener.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
cms.listener.Close()
|
|
||||||
}
|
}
|
||||||
cms.wg.Wait()
|
cms.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -292,8 +292,7 @@ func (c *ClusterClient) doGet(ctx context.Context, address string, v interface{}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
//nolint:errcheck,revive // we cannot do anything if the closing fails
|
resp.Body.Close() //nolint:revive // we cannot do anything if the closing fails
|
||||||
resp.Body.Close()
|
|
||||||
<-c.semaphore
|
<-c.semaphore
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,7 @@ func (monitor *DirectoryMonitor) Gather(_ telegraf.Accumulator) error {
|
||||||
|
|
||||||
stat, err := times.Stat(path)
|
stat, err := times.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Don't stop traversing if there is an eror
|
return nil //nolint:nilerr // don't stop traversing if there is an error
|
||||||
return nil //nolint:nilerr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
timeThresholdExceeded := time.Since(stat.AccessTime()) >= time.Duration(monitor.DirectoryDurationThreshold)
|
timeThresholdExceeded := time.Since(stat.AccessTime()) >= time.Duration(monitor.DirectoryDurationThreshold)
|
||||||
|
|
@ -105,7 +104,6 @@ func (monitor *DirectoryMonitor) Gather(_ telegraf.Accumulator) error {
|
||||||
})
|
})
|
||||||
// We've been cancelled via Stop().
|
// We've been cancelled via Stop().
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
//nolint:nilerr // context cancelation is not an error
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -126,7 +124,6 @@ func (monitor *DirectoryMonitor) Gather(_ telegraf.Accumulator) error {
|
||||||
err := processFile(path)
|
err := processFile(path)
|
||||||
// We've been cancelled via Stop().
|
// We've been cancelled via Stop().
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
//nolint:nilerr // context cancelation is not an error
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,13 +83,10 @@ func (d *DiskIO) diskInfo(devName string) (map[string]string, error) {
|
||||||
}
|
}
|
||||||
if l[:2] == "S:" {
|
if l[:2] == "S:" {
|
||||||
if devlinks.Len() > 0 {
|
if devlinks.Len() > 0 {
|
||||||
//nolint:errcheck,revive // this will never fail
|
devlinks.WriteString(" ") //nolint:revive // this will never fail
|
||||||
devlinks.WriteString(" ")
|
|
||||||
}
|
}
|
||||||
//nolint:errcheck,revive // this will never fail
|
devlinks.WriteString("/dev/") //nolint:revive // this will never fail
|
||||||
devlinks.WriteString("/dev/")
|
devlinks.WriteString(l[2:]) //nolint:revive // this will never fail
|
||||||
//nolint:errcheck,revive // this will never fail
|
|
||||||
devlinks.WriteString(l[2:])
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if l[:2] != "E:" {
|
if l[:2] != "E:" {
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,7 @@ func setupNullDisk(t *testing.T, s *DiskIO, devName string) func() {
|
||||||
|
|
||||||
cleanFunc := func() {
|
cleanFunc := func() {
|
||||||
ic.udevDataPath = origUdevPath
|
ic.udevDataPath = origUdevPath
|
||||||
//nolint:errcheck,revive // we cannot do anything if file cannot be removed
|
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()
|
||||||
|
|
|
||||||
|
|
@ -360,12 +360,9 @@ func tailMultiplexed(
|
||||||
}()
|
}()
|
||||||
|
|
||||||
_, err := stdcopy.StdCopy(outWriter, errWriter, src)
|
_, err := stdcopy.StdCopy(outWriter, errWriter, src)
|
||||||
//nolint:errcheck,revive // we cannot do anything if the closing fails
|
outWriter.Close() //nolint:revive // we cannot do anything if the closing fails
|
||||||
outWriter.Close()
|
errWriter.Close() //nolint:revive // we cannot do anything if the closing fails
|
||||||
//nolint:errcheck,revive // we cannot do anything if the closing fails
|
src.Close() //nolint:revive // we cannot do anything if the closing fails
|
||||||
errWriter.Close()
|
|
||||||
//nolint:errcheck,revive // we cannot do anything if the closing fails
|
|
||||||
src.Close()
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,8 +110,7 @@ func (c CommandRunner) truncate(buf bytes.Buffer) bytes.Buffer {
|
||||||
buf.Truncate(i)
|
buf.Truncate(i)
|
||||||
}
|
}
|
||||||
if didTruncate {
|
if didTruncate {
|
||||||
//nolint:errcheck,revive // Will always return nil or panic
|
buf.WriteString("...") //nolint:revive // will always return nil or panic
|
||||||
buf.WriteString("...")
|
|
||||||
}
|
}
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,9 +136,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 {
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
h.listener.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
h.listener.Close()
|
|
||||||
}
|
}
|
||||||
h.wg.Wait()
|
h.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,7 @@ func setUpTestMux() http.Handler {
|
||||||
fmt.Fprintf(w, "hit the good page!")
|
fmt.Fprintf(w, "hit the good page!")
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/invalidUTF8", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/invalidUTF8", func(w http.ResponseWriter, req *http.Request) {
|
||||||
//nolint:errcheck,revive
|
w.Write([]byte{0xff, 0xfe, 0xfd}) //nolint:errcheck,revive // ignore the returned error as the test will fail anyway
|
||||||
w.Write([]byte{0xff, 0xfe, 0xfd})
|
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/noheader", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/noheader", func(w http.ResponseWriter, req *http.Request) {
|
||||||
fmt.Fprintf(w, "hit the good page!")
|
fmt.Fprintf(w, "hit the good page!")
|
||||||
|
|
@ -120,8 +119,7 @@ func setUpTestMux() http.Handler {
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/musthaveabody", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/musthaveabody", func(w http.ResponseWriter, req *http.Request) {
|
||||||
body, err := io.ReadAll(req.Body)
|
body, err := io.ReadAll(req.Body)
|
||||||
//nolint:errcheck,revive
|
defer req.Body.Close()
|
||||||
req.Body.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "couldn't read request body", http.StatusBadRequest)
|
http.Error(w, "couldn't read request body", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -69,9 +69,7 @@ func (c *client) doGet(ctx context.Context, url string, v interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
resp.Body.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
resp.Body.Close()
|
|
||||||
<-c.semaphore
|
<-c.semaphore
|
||||||
}()
|
}()
|
||||||
// Clear invalid token if unauthorized
|
// Clear invalid token if unauthorized
|
||||||
|
|
|
||||||
|
|
@ -97,9 +97,8 @@ func (h mockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Ignore the returned error as the tests will fail anyway
|
|
||||||
//nolint:errcheck,revive
|
w.Write(b) //nolint:errcheck,revive // ignore the returned error as the tests will fail anyway
|
||||||
w.Write(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherNodeData(t *testing.T) {
|
func TestGatherNodeData(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -225,9 +225,7 @@ func TestMain(m *testing.M) {
|
||||||
grpcServer := grpc.NewServer(opts...)
|
grpcServer := grpc.NewServer(opts...)
|
||||||
telemetry.RegisterOpenConfigTelemetryServer(grpcServer, newServer())
|
telemetry.RegisterOpenConfigTelemetryServer(grpcServer, newServer())
|
||||||
go func() {
|
go func() {
|
||||||
// Ignore the returned error as the tests will fail anyway
|
grpcServer.Serve(lis) //nolint:errcheck // ignore the returned error as the tests will fail anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
grpcServer.Serve(lis)
|
|
||||||
}()
|
}()
|
||||||
defer grpcServer.Stop()
|
defer grpcServer.Stop()
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue