diff --git a/config/secret_without_mlock.go b/config/secret_without_mlock.go index 1c4c82c95..01ed4a2bb 100644 --- a/config/secret_without_mlock.go +++ b/config/secret_without_mlock.go @@ -6,7 +6,7 @@ import ( "github.com/awnumar/memguard" ) -func protect(secret []byte) error { +func protect(_ []byte) error { return nil } diff --git a/plugins/inputs/cgroup/cgroup_notlinux.go b/plugins/inputs/cgroup/cgroup_notlinux.go index 892d5d106..ed3911810 100644 --- a/plugins/inputs/cgroup/cgroup_notlinux.go +++ b/plugins/inputs/cgroup/cgroup_notlinux.go @@ -6,6 +6,6 @@ import ( "github.com/influxdata/telegraf" ) -func (g *CGroup) Gather(acc telegraf.Accumulator) error { +func (*CGroup) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/diskio/diskio_other.go b/plugins/inputs/diskio/diskio_other.go index b277c390d..44507ae3f 100644 --- a/plugins/inputs/diskio/diskio_other.go +++ b/plugins/inputs/diskio/diskio_other.go @@ -4,7 +4,7 @@ package diskio type diskInfoCache struct{} -func (d *DiskIO) diskInfo(devName string) (map[string]string, error) { +func (*DiskIO) diskInfo(_ string) (map[string]string, error) { return nil, nil } @@ -12,6 +12,6 @@ func resolveName(name string) string { return name } -func getDeviceWWID(name string) string { +func getDeviceWWID(_ string) string { return "" } diff --git a/plugins/inputs/dmcache/dmcache_notlinux.go b/plugins/inputs/dmcache/dmcache_notlinux.go index 111f5ed80..6d9d01e62 100644 --- a/plugins/inputs/dmcache/dmcache_notlinux.go +++ b/plugins/inputs/dmcache/dmcache_notlinux.go @@ -6,7 +6,7 @@ import ( "github.com/influxdata/telegraf" ) -func (c *DMCache) Gather(acc telegraf.Accumulator) error { +func (*DMCache) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/ethtool/ethtool.go b/plugins/inputs/ethtool/ethtool.go index 0e4f0b813..314272c50 100644 --- a/plugins/inputs/ethtool/ethtool.go +++ b/plugins/inputs/ethtool/ethtool.go @@ -11,8 +11,6 @@ import ( //go:embed sample.conf var sampleConfig string -var downInterfacesBehaviors = []string{"expose", "skip"} - type Command interface { Init() error DriverName(intf NamespacedInterface) (string, error) diff --git a/plugins/inputs/ethtool/ethtool_linux.go b/plugins/inputs/ethtool/ethtool_linux.go index 009038f6c..afbcaaeb7 100644 --- a/plugins/inputs/ethtool/ethtool_linux.go +++ b/plugins/inputs/ethtool/ethtool_linux.go @@ -19,6 +19,8 @@ import ( "github.com/influxdata/telegraf/plugins/inputs" ) +var downInterfacesBehaviors = []string{"expose", "skip"} + type CommandEthtool struct { Log telegraf.Logger namespaceGoroutines map[string]*NamespaceGoroutine diff --git a/plugins/inputs/ethtool/ethtool_notlinux.go b/plugins/inputs/ethtool/ethtool_notlinux.go index aff85dc3d..59d40ba62 100644 --- a/plugins/inputs/ethtool/ethtool_notlinux.go +++ b/plugins/inputs/ethtool/ethtool_notlinux.go @@ -12,7 +12,7 @@ func (e *Ethtool) Init() error { return nil } -func (e *Ethtool) Gather(acc telegraf.Accumulator) error { +func (*Ethtool) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/infiniband/infiniband_notlinux.go b/plugins/inputs/infiniband/infiniband_notlinux.go index 49a81f1b0..450307abc 100644 --- a/plugins/inputs/infiniband/infiniband_notlinux.go +++ b/plugins/inputs/infiniband/infiniband_notlinux.go @@ -12,7 +12,7 @@ func (i *Infiniband) Init() error { return nil } -func (_ *Infiniband) Gather(acc telegraf.Accumulator) error { +func (*Infiniband) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/intel_powerstat/dto.go b/plugins/inputs/intel_powerstat/dto.go index 71fc10f50..75ae2645e 100644 --- a/plugins/inputs/intel_powerstat/dto.go +++ b/plugins/inputs/intel_powerstat/dto.go @@ -1,3 +1,5 @@ +//go:build linux + package intel_powerstat type msrData struct { diff --git a/plugins/inputs/intel_powerstat/file_mock_test.go b/plugins/inputs/intel_powerstat/file_mock_test.go index 102142c2b..b4a5e16fb 100644 --- a/plugins/inputs/intel_powerstat/file_mock_test.go +++ b/plugins/inputs/intel_powerstat/file_mock_test.go @@ -1,3 +1,5 @@ +//go:build linux + // Code generated by mockery v2.12.3. DO NOT EDIT. package intel_powerstat diff --git a/plugins/inputs/intel_powerstat/msr_mock_test.go b/plugins/inputs/intel_powerstat/msr_mock_test.go index 3381132fa..f4b99f0e6 100644 --- a/plugins/inputs/intel_powerstat/msr_mock_test.go +++ b/plugins/inputs/intel_powerstat/msr_mock_test.go @@ -1,3 +1,5 @@ +//go:build linux + // Code generated by mockery v2.12.3. DO NOT EDIT. package intel_powerstat diff --git a/plugins/inputs/intel_powerstat/rapl_mock_test.go b/plugins/inputs/intel_powerstat/rapl_mock_test.go index fde381aa6..4e23fb1ba 100644 --- a/plugins/inputs/intel_powerstat/rapl_mock_test.go +++ b/plugins/inputs/intel_powerstat/rapl_mock_test.go @@ -1,3 +1,5 @@ +//go:build linux + // Code generated by mockery v2.12.3. DO NOT EDIT. package intel_powerstat diff --git a/plugins/inputs/kernel/kernel_notlinux.go b/plugins/inputs/kernel/kernel_notlinux.go index 1df31c3aa..fd3ca9fa1 100644 --- a/plugins/inputs/kernel/kernel_notlinux.go +++ b/plugins/inputs/kernel/kernel_notlinux.go @@ -21,8 +21,8 @@ func (k *Kernel) Init() error { k.Log.Warn("current platform is not supported") return nil } -func (*Kernel) SampleConfig() string { return sampleConfig } -func (*Kernel) Gather(acc telegraf.Accumulator) error { return nil } +func (*Kernel) SampleConfig() string { return sampleConfig } +func (*Kernel) Gather(_ telegraf.Accumulator) error { return nil } func init() { inputs.Add("kernel", func() telegraf.Input { diff --git a/plugins/inputs/powerdns/powerdns_linux_test.go b/plugins/inputs/powerdns/powerdns_linux_test.go index bd88fe133..f462e68e4 100644 --- a/plugins/inputs/powerdns/powerdns_linux_test.go +++ b/plugins/inputs/powerdns/powerdns_linux_test.go @@ -13,6 +13,28 @@ import ( "github.com/stretchr/testify/require" ) +type statServer struct{} + +func (s statServer) serverSocket(l net.Listener) { + for { + conn, err := l.Accept() + if err != nil { + return + } + + go func(c net.Conn) { + buf := make([]byte, 1024) + n, _ := c.Read(buf) + + data := buf[:n] + if string(data) == "show * \n" { + c.Write([]byte(metrics)) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway + c.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway + } + }(conn) + } +} + func TestPowerdnsGeneratesMetrics(t *testing.T) { // We create a fake server to return test data randomNumber := int64(5239846799706671610) diff --git a/plugins/inputs/powerdns/powerdns_test.go b/plugins/inputs/powerdns/powerdns_test.go index 080682aab..54c6bfef0 100644 --- a/plugins/inputs/powerdns/powerdns_test.go +++ b/plugins/inputs/powerdns/powerdns_test.go @@ -1,14 +1,11 @@ package powerdns import ( - "net" "testing" "github.com/influxdata/telegraf/testutil" ) -type statServer struct{} - var metrics = "corrupt-packets=0,deferred-cache-inserts=0,deferred-cache-lookup=0," + "dnsupdate-answers=0,dnsupdate-changes=0,dnsupdate-queries=0," + "dnsupdate-refused=0,packetcache-hit=0,packetcache-miss=1,packetcache-size=0," + @@ -44,26 +41,6 @@ var intOverflowMetrics = "corrupt-packets=18446744073709550195,deferred-cache-in "key-cache-size=0,latency=26,meta-cache-size=0,qsize-q=0," + "signature-cache-size=0,sys-msec=2889,uptime=86317,user-msec=2167," -func (s statServer) serverSocket(l net.Listener) { - for { - conn, err := l.Accept() - if err != nil { - return - } - - go func(c net.Conn) { - buf := make([]byte, 1024) - n, _ := c.Read(buf) - - data := buf[:n] - if string(data) == "show * \n" { - c.Write([]byte(metrics)) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway - c.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway - } - }(conn) - } -} - func TestPowerdnsParseMetrics(t *testing.T) { p := &Powerdns{ Log: testutil.Logger{}, diff --git a/plugins/inputs/synproxy/synproxy_notlinux.go b/plugins/inputs/synproxy/synproxy_notlinux.go index 151295de9..582a7b382 100644 --- a/plugins/inputs/synproxy/synproxy_notlinux.go +++ b/plugins/inputs/synproxy/synproxy_notlinux.go @@ -12,7 +12,7 @@ func (k *Synproxy) Init() error { return nil } -func (k *Synproxy) Gather(acc telegraf.Accumulator) error { +func (*Synproxy) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/wireless/wireless_notlinux.go b/plugins/inputs/wireless/wireless_notlinux.go index 55c70f815..8b876211c 100644 --- a/plugins/inputs/wireless/wireless_notlinux.go +++ b/plugins/inputs/wireless/wireless_notlinux.go @@ -12,7 +12,7 @@ func (w *Wireless) Init() error { return nil } -func (w *Wireless) Gather(acc telegraf.Accumulator) error { +func (*Wireless) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/zfs/zfs_other.go b/plugins/inputs/zfs/zfs_other.go index be17dbd9b..6a7cb2f71 100644 --- a/plugins/inputs/zfs/zfs_other.go +++ b/plugins/inputs/zfs/zfs_other.go @@ -7,7 +7,7 @@ import ( "github.com/influxdata/telegraf/plugins/inputs" ) -func (z *Zfs) Gather(acc telegraf.Accumulator) error { +func (*Zfs) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/secretstores/os/os_darwin.go b/plugins/secretstores/os/os_darwin.go index 8aca279ad..a7e9ee109 100644 --- a/plugins/secretstores/os/os_darwin.go +++ b/plugins/secretstores/os/os_darwin.go @@ -13,7 +13,7 @@ import ( func (o *OS) createKeyringConfig() (keyring.Config, error) { passwd, err := o.Password.Get() if err != nil { - return keyring.Config{}, fmt.Errorf("getting password failed: %v", err) + return keyring.Config{}, fmt.Errorf("getting password failed: %w", err) } defer config.ReleaseSecret(passwd)