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/[s-z]`
  • Loading branch information
zak-pawel committed Dec 17, 2024
1 parent e2b5a99 commit e801876
Show file tree
Hide file tree
Showing 36 changed files with 99 additions and 138 deletions.
12 changes: 6 additions & 6 deletions plugins/inputs/sflow/packetdecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ func (d *packetDecoder) decodeIPv4Header(r io.Reader) (h ipV4Header, err error)
}
switch h.Protocol {
case ipProtocolTCP:
h.ProtocolHeader, err = d.decodeTCPHeader(r)
h.ProtocolHeader, err = decodeTCPHeader(r)
case ipProtocolUDP:
h.ProtocolHeader, err = d.decodeUDPHeader(r)
h.ProtocolHeader, err = decodeUDPHeader(r)
default:
d.debug("Unknown IP protocol: ", h.Protocol)
}
Expand Down Expand Up @@ -412,9 +412,9 @@ func (d *packetDecoder) decodeIPv6Header(r io.Reader) (h ipV6Header, err error)
}
switch h.NextHeaderProto {
case ipProtocolTCP:
h.ProtocolHeader, err = d.decodeTCPHeader(r)
h.ProtocolHeader, err = decodeTCPHeader(r)
case ipProtocolUDP:
h.ProtocolHeader, err = d.decodeUDPHeader(r)
h.ProtocolHeader, err = decodeUDPHeader(r)
default:
// not handled
d.debug("Unknown IP protocol: ", h.NextHeaderProto)
Expand All @@ -423,7 +423,7 @@ func (d *packetDecoder) decodeIPv6Header(r io.Reader) (h ipV6Header, err error)
}

// https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure
func (d *packetDecoder) decodeTCPHeader(r io.Reader) (h tcpHeader, err error) {
func decodeTCPHeader(r io.Reader) (h tcpHeader, err error) {
if err := read(r, &h.SourcePort, "SourcePort"); err != nil {
return h, err
}
Expand Down Expand Up @@ -461,7 +461,7 @@ func (d *packetDecoder) decodeTCPHeader(r io.Reader) (h tcpHeader, err error) {
return h, err
}

func (d *packetDecoder) decodeUDPHeader(r io.Reader) (h udpHeader, err error) {
func decodeUDPHeader(r io.Reader) (h udpHeader, err error) {
if err := read(r, &h.SourcePort, "SourcePort"); err != nil {
return h, err
}
Expand Down
7 changes: 2 additions & 5 deletions plugins/inputs/sflow/packetdecoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ func TestUDPHeader(t *testing.T) {
0x00, 0x00, // checksum
})

dc := newDecoder()
actual, err := dc.decodeUDPHeader(octets)
actual, err := decodeUDPHeader(octets)
require.NoError(t, err)

expected := udpHeader{
Expand All @@ -36,11 +35,9 @@ func BenchmarkUDPHeader(b *testing.B) {
0x00, 0x00, // checksum
})

dc := newDecoder()

b.ResetTimer()
for n := 0; n < b.N; n++ {
_, err := dc.decodeUDPHeader(octets)
_, err := decodeUDPHeader(octets)
require.NoError(b, err)
}
}
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 @@ -84,7 +84,7 @@ func (s *SFlow) Start(acc telegraf.Accumulator) error {
}

// Gather is a NOOP for sFlow as it receives, asynchronously, sFlow network packets
func (s *SFlow) Gather(_ telegraf.Accumulator) error {
func (*SFlow) Gather(telegraf.Accumulator) error {
return nil
}

Expand Down
4 changes: 0 additions & 4 deletions plugins/inputs/slab/slab.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ func (*SlabStats) SampleConfig() string {
return sampleConfig
}

func (ss *SlabStats) Init() error {
return nil
}

func (ss *SlabStats) Gather(acc telegraf.Accumulator) error {
fields, err := ss.getSlabStats()
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions plugins/inputs/slurm/slurm.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *Slurm) Init() error {
return nil
}

func (s *Slurm) parseTres(tres string) map[string]interface{} {
func parseTres(tres string) map[string]interface{} {
tresKVs := strings.Split(tres, ",")
parsedValues := make(map[string]interface{}, len(tresKVs))

Expand Down Expand Up @@ -258,7 +258,7 @@ func (s *Slurm) gatherJobsMetrics(acc telegraf.Accumulator, jobs []goslurm.V0038
records["time_limit"] = *int64Ptr
}
if strPtr, ok := jobs[i].GetTresReqStrOk(); ok {
for k, v := range s.parseTres(*strPtr) {
for k, v := range parseTres(*strPtr) {
records["tres_"+k] = v
}
}
Expand Down Expand Up @@ -302,12 +302,12 @@ func (s *Slurm) gatherNodesMetrics(acc telegraf.Accumulator, nodes []goslurm.V00
records["alloc_memory"] = *int64Ptr
}
if strPtr, ok := node.GetTresOk(); ok {
for k, v := range s.parseTres(*strPtr) {
for k, v := range parseTres(*strPtr) {
records["tres_"+k] = v
}
}
if strPtr, ok := node.GetTresUsedOk(); ok {
for k, v := range s.parseTres(*strPtr) {
for k, v := range parseTres(*strPtr) {
records["tres_used_"+k] = v
}
}
Expand Down Expand Up @@ -348,7 +348,7 @@ func (s *Slurm) gatherPartitionsMetrics(acc telegraf.Accumulator, partitions []g
records["nodes"] = *strPtr
}
if strPtr, ok := partition.GetTresOk(); ok {
for k, v := range s.parseTres(*strPtr) {
for k, v := range parseTres(*strPtr) {
records["tres_"+k] = v
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/snmp/snmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (tsc *testSNMPConnection) Walk(oid string, wf gosnmp.WalkFunc) error {
}
return nil
}
func (tsc *testSNMPConnection) Reconnect() error {
func (*testSNMPConnection) Reconnect() error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/snmp_trap/gosmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type gosmiTranslator struct {
}

func (t *gosmiTranslator) lookup(oid string) (snmp.MibEntry, error) {
func (*gosmiTranslator) lookup(oid string) (snmp.MibEntry, error) {
return snmp.TrapLookup(oid)
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/snmp_trap/snmp_trap.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (*SnmpTrap) SampleConfig() string {
return sampleConfig
}

func (s *SnmpTrap) Gather(_ telegraf.Accumulator) error {
func (*SnmpTrap) Gather(telegraf.Accumulator) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/socket_listener/socket_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (sl *SocketListener) Init() error {
return nil
}

func (sl *SocketListener) Gather(_ telegraf.Accumulator) error {
func (*SocketListener) Gather(telegraf.Accumulator) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/solr/solr.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s *Solr) Start(_ telegraf.Accumulator) error {
return nil
}

func (s *Solr) Stop() {}
func (*Solr) Stop() {}

func (s *Solr) Gather(acc telegraf.Accumulator) error {
var wg sync.WaitGroup
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/sqlserver/sqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (s *SQLServer) Gather(acc telegraf.Accumulator) error {

if s.HealthMetric {
mutex.Lock()
s.gatherHealth(healthMetrics, dsn, queryError)
gatherHealth(healthMetrics, dsn, queryError)
mutex.Unlock()
}

Expand Down Expand Up @@ -425,7 +425,7 @@ func (s *SQLServer) accRow(query Query, acc telegraf.Accumulator, row scanner) e
}

// gatherHealth stores info about any query errors in the healthMetrics map
func (s *SQLServer) gatherHealth(healthMetrics map[string]*HealthMetric, serv string, queryError error) {
func gatherHealth(healthMetrics map[string]*HealthMetric, serv string, queryError error) {
if healthMetrics[serv] == nil {
healthMetrics[serv] = &HealthMetric{}
}
Expand Down
8 changes: 3 additions & 5 deletions plugins/inputs/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ func (s *stackdriver) gatherTimeSeries(

if tsDesc.ValueType == metricpb.MetricDescriptor_DISTRIBUTION {
dist := p.Value.GetDistributionValue()
if err := s.addDistribution(dist, tags, ts, grouper, tsConf); err != nil {
if err := addDistribution(dist, tags, ts, grouper, tsConf); err != nil {
return err
}
} else {
Expand Down Expand Up @@ -666,10 +666,8 @@ func NewBucket(dist *distributionpb.Distribution) (buckets, error) {
return nil, errors.New("no buckets available")
}

// AddDistribution adds metrics from a distribution value type.
func (s *stackdriver) addDistribution(dist *distributionpb.Distribution, tags map[string]string, ts time.Time,
grouper *lockedSeriesGrouper, tsConf *timeSeriesConf,
) error {
// addDistribution adds metrics from a distribution value type.
func addDistribution(dist *distributionpb.Distribution, tags map[string]string, ts time.Time, grouper *lockedSeriesGrouper, tsConf *timeSeriesConf) error {
field := tsConf.fieldKey
name := tsConf.measurement

Expand Down
6 changes: 1 addition & 5 deletions plugins/inputs/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ type supervisorInfo struct {
//go:embed sample.conf
var sampleConfig string

func (s *Supervisor) Description() string {
return "Gather info about processes state, that running under supervisor using its XML-RPC API"
}

func (s *Supervisor) SampleConfig() string {
func (*Supervisor) SampleConfig() string {
return sampleConfig
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/suricata/suricata.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (s *Suricata) parse(acc telegraf.Accumulator, sjson []byte) error {

// Gather measures and submits one full set of telemetry to Telegraf.
// Not used here, submission is completely input-driven.
func (s *Suricata) Gather(_ telegraf.Accumulator) error {
func (*Suricata) Gather(telegraf.Accumulator) error {
return nil
}

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 @@ -199,7 +199,7 @@ func withCLocale(cmd *exec.Cmd) *exec.Cmd {
//
// and parses the output to add it to the telegraf.Accumulator acc.
func (s *Sysstat) parse(acc telegraf.Accumulator, option, tmpfile string, ts time.Time) error {
cmd := execCommand(s.Sadf, s.sadfOptions(option, tmpfile)...)
cmd := execCommand(s.Sadf, sadfOptions(option, tmpfile)...)
cmd = withCLocale(cmd)
stdout, err := cmd.StdoutPipe()
if err != nil {
Expand Down Expand Up @@ -282,7 +282,7 @@ func (s *Sysstat) parse(acc telegraf.Accumulator, option, tmpfile string, ts tim
}

// sadfOptions creates the correct options for the sadf utility.
func (s *Sysstat) sadfOptions(activityOption, tmpfile string) []string {
func sadfOptions(activityOption, tmpfile string) []string {
options := []string{
"-p",
"--",
Expand Down
24 changes: 12 additions & 12 deletions plugins/inputs/system/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type SystemPS struct {

type SystemPSDisk struct{}

func (s *SystemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) {
func (*SystemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) {
var cpuTimes []cpu.TimesStat
if perCPU {
perCPUTimes, err := cpu.Times(true)
Expand Down Expand Up @@ -175,23 +175,23 @@ partitionRange:
return usage, partitions, nil
}

func (s *SystemPS) NetProto() ([]net.ProtoCountersStat, error) {
func (*SystemPS) NetProto() ([]net.ProtoCountersStat, error) {
return net.ProtoCounters(nil)
}

func (s *SystemPS) NetIO() ([]net.IOCountersStat, error) {
func (*SystemPS) NetIO() ([]net.IOCountersStat, error) {
return net.IOCounters(true)
}

func (s *SystemPS) NetConnections() ([]net.ConnectionStat, error) {
func (*SystemPS) NetConnections() ([]net.ConnectionStat, error) {
return net.Connections("all")
}

func (s *SystemPS) NetConntrack(perCPU bool) ([]net.ConntrackStat, error) {
func (*SystemPS) NetConntrack(perCPU bool) ([]net.ConntrackStat, error) {
return net.ConntrackStats(perCPU)
}

func (s *SystemPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error) {
func (*SystemPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error) {
m, err := disk.IOCounters(names...)
if errors.Is(err, internal.ErrNotImplemented) {
return nil, nil
Expand All @@ -200,26 +200,26 @@ func (s *SystemPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error
return m, err
}

func (s *SystemPS) VMStat() (*mem.VirtualMemoryStat, error) {
func (*SystemPS) VMStat() (*mem.VirtualMemoryStat, error) {
return mem.VirtualMemory()
}

func (s *SystemPS) SwapStat() (*mem.SwapMemoryStat, error) {
func (*SystemPS) SwapStat() (*mem.SwapMemoryStat, error) {
return mem.SwapMemory()
}

func (s *SystemPSDisk) Partitions(all bool) ([]disk.PartitionStat, error) {
func (*SystemPSDisk) Partitions(all bool) ([]disk.PartitionStat, error) {
return disk.Partitions(all)
}

func (s *SystemPSDisk) OSGetenv(key string) string {
func (*SystemPSDisk) OSGetenv(key string) string {
return os.Getenv(key)
}

func (s *SystemPSDisk) OSStat(name string) (os.FileInfo, error) {
func (*SystemPSDisk) OSStat(name string) (os.FileInfo, error) {
return os.Stat(name)
}

func (s *SystemPSDisk) PSDiskUsage(path string) (*disk.UsageStat, error) {
func (*SystemPSDisk) PSDiskUsage(path string) (*disk.UsageStat, error) {
return disk.Usage(path)
}
12 changes: 6 additions & 6 deletions plugins/inputs/tacacs/tacacs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Tacacs struct {
//go:embed sample.conf
var sampleConfig string

func (t *Tacacs) SampleConfig() string {
func (*Tacacs) SampleConfig() string {
return sampleConfig
}

Expand Down Expand Up @@ -74,7 +74,7 @@ func (t *Tacacs) Init() error {
return nil
}

func (t *Tacacs) AuthenReplyToString(code uint8) string {
func AuthenReplyToString(code uint8) string {
switch code {
case tacplus.AuthenStatusPass:
return `AuthenStatusPass`
Expand Down Expand Up @@ -157,7 +157,7 @@ func (t *Tacacs) pollServer(acc telegraf.Accumulator, client *tacplus.Client) er
defer session.Close()
if reply.Status != tacplus.AuthenStatusGetUser {
fields["responsetime_ms"] = time.Since(startTime).Milliseconds()
fields["response_status"] = t.AuthenReplyToString(reply.Status)
fields["response_status"] = AuthenReplyToString(reply.Status)
acc.AddFields("tacacs", fields, tags)
return nil
}
Expand All @@ -174,7 +174,7 @@ func (t *Tacacs) pollServer(acc telegraf.Accumulator, client *tacplus.Client) er
}
if reply.Status != tacplus.AuthenStatusGetPass {
fields["responsetime_ms"] = time.Since(startTime).Milliseconds()
fields["response_status"] = t.AuthenReplyToString(reply.Status)
fields["response_status"] = AuthenReplyToString(reply.Status)
acc.AddFields("tacacs", fields, tags)
return nil
}
Expand All @@ -191,13 +191,13 @@ func (t *Tacacs) pollServer(acc telegraf.Accumulator, client *tacplus.Client) er
}
if reply.Status != tacplus.AuthenStatusPass {
fields["responsetime_ms"] = time.Since(startTime).Milliseconds()
fields["response_status"] = t.AuthenReplyToString(reply.Status)
fields["response_status"] = AuthenReplyToString(reply.Status)
acc.AddFields("tacacs", fields, tags)
return nil
}

fields["responsetime_ms"] = time.Since(startTime).Milliseconds()
fields["response_status"] = t.AuthenReplyToString(reply.Status)
fields["response_status"] = AuthenReplyToString(reply.Status)
acc.AddFields("tacacs", fields, tags)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/tail/multiline.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (m *Multiline) ProcessLine(text string, buffer *bytes.Buffer) string {
return text
}

func (m *Multiline) Flush(buffer *bytes.Buffer) string {
func Flush(buffer *bytes.Buffer) string {
if buffer.Len() == 0 {
return ""
}
Expand Down
Loading

0 comments on commit e801876

Please sign in to comment.