Skip to content

Commit

Permalink
chore: Fix linter findings for revive:unused-receiver in `plugins/i…
Browse files Browse the repository at this point in the history
…nputs/[f-k]` (#16308)
  • Loading branch information
zak-pawel authored Dec 17, 2024
1 parent c0b3dd4 commit 6f80899
Show file tree
Hide file tree
Showing 46 changed files with 104 additions and 141 deletions.
2 changes: 1 addition & 1 deletion plugins/inputs/filecount/filesystem_helpers_notwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (f fakeFileInfo) ModTime() time.Time { return f.modtime }
func (f fakeFileInfo) IsDir() bool { return f.isdir }
func (f fakeFileInfo) Sys() interface{} { return f.sys }

func (f fakeFileSystem) open(name string) (file, error) {
func (fakeFileSystem) open(name string) (file, error) {
return nil, &os.PathError{Op: "Open", Path: name, Err: errors.New("not implemented by fake filesystem")}
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/fireboard/fireboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (r *Fireboard) Gather(acc telegraf.Accumulator) error {
}
// Range over all devices, gathering stats. Returns early in case of any error.
for _, s := range stats {
r.gatherTemps(s, acc)
gatherTemps(s, acc)
}
return nil
}
Expand All @@ -105,7 +105,7 @@ func scale(n int) string {
}

// Gathers stats from a single device, adding them to the accumulator
func (r *Fireboard) gatherTemps(s fireboardStats, acc telegraf.Accumulator) {
func gatherTemps(s fireboardStats, acc telegraf.Accumulator) {
// Construct lookup for scale values

for _, t := range s.LatestTemps {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/gnmi/gnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (c *GNMI) Start(acc telegraf.Accumulator) error {
return nil
}

func (c *GNMI) Gather(_ telegraf.Accumulator) error {
func (*GNMI) Gather(telegraf.Accumulator) error {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/gnmi/gnmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ type mockServer struct {
grpcServer *grpc.Server
}

func (s *mockServer) Capabilities(context.Context, *gnmi.CapabilityRequest) (*gnmi.CapabilityResponse, error) {
func (*mockServer) Capabilities(context.Context, *gnmi.CapabilityRequest) (*gnmi.CapabilityResponse, error) {
return nil, nil
}

func (s *mockServer) Get(context.Context, *gnmi.GetRequest) (*gnmi.GetResponse, error) {
func (*mockServer) Get(context.Context, *gnmi.GetRequest) (*gnmi.GetResponse, error) {
return nil, nil
}

func (s *mockServer) Set(context.Context, *gnmi.SetRequest) (*gnmi.SetResponse, error) {
func (*mockServer) Set(context.Context, *gnmi.SetRequest) (*gnmi.SetResponse, error) {
return nil, nil
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/gnmi/tag_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *tagStore) insert(subscription tagSubscription, path *pathInfo, values [
}
}
case "elements":
key, match := s.getElementsKeys(path, subscription.Elements)
key, match := getElementsKeys(path, subscription.Elements)
if !match || len(values) == 0 {
return nil
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func (s *tagStore) lookup(path *pathInfo, metricTags map[string]string) map[stri

// Match elements
for _, requiredKeys := range s.elements.required {
key, match := s.getElementsKeys(path, requiredKeys)
key, match := getElementsKeys(path, requiredKeys)
if !match {
continue
}
Expand All @@ -153,7 +153,7 @@ func (s *tagStore) lookup(path *pathInfo, metricTags map[string]string) map[stri
return tags
}

func (s *tagStore) getElementsKeys(path *pathInfo, elements []string) (string, bool) {
func getElementsKeys(path *pathInfo, elements []string) (string, bool) {
// Search for the required path elements and collect a ordered
// list of their values to in the form
// elementName1={keyA=valueA,keyB=valueB,...},...,elementNameN={keyY=valueY,keyZ=valueZ}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (gcs *GCS) Init() error {
return gcs.setOffset()
}

func (gcs *GCS) SampleConfig() string {
func (*GCS) SampleConfig() string {
return sampleConfig
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/graylog/graylog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ func (c *mockHTTPClient) makeRequest(req *http.Request) (*http.Response, error)
return &resp, nil
}

func (c *mockHTTPClient) setHTTPClient(_ *http.Client) {
func (*mockHTTPClient) setHTTPClient(*http.Client) {
}

func (c *mockHTTPClient) httpClient() *http.Client {
func (*mockHTTPClient) httpClient() *http.Client {
return nil
}

Expand Down
10 changes: 3 additions & 7 deletions plugins/inputs/haproxy/haproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import (
"github.com/influxdata/telegraf/testutil"
)

type statServer struct{}

func (s statServer) serverSocket(l net.Listener) {
func serverSocket(l net.Listener) {
for {
conn, err := l.Accept()
if err != nil {
Expand Down Expand Up @@ -151,8 +149,7 @@ func TestHaproxyGeneratesMetricsUsingSocket(t *testing.T) {
sockets[i] = sock
defer sock.Close() //nolint:revive,gocritic // done on purpose, closing will be executed properly

s := statServer{}
go s.serverSocket(sock)
go serverSocket(sock)
}

r := &HAProxy{
Expand Down Expand Up @@ -191,8 +188,7 @@ func TestHaproxyGeneratesMetricsUsingTcp(t *testing.T) {
}
defer l.Close()

s := statServer{}
go s.serverSocket(l)
go serverSocket(l)

r := &HAProxy{
Servers: []string{"tcp://" + l.Addr().String()},
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/hddtemp/go-hddtemp/hddtemp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func New() *hddtemp {
}

// Fetch gathers disks data from hddtemp daemon.
func (h *hddtemp) Fetch(address string) ([]Disk, error) {
func (*hddtemp) Fetch(address string) ([]Disk, error) {
var (
err error
conn net.Conn
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/hddtemp/hddtemp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type mockFetcher struct {
}

func (h *mockFetcher) Fetch(_ string) ([]hddtemp.Disk, error) {
func (*mockFetcher) Fetch(string) ([]hddtemp.Disk, error) {
return []hddtemp.Disk{
{
DeviceName: "Disk1",
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (h *HTTP) SetParserFunc(fn telegraf.ParserFunc) {
h.parserFunc = fn
}

func (h *HTTP) Start(_ telegraf.Accumulator) error {
func (*HTTP) Start(telegraf.Accumulator) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/http_listener_v2/http_listener_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (h *HTTPListenerV2) Start(acc telegraf.Accumulator) error {
return nil
}

func (h *HTTPListenerV2) Gather(_ telegraf.Accumulator) error {
func (*HTTPListenerV2) Gather(telegraf.Accumulator) error {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/hugepages/hugepages.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (h *Hugepages) Gather(acc telegraf.Accumulator) error {

// gatherStatsPerNode collects root hugepages statistics
func (h *Hugepages) gatherRootStats(acc telegraf.Accumulator) error {
return h.gatherFromHugepagePath(acc, "hugepages_"+rootHugepages, h.rootHugepagePath, hugepagesMetricsRoot, nil)
return gatherFromHugepagePath(acc, "hugepages_"+rootHugepages, h.rootHugepagePath, hugepagesMetricsRoot, nil)
}

// gatherStatsPerNode collects hugepages statistics per NUMA node
Expand All @@ -144,15 +144,15 @@ func (h *Hugepages) gatherStatsPerNode(acc telegraf.Accumulator) error {
"node": nodeNumber,
}
hugepagesPath := filepath.Join(h.numaNodePath, nodeDir.Name(), "hugepages")
err = h.gatherFromHugepagePath(acc, "hugepages_"+perNodeHugepages, hugepagesPath, hugepagesMetricsPerNUMANode, perNodeTags)
err = gatherFromHugepagePath(acc, "hugepages_"+perNodeHugepages, hugepagesPath, hugepagesMetricsPerNUMANode, perNodeTags)
if err != nil {
return err
}
}
return nil
}

func (h *Hugepages) gatherFromHugepagePath(acc telegraf.Accumulator, measurement, path string, fileFilter, defaultTags map[string]string) error {
func gatherFromHugepagePath(acc telegraf.Accumulator, measurement, path string, fileFilter, defaultTags map[string]string) error {
// read metrics from: hugepages/hugepages-*/*
hugepagesDirs, err := os.ReadDir(path)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions plugins/inputs/icinga2/icinga2.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (i *Icinga2) Gather(acc telegraf.Accumulator) error {
}

result := resultObject{}
err = i.parseObjectResponse(resp, &result)
err = parseObjectResponse(resp, &result)
if err != nil {
return fmt.Errorf("could not parse object response: %w", err)
}
Expand All @@ -145,13 +145,13 @@ func (i *Icinga2) Gather(acc telegraf.Accumulator) error {

switch statusType {
case "ApiListener":
fields, err = i.parsePerfdataResponse(resp)
fields, err = parsePerfdataResponse(resp)
case "CIB":
fields, err = i.parseCIBResponse(resp)
fields, err = parseCIBResponse(resp)
case "IdoMysqlConnection":
fields, err = i.parsePerfdataResponse(resp)
fields, err = parsePerfdataResponse(resp)
case "IdoPgsqlConnection":
fields, err = i.parsePerfdataResponse(resp)
fields, err = parsePerfdataResponse(resp)
}

if err != nil {
Expand Down Expand Up @@ -233,7 +233,7 @@ func (i *Icinga2) icingaRequest(address string) (*http.Response, error) {
return resp, nil
}

func (i *Icinga2) parseObjectResponse(resp *http.Response, result *resultObject) error {
func parseObjectResponse(resp *http.Response, result *resultObject) error {
err := json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
return err
Expand All @@ -246,7 +246,7 @@ func (i *Icinga2) parseObjectResponse(resp *http.Response, result *resultObject)
return nil
}

func (i *Icinga2) parseCIBResponse(resp *http.Response) (map[string]interface{}, error) {
func parseCIBResponse(resp *http.Response) (map[string]interface{}, error) {
result := resultCIB{}

err := json.NewDecoder(resp.Body).Decode(&result)
Expand All @@ -262,7 +262,7 @@ func (i *Icinga2) parseCIBResponse(resp *http.Response) (map[string]interface{},
return result.Results[0].Status, nil
}

func (i *Icinga2) parsePerfdataResponse(resp *http.Response) (map[string]interface{}, error) {
func parsePerfdataResponse(resp *http.Response) (map[string]interface{}, error) {
result := resultPerfdata{}

err := json.NewDecoder(resp.Body).Decode(&result)
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/infiniband/infiniband_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// Gather statistics from our infiniband cards
func (i *Infiniband) Gather(acc telegraf.Accumulator) error {
func (*Infiniband) Gather(acc telegraf.Accumulator) error {
rdmaDevices := rdmamap.GetRdmaDeviceList()

if len(rdmaDevices) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/influxdb_listener/influxdb_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (*InfluxDBListener) SampleConfig() string {
return sampleConfig
}

func (h *InfluxDBListener) Gather(_ telegraf.Accumulator) error {
func (*InfluxDBListener) Gather(telegraf.Accumulator) error {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (h *InfluxDBV2Listener) Init() error {
return nil
}

func (h *InfluxDBV2Listener) Gather(_ telegraf.Accumulator) error {
func (*InfluxDBV2Listener) Gather(telegraf.Accumulator) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/intel_baseband/intel_baseband.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Baseband struct {
sockConn *socketConnector
}

func (b *Baseband) SampleConfig() string {
func (*Baseband) SampleConfig() string {
return sampleConfig
}

Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/intel_baseband/log_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (lc *logConnector) readNumVFs() error {
continue
}

numVFs, err := lc.parseNumVFs(line)
numVFs, err := parseNumVFs(line)
if err != nil {
lc.numVFs = -1
return err
Expand Down Expand Up @@ -189,7 +189,7 @@ func (lc *logConnector) getMetric(offsetLine int, name string) (int, *logMetric,
return offsetLine, nil, err
}

operationName := lc.parseOperationName(line)
operationName := parseOperationName(line)
if len(operationName) == 0 {
return offsetLine, nil, errors.New("valid operation name wasn't found in log")
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func (lc *logConnector) getMetric(offsetLine int, name string) (int, *logMetric,
}

// Example value = Thu Apr 13 13:28:40 2023:INFO:Device Status:: 2 VFs
func (lc *logConnector) parseNumVFs(s string) (int, error) {
func parseNumVFs(s string) (int, error) {
i := strings.LastIndex(s, deviceStatusStartPrefix)
if i == -1 {
return 0, errors.New("couldn't find device status prefix in line")
Expand All @@ -244,7 +244,7 @@ func (lc *logConnector) parseNumVFs(s string) (int, error) {
// Parse Operation name
// Example = Thu Apr 13 13:28:40 2023:INFO:5GUL counters: Code Blocks
// Output: 5GUL
func (lc *logConnector) parseOperationName(s string) string {
func parseOperationName(s string) string {
i := strings.Index(s, infoLine)
if i >= 0 {
j := strings.Index(s[i:], countersLine)
Expand Down
4 changes: 1 addition & 3 deletions plugins/inputs/intel_baseband/log_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,9 @@ func TestParseOperationName(t *testing.T) {
{"", ""},
}

logConnector := prepareLogConnMock()
require.NotNil(t, logConnector)
for _, tc := range testCases {
t.Run("expected "+tc.expected, func(t *testing.T) {
operationName := logConnector.parseOperationName(tc.input)
operationName := parseOperationName(tc.input)
require.Equal(t, tc.expected, operationName)
})
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/intel_dlb/intel_dlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type IntelDLB struct {
maxInitMessageLength uint32
}

func (d *IntelDLB) SampleConfig() string {
func (*IntelDLB) SampleConfig() string {
return sampleConfig
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/intel_pmt/intel_pmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type fileInfo struct {
pciBdf string // PCI Bus:Device.Function (BDF)
}

func (p *IntelPMT) SampleConfig() string {
func (*IntelPMT) SampleConfig() string {
return sampleConfig
}

Expand Down
12 changes: 6 additions & 6 deletions plugins/inputs/intel_pmu/intel_pmu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,9 @@ type fakeFileInfo struct {
fileMode os.FileMode
}

func (f fakeFileInfo) Name() string { return "" }
func (f fakeFileInfo) Size() int64 { return 0 }
func (f fakeFileInfo) Mode() os.FileMode { return f.fileMode }
func (f fakeFileInfo) ModTime() time.Time { return time.Time{} }
func (f fakeFileInfo) IsDir() bool { return false }
func (f fakeFileInfo) Sys() interface{} { return nil }
func (fakeFileInfo) Name() string { return "" }
func (fakeFileInfo) Size() int64 { return 0 }
func (f fakeFileInfo) Mode() os.FileMode { return f.fileMode }
func (fakeFileInfo) ModTime() time.Time { return time.Time{} }
func (fakeFileInfo) IsDir() bool { return false }
func (fakeFileInfo) Sys() interface{} { return nil }
2 changes: 1 addition & 1 deletion plugins/inputs/intel_powerstat/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type optGenerator struct{}

// generate takes plugin configuration options and generates options needed
// to gather requested metrics.
func (g *optGenerator) generate(cfg optConfig) []ptel.Option {
func (*optGenerator) generate(cfg optConfig) []ptel.Option {
opts := make([]ptel.Option, 0)
if len(cfg.includedCPUs) != 0 {
opts = append(opts, ptel.WithIncludedCPUs(cfg.includedCPUs))
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/intel_rdt/intel_rdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (r *IntelRDT) Start(acc telegraf.Accumulator) error {
return nil
}

func (r *IntelRDT) Gather(_ telegraf.Accumulator) error {
func (*IntelRDT) Gather(telegraf.Accumulator) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/intel_rdt/intel_rdt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type mockProc struct{}

func (m *mockProc) getAllProcesses() ([]process, error) {
func (*mockProc) getAllProcesses() ([]process, error) {
procs := []process{
{Name: "process", PID: 1000},
{Name: "process2", PID: 1002},
Expand Down
Loading

0 comments on commit 6f80899

Please sign in to comment.