Skip to content

Commit

Permalink
chore: Enable G601 rule for gosec (influxdata#13042)
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel authored Apr 12, 2023
1 parent 55e4bb6 commit 5f2142a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ linters-settings:
- G502
- G503
- G505
- G601
# To specify the configuration of rules.
config:
# Maximum allowed permissions mode for os.OpenFile and os.Chmod
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (ch *ClickHouse) Gather(acc telegraf.Accumulator) (err error) {
}
}

for _, conn := range connects {
for i := range connects {
metricsFuncs := []func(acc telegraf.Accumulator, conn *connect) error{
ch.tables,
ch.zookeeper,
Expand All @@ -141,13 +141,13 @@ func (ch *ClickHouse) Gather(acc telegraf.Accumulator) (err error) {
}

for _, metricFunc := range metricsFuncs {
if err := metricFunc(acc, &conn); err != nil {
if err := metricFunc(acc, &connects[i]); err != nil {
acc.AddError(err)
}
}

for metric := range commonMetrics {
if err := ch.commonMetrics(acc, &conn, metric); err != nil {
if err := ch.commonMetrics(acc, &connects[i], metric); err != nil {
acc.AddError(err)
}
}
Expand Down
12 changes: 8 additions & 4 deletions plugins/inputs/mongodb/mongodb_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ var topDataStats = map[string]string{
}

func (d *MongodbData) AddDbStats() {
for _, dbstat := range d.StatLine.DbStatsLines {
for i := range d.StatLine.DbStatsLines {
dbstat := d.StatLine.DbStatsLines[i]
dbStatLine := reflect.ValueOf(&dbstat).Elem()
newDbData := &DbData{
Name: dbstat.Name,
Expand All @@ -315,7 +316,8 @@ func (d *MongodbData) AddDbStats() {
}

func (d *MongodbData) AddColStats() {
for _, colstat := range d.StatLine.ColStatsLines {
for i := range d.StatLine.ColStatsLines {
colstat := d.StatLine.ColStatsLines[i]
colStatLine := reflect.ValueOf(&colstat).Elem()
newColData := &ColData{
Name: colstat.Name,
Expand All @@ -332,7 +334,8 @@ func (d *MongodbData) AddColStats() {
}

func (d *MongodbData) AddShardHostStats() {
for host, hostStat := range d.StatLine.ShardHostStatsLines {
for host := range d.StatLine.ShardHostStatsLines {
hostStat := d.StatLine.ShardHostStatsLines[host]
hostStatLine := reflect.ValueOf(&hostStat).Elem()
newDbData := &DbData{
Name: host,
Expand All @@ -348,7 +351,8 @@ func (d *MongodbData) AddShardHostStats() {
}

func (d *MongodbData) AddTopStats() {
for _, topStat := range d.StatLine.TopStatLines {
for i := range d.StatLine.TopStatLines {
topStat := d.StatLine.TopStatLines[i]
topStatLine := reflect.ValueOf(&topStat).Elem()
newTopStatData := &DbData{
Name: topStat.CollectionName,
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/ras/ras_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

func TestUpdateCounters(t *testing.T) {
ras := newRas()
for _, mce := range testData {
ras.updateCounters(&mce)
for i := range testData {
ras.updateCounters(&testData[i])
}

require.Equal(t, 1, len(ras.cpuSocketCounters), "Should contain counters only for single socket")
Expand Down Expand Up @@ -94,8 +94,8 @@ func TestMultipleSockets(t *testing.T) {
MciStatusMsg: overflow,
},
}
for _, mce := range testData {
ras.updateCounters(&mce)
for i := range testData {
ras.updateCounters(&testData[i])
}
require.Equal(t, 4, len(ras.cpuSocketCounters), "Should contain counters for four sockets")

Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/vsphere/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ func (e *Endpoint) collectChunk(
e.log.Errorf("MOID %s not found in cache. Skipping", moid)
continue
}
e.populateTags(objectRef, resourceType, res, t, &v)
e.populateTags(objectRef, resourceType, res, t, v)

nValues := 0
alignedInfo, alignedValues := e.alignSamples(em.SampleInfo, v.Value, interval)
Expand Down Expand Up @@ -1280,7 +1280,7 @@ func (e *Endpoint) collectChunk(
return count, latestSample, nil
}

func (e *Endpoint) populateTags(objectRef *objectRef, resourceType string, resource *resourceKind, t map[string]string, v *performance.MetricSeries) {
func (e *Endpoint) populateTags(objectRef *objectRef, resourceType string, resource *resourceKind, t map[string]string, v performance.MetricSeries) {
// Map name of object.
if resource.pKey != "" {
t[resource.pKey] = objectRef.name
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/azure_monitor/azure_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (a *AzureMonitor) Write(metrics []telegraf.Metric) error {
for _, m := range azmetrics {
// Azure Monitor accepts new batches of points in new-line delimited
// JSON, following RFC 4288 (see https://github.com/ndjson/ndjson-spec).
jsonBytes, err := json.Marshal(&m)
jsonBytes, err := json.Marshal(m)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/parsers/collectd/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ func writeValueList(valueLists []api.ValueList) (*network.Buffer, error) {
buffer := network.NewBuffer(0)

ctx := context.Background()
for _, vl := range valueLists {
err := buffer.Write(ctx, &vl)
for i := range valueLists {
err := buffer.Write(ctx, &valueLists[i])
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5f2142a

Please sign in to comment.