From 358224fa02fa9582a63daece758c8a4255e3af03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=BBak?= Date: Thu, 12 Sep 2024 22:59:30 +0200 Subject: [PATCH] chore: Fix linter findings for `revive:enforce-repeated-arg-type-style` in `plugins/inputs/[o-z]*` (#15857) --- .../inputs/openweathermap/openweathermap.go | 2 +- plugins/inputs/phpfpm/fcgi.go | 2 +- plugins/inputs/phpfpm/fcgi_client.go | 2 +- plugins/inputs/phpfpm/phpfpm.go | 2 +- plugins/inputs/ping/ping_notwindows.go | 4 +-- plugins/inputs/proxmox/proxmox.go | 4 +-- plugins/inputs/proxmox/proxmox_test.go | 2 +- plugins/inputs/redis/redis.go | 35 +++---------------- .../inputs/redis_sentinel/redis_sentinel.go | 6 +--- .../redis_sentinel/redis_sentinel_test.go | 2 +- plugins/inputs/sflow/sflow.go | 2 +- plugins/inputs/smart/smart.go | 2 +- plugins/inputs/smartctl/smartctl_device.go | 2 +- plugins/inputs/snmp_trap/snmp_trap_test.go | 4 +-- plugins/inputs/socketstat/socketstat.go | 2 +- plugins/inputs/sqlserver/connectionstring.go | 6 ++-- plugins/inputs/stackdriver/stackdriver.go | 2 +- plugins/inputs/statsd/datadog.go | 2 +- plugins/inputs/statsd/statsd.go | 4 +-- plugins/inputs/sysstat/sysstat.go | 4 +-- plugins/inputs/system/mock_PS.go | 2 +- plugins/inputs/system/ps.go | 6 +--- plugins/inputs/vsphere/client.go | 2 +- plugins/inputs/vsphere/endpoint.go | 8 ++--- plugins/inputs/vsphere/tscache.go | 8 ++--- plugins/inputs/vsphere/vsan.go | 4 +-- .../artifactory/artifactory_webhook.go | 2 +- .../artifactory/artifactory_webhook_test.go | 6 ++-- .../webhooks/github/github_webhooks_test.go | 8 ++--- .../webhooks/papertrail/papertrail_test.go | 2 +- 30 files changed, 53 insertions(+), 86 deletions(-) diff --git a/plugins/inputs/openweathermap/openweathermap.go b/plugins/inputs/openweathermap/openweathermap.go index 35dac0e52588d..6543b113abcb2 100644 --- a/plugins/inputs/openweathermap/openweathermap.go +++ b/plugins/inputs/openweathermap/openweathermap.go @@ -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}, diff --git a/plugins/inputs/phpfpm/fcgi.go b/plugins/inputs/phpfpm/fcgi.go index e0208196592db..9b5c526333b7a 100644 --- a/plugins/inputs/phpfpm/fcgi.go +++ b/plugins/inputs/phpfpm/fcgi.go @@ -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[:]) } diff --git a/plugins/inputs/phpfpm/fcgi_client.go b/plugins/inputs/phpfpm/fcgi_client.go index 05d975a62cac0..f33b68d0af9a5 100644 --- a/plugins/inputs/phpfpm/fcgi_client.go +++ b/plugins/inputs/phpfpm/fcgi_client.go @@ -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 diff --git a/plugins/inputs/phpfpm/phpfpm.go b/plugins/inputs/phpfpm/phpfpm.go index 2f21e4e74ec2e..e1b3ce515fd30 100644 --- a/plugins/inputs/phpfpm/phpfpm.go +++ b/plugins/inputs/phpfpm/phpfpm.go @@ -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] diff --git a/plugins/inputs/ping/ping_notwindows.go b/plugins/inputs/ping/ping_notwindows.go index 1ba0026a6e30b..eb7fee33f0206 100644 --- a/plugins/inputs/ping/ping_notwindows.go +++ b/plugins/inputs/ping/ping_notwindows.go @@ -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) } @@ -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, ", ") diff --git a/plugins/inputs/proxmox/proxmox.go b/plugins/inputs/proxmox/proxmox.go index e9c5d36a8f4c3..3ba47f5894d4a 100644 --- a/plugins/inputs/proxmox/proxmox.go +++ b/plugins/inputs/proxmox/proxmox.go @@ -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 @@ -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 diff --git a/plugins/inputs/proxmox/proxmox_test.go b/plugins/inputs/proxmox/proxmox_test.go index 9e96c87255f7d..ae3f1cbda9d8a 100644 --- a/plugins/inputs/proxmox/proxmox_test.go +++ b/plugins/inputs/proxmox/proxmox_test.go @@ -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") { diff --git a/plugins/inputs/redis/redis.go b/plugins/inputs/redis/redis.go index ee577e7a63188..a4142e6787a9c 100644 --- a/plugins/inputs/redis/redis.go +++ b/plugins/inputs/redis/redis.go @@ -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) @@ -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 } @@ -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 } @@ -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 { @@ -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 diff --git a/plugins/inputs/redis_sentinel/redis_sentinel.go b/plugins/inputs/redis_sentinel/redis_sentinel.go index 2edc589a37bf6..3443d736f70f2 100644 --- a/plugins/inputs/redis_sentinel/redis_sentinel.go +++ b/plugins/inputs/redis_sentinel/redis_sentinel.go @@ -328,11 +328,7 @@ func (client *RedisSentinelClient) gatherSentinelStats(acc telegraf.Accumulator, } // converts `sentinel masters ` 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"] diff --git a/plugins/inputs/redis_sentinel/redis_sentinel_test.go b/plugins/inputs/redis_sentinel/redis_sentinel_test.go index 855763621ff6c..a325bb97a4732 100644 --- a/plugins/inputs/redis_sentinel/redis_sentinel_test.go +++ b/plugins/inputs/redis_sentinel/redis_sentinel_test.go @@ -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}, diff --git a/plugins/inputs/sflow/sflow.go b/plugins/inputs/sflow/sflow.go index 368647afc1ce0..74a98721432ee 100644 --- a/plugins/inputs/sflow/sflow.go +++ b/plugins/inputs/sflow/sflow.go @@ -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) diff --git a/plugins/inputs/smart/smart.go b/plugins/inputs/smart/smart.go index 18d9fa856731b..b595cf62bc3b6 100644 --- a/plugins/inputs/smart/smart.go +++ b/plugins/inputs/smart/smart.go @@ -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 { diff --git a/plugins/inputs/smartctl/smartctl_device.go b/plugins/inputs/smartctl/smartctl_device.go index 898cd8660b9cf..7bbb37ef82c31 100644 --- a/plugins/inputs/smartctl/smartctl_device.go +++ b/plugins/inputs/smartctl/smartctl_device.go @@ -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 { diff --git a/plugins/inputs/snmp_trap/snmp_trap_test.go b/plugins/inputs/snmp_trap/snmp_trap_test.go index 54323b3f8bc42..43e2b16bf327a 100644 --- a/plugins/inputs/snmp_trap/snmp_trap_test.go +++ b/plugins/inputs/snmp_trap/snmp_trap_test.go @@ -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": @@ -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, diff --git a/plugins/inputs/socketstat/socketstat.go b/plugins/inputs/socketstat/socketstat.go index 400bd512dee9f..d12081b99199b 100644 --- a/plugins/inputs/socketstat/socketstat.go +++ b/plugins/inputs/socketstat/socketstat.go @@ -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...) diff --git a/plugins/inputs/sqlserver/connectionstring.go b/plugins/inputs/sqlserver/connectionstring.go index 06d08653c17ee..dcdc7235fa0e7 100644 --- a/plugins/inputs/sqlserver/connectionstring.go +++ b/plugins/inputs/sqlserver/connectionstring.go @@ -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 } @@ -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 = "" @@ -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) diff --git a/plugins/inputs/stackdriver/stackdriver.go b/plugins/inputs/stackdriver/stackdriver.go index 2105acd1c4758..e257dcc43e218 100644 --- a/plugins/inputs/stackdriver/stackdriver.go +++ b/plugins/inputs/stackdriver/stackdriver.go @@ -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) { diff --git a/plugins/inputs/statsd/datadog.go b/plugins/inputs/statsd/datadog.go index 88612649e840a..aee163fc197b3 100644 --- a/plugins/inputs/statsd/datadog.go +++ b/plugins/inputs/statsd/datadog.go @@ -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 diff --git a/plugins/inputs/statsd/statsd.go b/plugins/inputs/statsd/statsd.go index 15bf523928bc7..1aee72160f0c4 100644 --- a/plugins/inputs/statsd/statsd.go +++ b/plugins/inputs/statsd/statsd.go @@ -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 (, , ) -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) @@ -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 { diff --git a/plugins/inputs/sysstat/sysstat.go b/plugins/inputs/sysstat/sysstat.go index 834e9451325a2..37a9e6be3e8ef 100644 --- a/plugins/inputs/sysstat/sysstat.go +++ b/plugins/inputs/sysstat/sysstat.go @@ -198,7 +198,7 @@ func withCLocale(cmd *exec.Cmd) *exec.Cmd { // Sadf -p -- -p