Skip to content

Commit

Permalink
chore: Fix linter findings for `revive:enforce-repeated-arg-type-styl…
Browse files Browse the repository at this point in the history
…e` in `plugins/inputs/[o-z]*` (#15857)
  • Loading branch information
zak-pawel committed Sep 12, 2024
1 parent 46c056f commit 358224f
Show file tree
Hide file tree
Showing 30 changed files with 53 additions and 86 deletions.
2 changes: 1 addition & 1 deletion plugins/inputs/openweathermap/openweathermap.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (n *OpenWeatherMap) gatherForecast(acc telegraf.Accumulator, city string) e
return nil
}

func (n *OpenWeatherMap) formatURL(path string, city string) string {
func (n *OpenWeatherMap) formatURL(path, city string) string {
v := url.Values{
"id": []string{city},
"APPID": []string{n.AppID},
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/phpfpm/fcgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (c *conn) writeRecord(recType recType, reqID uint16, b []byte) error {
return err
}

func (c *conn) writeBeginRequest(reqID uint16, role uint16, flags uint8) error {
func (c *conn) writeBeginRequest(reqID, role uint16, flags uint8) error {
b := [8]byte{byte(role >> 8), byte(role), flags}
return c.writeRecord(typeBeginRequest, reqID, b[:])
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/phpfpm/fcgi_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newFcgiClient(timeout time.Duration, h string, args ...interface{}) (*conn,
return &conn{rwc: con}, nil
}

func (c *conn) Request(env map[string]string, requestData string) (retout []byte, reterr []byte, err error) {
func (c *conn) Request(env map[string]string, requestData string) (retout, reterr []byte, err error) {
defer c.rwc.Close()
var reqID uint16 = 1

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/phpfpm/phpfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func globUnixSocket(address string) ([]string, error) {
return addresses, nil
}

func unixSocketPaths(addr string) (socketPath string, statusPath string) {
func unixSocketPaths(addr string) (socketPath, statusPath string) {
socketAddr := strings.Split(addr, ":")
if len(socketAddr) >= 2 {
socketPath = socketAddr[0]
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/ping/ping_notwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (p *Ping) pingToURL(u string, acc telegraf.Accumulator) {
}

// args returns the arguments for the 'ping' executable
func (p *Ping) args(url string, system string) []string {
func (p *Ping) args(url, system string) []string {
if len(p.Arguments) > 0 {
return append(p.Arguments, url)
}
Expand Down Expand Up @@ -214,7 +214,7 @@ func processPingOutput(out string) (statistics, error) {
return stats, err
}

func getPacketStats(line string) (trans int, recv int, err error) {
func getPacketStats(line string) (trans, recv int, err error) {
recv = 0

stats := strings.Split(line, ", ")
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/proxmox/proxmox.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func getNodeSearchDomain(px *Proxmox) error {
return nil
}

func performRequest(px *Proxmox, apiURL string, method string, data url.Values) ([]byte, error) {
func performRequest(px *Proxmox, apiURL, method string, data url.Values) ([]byte, error) {
request, err := http.NewRequest(method, px.BaseURL+apiURL, strings.NewReader(data.Encode()))
if err != nil {
return nil, err
Expand Down Expand Up @@ -220,7 +220,7 @@ func getFields(vmStat VMStat) map[string]interface{} {
}
}

func getByteMetrics(total json.Number, used json.Number) metrics {
func getByteMetrics(total, used json.Number) metrics {
int64Total := jsonNumberToInt64(total)
int64Used := jsonNumberToInt64(used)
int64Free := int64Total - int64Used
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/proxmox/proxmox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var lxcCurrentStatusTestData = `{"data":{"vmid":"111","type":"lxc","uptime":2078
var qemuCurrentStatusTestData = `{"data":{"name":"qemu1","status":"running","maxdisk":10737418240,"cpu":0.029336643550795,"vmid":"113",` +
`"uptime":2159739,"disk":0,"maxmem":2147483648,"mem":1722451796}}`

func performTestRequest(_ *Proxmox, apiURL string, _ string, _ url.Values) ([]byte, error) {
func performTestRequest(_ *Proxmox, apiURL, _ string, _ url.Values) ([]byte, error) {
var bytedata = []byte("")

if strings.HasSuffix(apiURL, "dns") {
Expand Down
35 changes: 5 additions & 30 deletions plugins/inputs/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,7 @@ func gatherInfoOutput(
// db0:keys=2,expires=0,avg_ttl=0
//
// And there is one for each db on the redis instance
func gatherKeyspaceLine(
name string,
line string,
acc telegraf.Accumulator,
globalTags map[string]string,
) {
func gatherKeyspaceLine(name, line string, acc telegraf.Accumulator, globalTags map[string]string) {
if strings.Contains(line, "keys=") {
fields := make(map[string]interface{})
tags := make(map[string]string)
Expand All @@ -521,12 +516,7 @@ func gatherKeyspaceLine(
// cmdstat_publish:calls=33791,usec=208789,usec_per_call=6.18
//
// Tag: command=publish; Fields: calls=33791i,usec=208789i,usec_per_call=6.18
func gatherCommandstateLine(
name string,
line string,
acc telegraf.Accumulator,
globalTags map[string]string,
) {
func gatherCommandstateLine(name, line string, acc telegraf.Accumulator, globalTags map[string]string) {
if !strings.HasPrefix(name, "cmdstat") {
return
}
Expand Down Expand Up @@ -568,12 +558,7 @@ func gatherCommandstateLine(
// latency_percentiles_usec_zadd:p50=9.023,p99=28.031,p99.9=43.007
//
// Tag: command=zadd; Fields: p50=9.023,p99=28.031,p99.9=43.007
func gatherLatencystatsLine(
name string,
line string,
acc telegraf.Accumulator,
globalTags map[string]string,
) {
func gatherLatencystatsLine(name, line string, acc telegraf.Accumulator, globalTags map[string]string) {
if !strings.HasPrefix(name, "latency_percentiles_usec") {
return
}
Expand Down Expand Up @@ -608,12 +593,7 @@ func gatherLatencystatsLine(
// slave0:ip=127.0.0.1,port=7379,state=online,offset=4556468,lag=0
//
// This line will only be visible when a node has a replica attached.
func gatherReplicationLine(
name string,
line string,
acc telegraf.Accumulator,
globalTags map[string]string,
) {
func gatherReplicationLine(name, line string, acc telegraf.Accumulator, globalTags map[string]string) {
fields := make(map[string]interface{})
tags := make(map[string]string)
for k, v := range globalTags {
Expand Down Expand Up @@ -653,12 +633,7 @@ func gatherReplicationLine(
//
// errorstat_ERR:count=37
// errorstat_MOVED:count=3626
func gatherErrorstatsLine(
name string,
line string,
acc telegraf.Accumulator,
globalTags map[string]string,
) {
func gatherErrorstatsLine(name, line string, acc telegraf.Accumulator, globalTags map[string]string) {
tags := make(map[string]string, len(globalTags)+1)
for k, v := range globalTags {
tags[k] = v
Expand Down
6 changes: 1 addition & 5 deletions plugins/inputs/redis_sentinel/redis_sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,7 @@ func (client *RedisSentinelClient) gatherSentinelStats(acc telegraf.Accumulator,
}

// converts `sentinel masters <name>` output to tags and fields
func convertSentinelMastersOutput(
globalTags map[string]string,
master map[string]string,
quorumErr error,
) (map[string]string, map[string]interface{}, error) {
func convertSentinelMastersOutput(globalTags, master map[string]string, quorumErr error) (map[string]string, map[string]interface{}, error) {
tags := globalTags

tags["master"] = master["name"]
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/redis_sentinel/redis_sentinel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func createRedisContainer(networkName string) testutil.Container {
}
}

func createSentinelContainer(redisAddress string, networkName string, waitingFor wait.Strategy) testutil.Container {
func createSentinelContainer(redisAddress, networkName string, waitingFor wait.Strategy) testutil.Container {
return testutil.Container{
Image: "bitnami/redis-sentinel:7.0",
ExposedPorts: []string{sentinelServicePort},
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/sflow/sflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (s *SFlow) process(acc telegraf.Accumulator, buf []byte) {
}
}

func listenUDP(network string, address string) (*net.UDPConn, error) {
func listenUDP(network, address string) (*net.UDPConn, error) {
switch network {
case "udp", "udp4", "udp6":
addr, err := net.ResolveUDPAddr(network, address)
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/smart/smart.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func (m *Smart) scanAllDevices(ignoreExcludes bool) ([]string, []string, error)
return nvmeDevices, nonNVMeDevices, nil
}

func distinguishNVMeDevices(userDevices []string, availableNVMeDevices []string) []string {
func distinguishNVMeDevices(userDevices, availableNVMeDevices []string) []string {
var nvmeDevices []string

for _, userDevice := range userDevices {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/smartctl/smartctl_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/influxdata/telegraf/internal"
)

func (s *Smartctl) scanDevice(acc telegraf.Accumulator, deviceName string, deviceType string) error {
func (s *Smartctl) scanDevice(acc telegraf.Accumulator, deviceName, deviceType string) error {
args := []string{"--json", "--all", deviceName, "--device", deviceType, "--nocheck=" + s.NoCheck}
cmd := execCommand(s.Path, args...)
if s.UseSudo {
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/snmp_trap/snmp_trap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func newMsgFlagsV3(secLevel string) gosnmp.SnmpV3MsgFlags {
return msgFlags
}

func newUsmSecurityParametersForV3(authProto string, privProto string, username string, privPass string, authPass string) *gosnmp.UsmSecurityParameters {
func newUsmSecurityParametersForV3(authProto, privProto, username, privPass, authPass string) *gosnmp.UsmSecurityParameters {
var authenticationProtocol gosnmp.SnmpV3AuthProtocol
switch strings.ToLower(authProto) {
case "md5":
Expand Down Expand Up @@ -107,7 +107,7 @@ func newUsmSecurityParametersForV3(authProto string, privProto string, username
}
}

func newGoSNMPV3(port uint16, contextName string, engineID string, msgFlags gosnmp.SnmpV3MsgFlags, sp *gosnmp.UsmSecurityParameters) gosnmp.GoSNMP {
func newGoSNMPV3(port uint16, contextName, engineID string, msgFlags gosnmp.SnmpV3MsgFlags, sp *gosnmp.UsmSecurityParameters) gosnmp.GoSNMP {
return gosnmp.GoSNMP{
Port: port,
Version: gosnmp.Version3,
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/socketstat/socketstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (ss *Socketstat) Gather(acc telegraf.Accumulator) error {
return nil
}

func socketList(cmdName string, proto string, timeout config.Duration) (*bytes.Buffer, error) {
func socketList(cmdName, proto string, timeout config.Duration) (*bytes.Buffer, error) {
// Run ss for the given protocol, return the output as bytes.Buffer
args := []string{"-in", "--" + proto}
cmd := exec.Command(cmdName, args...)
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/sqlserver/connectionstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
// getConnectionIdentifiers returns the sqlInstance and databaseName from the given connection string.
// The name of the SQL instance is returned as-is in the connection string
// If the connection string could not be parsed or sqlInstance/databaseName were not present, a placeholder value is returned
func getConnectionIdentifiers(connectionString string) (sqlInstance string, databaseName string) {
func getConnectionIdentifiers(connectionString string) (sqlInstance, databaseName string) {
if len(connectionString) == 0 {
return emptySQLInstance, emptyDatabaseName
}
Expand All @@ -31,7 +31,7 @@ func getConnectionIdentifiers(connectionString string) (sqlInstance string, data
}

// parseConnectionStringKeyValue parses a "key=value;" connection string and returns the SQL instance and database name
func parseConnectionStringKeyValue(connectionString string) (sqlInstance string, databaseName string) {
func parseConnectionStringKeyValue(connectionString string) (sqlInstance, databaseName string) {
sqlInstance = ""
databaseName = ""

Expand Down Expand Up @@ -71,7 +71,7 @@ func parseConnectionStringKeyValue(connectionString string) (sqlInstance string,
}

// parseConnectionStringURL parses a URL-formatted connection string and returns the SQL instance and database name
func parseConnectionStringURL(connectionString string) (sqlInstance string, databaseName string) {
func parseConnectionStringURL(connectionString string) (sqlInstance, databaseName string) {
databaseName = emptyDatabaseName

u, err := url.Parse(connectionString)
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (s *Stackdriver) initializeStackdriverClient(ctx context.Context) error {
return nil
}

func includeExcludeHelper(key string, includes []string, excludes []string) bool {
func includeExcludeHelper(key string, includes, excludes []string) bool {
if len(includes) > 0 {
for _, includeStr := range includes {
if strings.HasPrefix(key, includeStr) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/statsd/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (

var uncommenter = strings.NewReplacer("\\n", "\n")

func (s *Statsd) parseEventMessage(now time.Time, message string, defaultHostname string) error {
func (s *Statsd) parseEventMessage(now time.Time, message, defaultHostname string) error {
// _e{title.length,text.length}:title|text
// [
// |d:date_happened
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ func (s *Statsd) parseStatsdLine(line string) error {
// config file. If there is a match, it will parse the name of the metric and
// map of tags.
// Return values are (<name>, <field>, <tags>)
func (s *Statsd) parseName(bucket string) (name string, field string, tags map[string]string) {
func (s *Statsd) parseName(bucket string) (name, field string, tags map[string]string) {
s.Lock()
defer s.Unlock()
tags = make(map[string]string)
Expand Down Expand Up @@ -796,7 +796,7 @@ func (s *Statsd) parseName(bucket string) (name string, field string, tags map[s
}

// Parse the key,value out of a string that looks like "key=value"
func parseKeyValue(keyValue string) (key string, val string) {
func parseKeyValue(keyValue string) (key, val string) {
split := strings.Split(keyValue, "=")
// Must be exactly 2 to get anything meaningful out of them
if len(split) == 2 {
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/sysstat/sysstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func withCLocale(cmd *exec.Cmd) *exec.Cmd {
// Sadf -p -- -p <option> tmpFile
//
// and parses the output to add it to the telegraf.Accumulator acc.
func (s *Sysstat) parse(acc telegraf.Accumulator, option string, tmpfile string, ts time.Time) error {
func (s *Sysstat) parse(acc telegraf.Accumulator, option, tmpfile string, ts time.Time) error {
cmd := execCommand(s.Sadf, s.sadfOptions(option, tmpfile)...)
cmd = withCLocale(cmd)
stdout, err := cmd.StdoutPipe()
Expand Down Expand Up @@ -282,7 +282,7 @@ func (s *Sysstat) parse(acc telegraf.Accumulator, option string, tmpfile string,
}

// sadfOptions creates the correct options for the sadf utility.
func (s *Sysstat) sadfOptions(activityOption string, tmpfile string) []string {
func (s *Sysstat) sadfOptions(activityOption, tmpfile string) []string {
options := []string{
"-p",
"--",
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/system/mock_PS.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (m *MockPS) CPUTimes(_, _ bool) ([]cpu.TimesStat, error) {
return r0, r1
}

func (m *MockPS) DiskUsage(mountPointFilter []string, mountOptsExclude []string, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
func (m *MockPS) DiskUsage(mountPointFilter, mountOptsExclude, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
ret := m.Called(mountPointFilter, mountOptsExclude, fstypeExclude)

r0 := ret.Get(0).([]*disk.UsageStat)
Expand Down
6 changes: 1 addition & 5 deletions plugins/inputs/system/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ func newSet() *set {
return s
}

func (s *SystemPS) DiskUsage(
mountPointFilter []string,
mountOptsExclude []string,
fstypeExclude []string,
) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
func (s *SystemPS) DiskUsage(mountPointFilter, mountOptsExclude, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
parts, err := s.Partitions(true)
if err != nil {
return nil, nil, err
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/vsphere/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (c *Client) CounterInfoByKey(ctx context.Context) (map[int32]*types.PerfCou
}

// ListResources wraps property.Collector.Retrieve to give it proper timeouts
func (c *Client) ListResources(ctx context.Context, root *view.ContainerView, kind []string, ps []string, dst interface{}) error {
func (c *Client) ListResources(ctx context.Context, root *view.ContainerView, kind, ps []string, dst interface{}) error {
ctx1, cancel1 := context.WithTimeout(ctx, c.Timeout)
defer cancel1()
return root.Retrieve(ctx1, kind, ps, dst)
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/vsphere/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,15 @@ func anythingEnabled(ex []string) bool {
return true
}

func newFilterOrPanic(include []string, exclude []string) filter.Filter {
func newFilterOrPanic(include, exclude []string) filter.Filter {
f, err := filter.NewIncludeExcludeFilter(include, exclude)
if err != nil {
panic(fmt.Sprintf("Include/exclude filters are invalid: %v", err))
}
return f
}

func isSimple(include []string, exclude []string) bool {
func isSimple(include, exclude []string) bool {
if len(exclude) > 0 || len(include) == 0 {
return false
}
Expand Down Expand Up @@ -998,7 +998,7 @@ func submitChunkJob(ctx context.Context, te *ThrottledExecutor, job queryJob, pq
})
}

func (e *Endpoint) chunkify(ctx context.Context, res *resourceKind, now time.Time, latest time.Time, job queryJob) {
func (e *Endpoint) chunkify(ctx context.Context, res *resourceKind, now, latest time.Time, job queryJob) {
te := NewThrottledExecutor(e.Parent.CollectConcurrency)
maxMetrics := e.Parent.MaxQueryMetrics
if maxMetrics < 1 {
Expand Down Expand Up @@ -1414,7 +1414,7 @@ func (e *Endpoint) populateTags(objectRef *objectRef, resourceType string, resou
}
}

func (e *Endpoint) makeMetricIdentifier(prefix, metric string) (metricName string, fieldName string) {
func (e *Endpoint) makeMetricIdentifier(prefix, metric string) (metricName, fieldName string) {
parts := strings.Split(metric, ".")
if len(parts) == 1 {
return prefix, parts[0]
Expand Down
Loading

0 comments on commit 358224f

Please sign in to comment.