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/[l-r]` (#16325)
  • Loading branch information
zak-pawel authored Dec 18, 2024
1 parent e766c86 commit d829a5b
Show file tree
Hide file tree
Showing 44 changed files with 145 additions and 166 deletions.
2 changes: 1 addition & 1 deletion plugins/inputs/lanz/lanz.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (l *Lanz) Start(acc telegraf.Accumulator) error {
return nil
}

func (l *Lanz) Gather(_ telegraf.Accumulator) error {
func (*Lanz) Gather(telegraf.Accumulator) error {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/leofs/leofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (*LeoFS) SampleConfig() string {

func (l *LeoFS) Gather(acc telegraf.Accumulator) error {
if len(l.Servers) == 0 {
return l.gatherServer(defaultEndpoint, serverTypeManagerMaster, acc)
return gatherServer(defaultEndpoint, serverTypeManagerMaster, acc)
}
var wg sync.WaitGroup
for _, endpoint := range l.Servers {
Expand All @@ -185,14 +185,14 @@ func (l *LeoFS) Gather(acc telegraf.Accumulator) error {
wg.Add(1)
go func(endpoint string, st serverType) {
defer wg.Done()
acc.AddError(l.gatherServer(endpoint, st, acc))
acc.AddError(gatherServer(endpoint, st, acc))
}(endpoint, st)
}
wg.Wait()
return nil
}

func (l *LeoFS) gatherServer(endpoint string, serverType serverType, acc telegraf.Accumulator) error {
func gatherServer(endpoint string, serverType serverType, acc telegraf.Accumulator) error {
cmd := exec.Command("snmpwalk", "-v2c", "-cpublic", "-On", endpoint, oid)
stdout, err := cmd.StdoutPipe()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Libvirt struct {
domainsMap map[string]struct{}
}

func (l *Libvirt) SampleConfig() string {
func (*Libvirt) SampleConfig() string {
return sampleConfig
}

Expand Down
40 changes: 20 additions & 20 deletions plugins/inputs/libvirt/libvirt_metric_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ var (
)

func (l *Libvirt) addMetrics(stats []golibvirt.DomainStatsRecord, vcpuInfos map[string][]vcpuAffinity, acc telegraf.Accumulator) {
domainsMetrics := l.translateMetrics(stats)
domainsMetrics := translateMetrics(stats)

for domainName, metrics := range domainsMetrics {
for metricType, values := range metrics {
switch metricType {
case "state":
l.addStateMetrics(values, domainName, acc)
addStateMetrics(values, domainName, acc)
case "cpu":
l.addCPUMetrics(values, domainName, acc)
addCPUMetrics(values, domainName, acc)
case "balloon":
l.addBalloonMetrics(values, domainName, acc)
addBalloonMetrics(values, domainName, acc)
case "vcpu":
l.addVcpuMetrics(values, domainName, vcpuInfos[domainName], acc)
case "net":
l.addInterfaceMetrics(values, domainName, acc)
addInterfaceMetrics(values, domainName, acc)
case "perf":
l.addPerfMetrics(values, domainName, acc)
addPerfMetrics(values, domainName, acc)
case "block":
l.addBlockMetrics(values, domainName, acc)
addBlockMetrics(values, domainName, acc)
case "iothread":
l.addIothreadMetrics(values, domainName, acc)
addIothreadMetrics(values, domainName, acc)
case "memory":
l.addMemoryMetrics(values, domainName, acc)
addMemoryMetrics(values, domainName, acc)
case "dirtyrate":
l.addDirtyrateMetrics(values, domainName, acc)
addDirtyrateMetrics(values, domainName, acc)
}
}
}
Expand All @@ -61,7 +61,7 @@ func (l *Libvirt) addMetrics(stats []golibvirt.DomainStatsRecord, vcpuInfos map[
}
}

func (l *Libvirt) translateMetrics(stats []golibvirt.DomainStatsRecord) map[string]map[string]map[string]golibvirt.TypedParamValue {
func translateMetrics(stats []golibvirt.DomainStatsRecord) map[string]map[string]map[string]golibvirt.TypedParamValue {
metrics := make(map[string]map[string]map[string]golibvirt.TypedParamValue)
for _, stat := range stats {
if stat.Params != nil {
Expand All @@ -83,7 +83,7 @@ func (l *Libvirt) translateMetrics(stats []golibvirt.DomainStatsRecord) map[stri
return metrics
}

func (l *Libvirt) addStateMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
func addStateMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
var stateFields = make(map[string]interface{})
var stateTags = map[string]string{
"domain_name": domainName,
Expand All @@ -101,7 +101,7 @@ func (l *Libvirt) addStateMetrics(metrics map[string]golibvirt.TypedParamValue,
}
}

func (l *Libvirt) addCPUMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
func addCPUMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
var cpuFields = make(map[string]interface{})
var cpuCacheMonitorTotalFields = make(map[string]interface{})

Expand Down Expand Up @@ -188,7 +188,7 @@ func (l *Libvirt) addCPUMetrics(metrics map[string]golibvirt.TypedParamValue, do
}
}

func (l *Libvirt) addBalloonMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
func addBalloonMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
var balloonFields = make(map[string]interface{})
var balloonTags = map[string]string{
"domain_name": domainName,
Expand Down Expand Up @@ -283,7 +283,7 @@ func (l *Libvirt) getCurrentPCPUForVCPU(vcpuID string, vcpuInfos []vcpuAffinity)
return -1
}

func (l *Libvirt) addInterfaceMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
func addInterfaceMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
var netTotalFields = make(map[string]interface{})
var netData = make(map[string]map[string]interface{})

Expand Down Expand Up @@ -330,7 +330,7 @@ func (l *Libvirt) addInterfaceMetrics(metrics map[string]golibvirt.TypedParamVal
}
}

func (l *Libvirt) addPerfMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
func addPerfMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
var perfFields = make(map[string]interface{})
var perfTags = map[string]string{
"domain_name": domainName,
Expand All @@ -351,7 +351,7 @@ func (l *Libvirt) addPerfMetrics(metrics map[string]golibvirt.TypedParamValue, d
}
}

func (l *Libvirt) addBlockMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
func addBlockMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
var blockTotalFields = make(map[string]interface{})
var blockData = make(map[string]map[string]interface{})

Expand Down Expand Up @@ -399,7 +399,7 @@ func (l *Libvirt) addBlockMetrics(metrics map[string]golibvirt.TypedParamValue,
}
}

func (l *Libvirt) addIothreadMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
func addIothreadMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
var iothreadTotalFields = make(map[string]interface{})
var iothreadData = make(map[string]map[string]interface{})

Expand Down Expand Up @@ -446,7 +446,7 @@ func (l *Libvirt) addIothreadMetrics(metrics map[string]golibvirt.TypedParamValu
}
}

func (l *Libvirt) addMemoryMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
func addMemoryMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
var memoryBandwidthMonitorTotalFields = make(map[string]interface{})

var memoryBandwidthMonitorData = make(map[string]map[string]interface{})
Expand Down Expand Up @@ -528,7 +528,7 @@ func (l *Libvirt) addMemoryMetrics(metrics map[string]golibvirt.TypedParamValue,
}
}

func (l *Libvirt) addDirtyrateMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
func addDirtyrateMetrics(metrics map[string]golibvirt.TypedParamValue, domainName string, acc telegraf.Accumulator) {
var dirtyrateFields = make(map[string]interface{})
var dirtyrateVcpuData = make(map[string]map[string]interface{})

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/linux_cpu/linux_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type prop struct {
optional bool
}

func (g *LinuxCPU) SampleConfig() string {
func (*LinuxCPU) SampleConfig() string {
return sampleConfig
}

Expand Down
25 changes: 10 additions & 15 deletions plugins/inputs/logstash/logstash.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,7 @@ func (logstash *Logstash) gatherProcessStats(address string, accumulator telegra
}

// gatherPluginsStats go through a list of plugins and add their metrics to the accumulator
func (logstash *Logstash) gatherPluginsStats(
plugins []plugin,
pluginType string,
tags map[string]string,
accumulator telegraf.Accumulator,
) error {
func gatherPluginsStats(plugins []plugin, pluginType string, tags map[string]string, accumulator telegraf.Accumulator) error {
for _, plugin := range plugins {
pluginTags := map[string]string{
"plugin_name": plugin.Name,
Expand Down Expand Up @@ -370,7 +365,7 @@ func (logstash *Logstash) gatherPluginsStats(
return nil
}

func (logstash *Logstash) gatherQueueStats(queue pipelineQueue, tags map[string]string, acc telegraf.Accumulator) error {
func gatherQueueStats(queue pipelineQueue, tags map[string]string, acc telegraf.Accumulator) error {
queueTags := map[string]string{
"queue_type": queue.Type,
}
Expand Down Expand Up @@ -438,20 +433,20 @@ func (logstash *Logstash) gatherPipelineStats(address string, accumulator telegr
}
accumulator.AddFields("logstash_events", flattener.Fields, tags)

err = logstash.gatherPluginsStats(pipelineStats.Pipeline.Plugins.Inputs, "input", tags, accumulator)
err = gatherPluginsStats(pipelineStats.Pipeline.Plugins.Inputs, "input", tags, accumulator)
if err != nil {
return err
}
err = logstash.gatherPluginsStats(pipelineStats.Pipeline.Plugins.Filters, "filter", tags, accumulator)
err = gatherPluginsStats(pipelineStats.Pipeline.Plugins.Filters, "filter", tags, accumulator)
if err != nil {
return err
}
err = logstash.gatherPluginsStats(pipelineStats.Pipeline.Plugins.Outputs, "output", tags, accumulator)
err = gatherPluginsStats(pipelineStats.Pipeline.Plugins.Outputs, "output", tags, accumulator)
if err != nil {
return err
}

err = logstash.gatherQueueStats(pipelineStats.Pipeline.Queue, tags, accumulator)
err = gatherQueueStats(pipelineStats.Pipeline.Queue, tags, accumulator)
if err != nil {
return err
}
Expand Down Expand Up @@ -484,20 +479,20 @@ func (logstash *Logstash) gatherPipelinesStats(address string, accumulator teleg
}
accumulator.AddFields("logstash_events", flattener.Fields, tags)

err = logstash.gatherPluginsStats(pipeline.Plugins.Inputs, "input", tags, accumulator)
err = gatherPluginsStats(pipeline.Plugins.Inputs, "input", tags, accumulator)
if err != nil {
return err
}
err = logstash.gatherPluginsStats(pipeline.Plugins.Filters, "filter", tags, accumulator)
err = gatherPluginsStats(pipeline.Plugins.Filters, "filter", tags, accumulator)
if err != nil {
return err
}
err = logstash.gatherPluginsStats(pipeline.Plugins.Outputs, "output", tags, accumulator)
err = gatherPluginsStats(pipeline.Plugins.Outputs, "output", tags, accumulator)
if err != nil {
return err
}

err = logstash.gatherQueueStats(pipeline.Queue, tags, accumulator)
err = gatherQueueStats(pipeline.Queue, tags, accumulator)
if err != nil {
return err
}
Expand Down
4 changes: 0 additions & 4 deletions plugins/inputs/lvm/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ func (*LVM) SampleConfig() string {
return sampleConfig
}

func (lvm *LVM) Init() error {
return nil
}

func (lvm *LVM) Gather(acc telegraf.Accumulator) error {
if err := lvm.gatherPhysicalVolumes(acc); err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/mcrouter/mcrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ func (m *Mcrouter) Gather(acc telegraf.Accumulator) error {
}

for _, serverAddress := range m.Servers {
acc.AddError(m.gatherServer(ctx, serverAddress, acc))
acc.AddError(gatherServer(ctx, serverAddress, acc))
}

return nil
}

// parseAddress parses an address string into 'host:port' and 'protocol' parts
func (m *Mcrouter) parseAddress(address string) (parsedAddress, protocol string, err error) {
func parseAddress(address string) (parsedAddress, protocol string, err error) {
var host string
var port string

Expand Down Expand Up @@ -181,13 +181,13 @@ func (m *Mcrouter) parseAddress(address string) (parsedAddress, protocol string,
return parsedAddress, protocol, nil
}

func (m *Mcrouter) gatherServer(ctx context.Context, address string, acc telegraf.Accumulator) error {
func gatherServer(ctx context.Context, address string, acc telegraf.Accumulator) error {
var conn net.Conn
var err error
var protocol string
var dialer net.Dialer

address, protocol, err = m.parseAddress(address)
address, protocol, err = parseAddress(address)
if err != nil {
return err
}
Expand Down
8 changes: 2 additions & 6 deletions plugins/inputs/mcrouter/mcrouter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import (
)

func TestAddressParsing(t *testing.T) {
m := &Mcrouter{
Servers: []string{"tcp://" + testutil.GetLocalHost()},
}

var acceptTests = [][3]string{
{"tcp://localhost:8086", "localhost:8086", "tcp"},
{"tcp://localhost", "localhost:" + defaultServerURL.Port(), "tcp"},
Expand All @@ -32,15 +28,15 @@ func TestAddressParsing(t *testing.T) {
}

for _, args := range acceptTests {
address, protocol, err := m.parseAddress(args[0])
address, protocol, err := parseAddress(args[0])

require.NoError(t, err, args[0])
require.Equal(t, args[1], address, args[0])
require.Equal(t, args[2], protocol, args[0])
}

for _, addr := range rejectTests {
address, protocol, err := m.parseAddress(addr)
address, protocol, err := parseAddress(addr)

require.Error(t, err, addr)
require.Empty(t, address, addr)
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/modbus/configuration_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type configurationPerMetric struct {
logger telegraf.Logger
}

func (c *configurationPerMetric) sampleConfigPart() string {
func (*configurationPerMetric) sampleConfigPart() string {
return sampleConfigPartPerMetric
}

Expand Down Expand Up @@ -366,7 +366,7 @@ func (c *configurationPerMetric) fieldID(seed maphash.Seed, def metricDefinition
return mh.Sum64()
}

func (c *configurationPerMetric) determineOutputDatatype(input string) (string, error) {
func (*configurationPerMetric) determineOutputDatatype(input string) (string, error) {
// Handle our special types
switch input {
case "INT8L", "INT8H", "INT16", "INT32", "INT64":
Expand All @@ -381,7 +381,7 @@ func (c *configurationPerMetric) determineOutputDatatype(input string) (string,
return "unknown", fmt.Errorf("invalid input datatype %q for determining output", input)
}

func (c *configurationPerMetric) determineFieldLength(input string, length uint16) (uint16, error) {
func (*configurationPerMetric) determineFieldLength(input string, length uint16) (uint16, error) {
// Handle our special types
switch input {
case "BIT", "INT8L", "INT8H", "UINT8L", "UINT8H":
Expand Down
Loading

0 comments on commit d829a5b

Please sign in to comment.