Skip to content

Commit

Permalink
Linter fixes - gosimple (influxdata#9046)
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel authored Mar 25, 2021
1 parent d5b4c3e commit 099ccda
Show file tree
Hide file tree
Showing 70 changed files with 152 additions and 255 deletions.
2 changes: 1 addition & 1 deletion filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Compile(filters []string) (Filter, error) {

// hasMeta reports whether path contains any magic glob characters.
func hasMeta(s string) bool {
return strings.IndexAny(s, "*?[") >= 0
return strings.ContainsAny(s, "*?[")
}

type filter struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/globpath/globpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ func (g *GlobPath) GetRoots() []string {

// hasMeta reports whether path contains any magic glob characters.
func hasMeta(path string) bool {
return strings.IndexAny(path, "*?[") >= 0
return strings.ContainsAny(path, "*?[")
}

// hasSuperMeta reports whether path contains any super magic glob characters (**).
func hasSuperMeta(path string) bool {
return strings.Index(path, "**") >= 0
return strings.Contains(path, "**")
}
2 changes: 1 addition & 1 deletion internal/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestMain(m *testing.M) {
// externalProcess is an external "misbehaving" process that won't exit
// cleanly.
func externalProcess() {
wait := make(chan int, 0)
wait := make(chan int)
fmt.Fprintln(os.Stdout, "started")
<-wait
os.Exit(2)
Expand Down
2 changes: 0 additions & 2 deletions internal/templating/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ func (t *Template) Apply(line string, joiner string) (string, map[string]string,
field = append(field, fields[i])
case "field*":
field = append(field, fields[i:]...)
break
case "measurement*":
measurement = append(measurement, fields[i:]...)
break
default:
tags[tag] = append(tags[tag], fields[i])
}
Expand Down
3 changes: 1 addition & 2 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ func (t *telegrafLog) Write(b []byte) (n int, err error) {
}

func (t *telegrafLog) Close() error {
var stdErrWriter io.Writer
stdErrWriter = os.Stderr
stdErrWriter := os.Stderr
// avoid closing stderr
if t.internalWriter != stdErrWriter {
closer, isCloser := t.internalWriter.(io.Closer)
Expand Down
26 changes: 10 additions & 16 deletions models/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,41 @@ func (f *Filter) Compile() error {
var err error
f.nameDrop, err = filter.Compile(f.NameDrop)
if err != nil {
return fmt.Errorf("Error compiling 'namedrop', %s", err)
return fmt.Errorf("error compiling 'namedrop', %s", err)
}
f.namePass, err = filter.Compile(f.NamePass)
if err != nil {
return fmt.Errorf("Error compiling 'namepass', %s", err)
return fmt.Errorf("error compiling 'namepass', %s", err)
}

f.fieldDrop, err = filter.Compile(f.FieldDrop)
if err != nil {
return fmt.Errorf("Error compiling 'fielddrop', %s", err)
return fmt.Errorf("error compiling 'fielddrop', %s", err)
}
f.fieldPass, err = filter.Compile(f.FieldPass)
if err != nil {
return fmt.Errorf("Error compiling 'fieldpass', %s", err)
return fmt.Errorf("error compiling 'fieldpass', %s", err)
}

f.tagExclude, err = filter.Compile(f.TagExclude)
if err != nil {
return fmt.Errorf("Error compiling 'tagexclude', %s", err)
return fmt.Errorf("error compiling 'tagexclude', %s", err)
}
f.tagInclude, err = filter.Compile(f.TagInclude)
if err != nil {
return fmt.Errorf("Error compiling 'taginclude', %s", err)
return fmt.Errorf("error compiling 'taginclude', %s", err)
}

for i := range f.TagDrop {
f.TagDrop[i].filter, err = filter.Compile(f.TagDrop[i].Filter)
if err != nil {
return fmt.Errorf("Error compiling 'tagdrop', %s", err)
return fmt.Errorf("error compiling 'tagdrop', %s", err)
}
}
for i := range f.TagPass {
f.TagPass[i].filter, err = filter.Compile(f.TagPass[i].Filter)
if err != nil {
return fmt.Errorf("Error compiling 'tagpass', %s", err)
return fmt.Errorf("error compiling 'tagpass', %s", err)
}
}
return nil
Expand Down Expand Up @@ -132,17 +132,11 @@ func (f *Filter) IsActive() bool {
// based on the drop/pass filter parameters
func (f *Filter) shouldNamePass(key string) bool {
pass := func(f *Filter) bool {
if f.namePass.Match(key) {
return true
}
return false
return f.namePass.Match(key)
}

drop := func(f *Filter) bool {
if f.nameDrop.Match(key) {
return false
}
return true
return !f.nameDrop.Match(key)
}

if f.namePass != nil && f.nameDrop != nil {
Expand Down
2 changes: 0 additions & 2 deletions models/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,4 @@ func SetLoggerOnPlugin(i interface{}, log telegraf.Logger) {
log.Debugf("Plugin %q defines a 'Log' field on its struct of an unexpected type %q. Expected telegraf.Logger",
valI.Type().Name(), field.Type().String())
}

return
}
4 changes: 1 addition & 3 deletions models/running_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,7 @@ func (m *mockOutput) Write(metrics []telegraf.Metric) error {
m.metrics = []telegraf.Metric{}
}

for _, metric := range metrics {
m.metrics = append(m.metrics, metric)
}
m.metrics = append(m.metrics, metrics...)
return nil
}

Expand Down
2 changes: 0 additions & 2 deletions plugins/common/shim/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,4 @@ func setLoggerOnPlugin(i interface{}, log telegraf.Logger) {
field.Set(reflect.ValueOf(log))
}
}

return
}
10 changes: 1 addition & 9 deletions plugins/inputs/aerospike/aerospike.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ func (a *Aerospike) parseNodeInfo(stats map[string]string, hostPort string, node
fields[key] = parseAerospikeValue(key, v)
}
acc.AddFields("aerospike_node", fields, tags, time.Now())

return
}

func (a *Aerospike) getNamespaces(n *as.Node) ([]string, error) {
Expand Down Expand Up @@ -295,8 +293,6 @@ func (a *Aerospike) parseNamespaceInfo(stats map[string]string, hostPort string,
nFields[key] = parseAerospikeValue(key, parts[1])
}
acc.AddFields("aerospike_namespace", nFields, nTags, time.Now())

return
}

func (a *Aerospike) getSets(n *as.Node) ([]string, error) {
Expand Down Expand Up @@ -365,8 +361,6 @@ func (a *Aerospike) parseSetInfo(stats map[string]string, hostPort string, names
nFields[key] = parseAerospikeValue(key, pieces[1])
}
acc.AddFields("aerospike_set", nFields, nTags, time.Now())

return
}

func (a *Aerospike) getTTLHistogram(hostPort string, namespace string, set string, n *as.Node, acc telegraf.Accumulator) error {
Expand Down Expand Up @@ -430,7 +424,7 @@ func (a *Aerospike) parseHistogram(stats map[string]string, hostPort string, nam
// Normalize incase of less buckets than expected
numRecordsPerBucket := 1
if len(buckets) > a.NumberHistogramBuckets {
numRecordsPerBucket = int(math.Ceil((float64(len(buckets)) / float64(a.NumberHistogramBuckets))))
numRecordsPerBucket = int(math.Ceil(float64(len(buckets)) / float64(a.NumberHistogramBuckets)))
}

bucketCount := 0
Expand Down Expand Up @@ -462,8 +456,6 @@ func (a *Aerospike) parseHistogram(stats map[string]string, hostPort string, nam
}

acc.AddFields(fmt.Sprintf("aerospike_histogram_%v", strings.Replace(histogramType, "-", "_", -1)), nFields, nTags, time.Now())

return
}

func splitNamespaceSet(namespaceSet string) (string, string) {
Expand Down
14 changes: 7 additions & 7 deletions plugins/inputs/amqp_consumer/amqp_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (a *externalAuth) Mechanism() string {
return "EXTERNAL"
}
func (a *externalAuth) Response() string {
return fmt.Sprintf("\000")
return "\000"
}

const (
Expand Down Expand Up @@ -288,7 +288,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err

ch, err := a.conn.Channel()
if err != nil {
return nil, fmt.Errorf("Failed to open a channel: %s", err.Error())
return nil, fmt.Errorf("failed to open a channel: %s", err.Error())
}

if a.Exchange != "" {
Expand Down Expand Up @@ -335,7 +335,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
nil,
)
if err != nil {
return nil, fmt.Errorf("Failed to bind a queue: %s", err)
return nil, fmt.Errorf("failed to bind a queue: %s", err)
}
}

Expand All @@ -345,7 +345,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
false, // global
)
if err != nil {
return nil, fmt.Errorf("Failed to set QoS: %s", err)
return nil, fmt.Errorf("failed to set QoS: %s", err)
}

msgs, err := ch.Consume(
Expand All @@ -358,7 +358,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
nil, // arguments
)
if err != nil {
return nil, fmt.Errorf("Failed establishing connection to queue: %s", err)
return nil, fmt.Errorf("failed establishing connection to queue: %s", err)
}

return msgs, err
Expand Down Expand Up @@ -395,7 +395,7 @@ func declareExchange(
)
}
if err != nil {
return fmt.Errorf("Error declaring exchange: %v", err)
return fmt.Errorf("error declaring exchange: %v", err)
}
return nil
}
Expand Down Expand Up @@ -437,7 +437,7 @@ func declareQueue(
)
}
if err != nil {
return nil, fmt.Errorf("Error declaring queue: %v", err)
return nil, fmt.Errorf("error declaring queue: %v", err)
}
return &queue, nil
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ func (c *CiscoTelemetryMDT) nxosValueXform(field *telemetry.TelemetryField, valu
}
case *telemetry.TelemetryField_Uint32Value:
vali, ok := value.(uint32)
if ok == true {
if ok {
return vali
}
case *telemetry.TelemetryField_Uint64Value:
vali, ok := value.(uint64)
if ok == true {
if ok {
return vali
}
} //switch
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/diskio/diskio.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (d *DiskIO) SampleConfig() string {

// hasMeta reports whether s contains any special glob characters.
func hasMeta(s string) bool {
return strings.IndexAny(s, "*?[") >= 0
return strings.ContainsAny(s, "*?[")
}

func (d *DiskIO) init() error {
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 @@ -24,7 +24,7 @@ func setupNullDisk(t *testing.T, s *DiskIO, devName string) func() error {
require.NoError(t, err)

if s.infoCache == nil {
s.infoCache = make(map[string]diskInfoCache, 0)
s.infoCache = make(map[string]diskInfoCache)
}
ic, ok := s.infoCache[devName]
if !ok {
Expand Down
11 changes: 3 additions & 8 deletions plugins/inputs/elasticsearch/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (

"github.com/influxdata/telegraf/testutil"

"fmt"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -56,8 +54,7 @@ func (t *transportMock) CancelRequest(_ *http.Request) {

func checkIsMaster(es *Elasticsearch, server string, expected bool, t *testing.T) {
if es.serverInfo[server].isMaster() != expected {
msg := fmt.Sprintf("IsMaster set incorrectly")
assert.Fail(t, msg)
assert.Fail(t, "IsMaster set incorrectly")
}
}

Expand Down Expand Up @@ -231,8 +228,7 @@ func TestGatherClusterStatsMaster(t *testing.T) {

IsMasterResultTokens := strings.Split(string(IsMasterResult), " ")
if masterID != IsMasterResultTokens[0] {
msg := fmt.Sprintf("catmaster is incorrect")
assert.Fail(t, msg)
assert.Fail(t, "catmaster is incorrect")
}

// now get node status, which determines whether we're master
Expand Down Expand Up @@ -275,8 +271,7 @@ func TestGatherClusterStatsNonMaster(t *testing.T) {

IsNotMasterResultTokens := strings.Split(string(IsNotMasterResult), " ")
if masterID != IsNotMasterResultTokens[0] {
msg := fmt.Sprintf("catmaster is incorrect")
assert.Fail(t, msg)
assert.Fail(t, "catmaster is incorrect")
}

// now get node status, which determines whether we're master
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/fibaro/fibaro.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (f *Fibaro) getJSON(path string, dataStruct interface{}) error {
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
err = fmt.Errorf("Response from url \"%s\" has status code %d (%s), expected %d (%s)",
err = fmt.Errorf("response from url \"%s\" has status code %d (%s), expected %d (%s)",
requestURL,
resp.StatusCode,
http.StatusText(resp.StatusCode),
Expand Down Expand Up @@ -159,7 +159,7 @@ func (f *Fibaro) Gather(acc telegraf.Accumulator) error {
for _, device := range devices {
// skip device in some cases
if device.RoomID == 0 ||
device.Enabled == false ||
!device.Enabled ||
device.Properties.Dead == "true" ||
device.Type == "com.fibaro.zwaveDevice" {
continue
Expand Down
5 changes: 1 addition & 4 deletions plugins/inputs/fluentd/fluentd.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ func parse(data []byte) (datapointArray []pluginData, err error) {
return
}

for _, point := range endpointData.Payload {
datapointArray = append(datapointArray, point)
}

datapointArray = append(datapointArray, endpointData.Payload...)
return
}

Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/graylog/graylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ func (h *GrayLog) flatten(item map[string]interface{}, fields map[string]interfa
id = id + "_"
}
for k, i := range item {
switch i.(type) {
switch i := i.(type) {
case int:
fields[id+k] = i.(float64)
fields[id+k] = float64(i)
case float64:
fields[id+k] = i.(float64)
fields[id+k] = i
case map[string]interface{}:
h.flatten(i.(map[string]interface{}), fields, id+k)
h.flatten(i, fields, id+k)
default:
}
}
Expand Down
4 changes: 1 addition & 3 deletions plugins/inputs/haproxy/haproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ func (h *haproxy) Gather(acc telegraf.Accumulator) error {
if len(matches) == 0 {
endpoints = append(endpoints, socketPath)
} else {
for _, match := range matches {
endpoints = append(endpoints, match)
}
endpoints = append(endpoints, matches...)
}
}

Expand Down
Loading

0 comments on commit 099ccda

Please sign in to comment.