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/[a-e]`
  • Loading branch information
zak-pawel committed Dec 6, 2024
1 parent 304ab2e commit 1c02371
Show file tree
Hide file tree
Showing 41 changed files with 162 additions and 179 deletions.
31 changes: 16 additions & 15 deletions plugins/inputs/aerospike/aerospike.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ func (a *Aerospike) gatherServer(acc telegraf.Accumulator, hostPort string) erro
nodes := c.GetNodes()
for _, n := range nodes {
nodeHost := n.GetHost().String()
stats, err := a.getNodeInfo(n, asInfoPolicy)
stats, err := getNodeInfo(n, asInfoPolicy)
if err != nil {
return err
}
a.parseNodeInfo(acc, stats, nodeHost, n.GetName())
parseNodeInfo(acc, stats, nodeHost, n.GetName())

namespaces, err := a.getNamespaces(n, asInfoPolicy)
if err != nil {
Expand All @@ -135,12 +135,12 @@ func (a *Aerospike) gatherServer(acc telegraf.Accumulator, hostPort string) erro
if !a.DisableQueryNamespaces {
// Query Namespaces
for _, namespace := range namespaces {
stats, err = a.getNamespaceInfo(namespace, n, asInfoPolicy)
stats, err = getNamespaceInfo(namespace, n, asInfoPolicy)

if err != nil {
continue
}
a.parseNamespaceInfo(acc, stats, nodeHost, namespace, n.GetName())
parseNamespaceInfo(acc, stats, nodeHost, namespace, n.GetName())

if a.EnableTTLHistogram {
err = a.getTTLHistogram(acc, nodeHost, namespace, "", n, asInfoPolicy)
Expand All @@ -162,12 +162,12 @@ func (a *Aerospike) gatherServer(acc telegraf.Accumulator, hostPort string) erro
if err == nil {
for _, namespaceSet := range namespaceSets {
namespace, set := splitNamespaceSet(namespaceSet)
stats, err := a.getSetInfo(namespaceSet, n, asInfoPolicy)
stats, err := getSetInfo(namespaceSet, n, asInfoPolicy)

if err != nil {
continue
}
a.parseSetInfo(acc, stats, nodeHost, namespaceSet, n.GetName())
parseSetInfo(acc, stats, nodeHost, namespaceSet, n.GetName())

if a.EnableTTLHistogram {
err = a.getTTLHistogram(acc, nodeHost, namespace, set, n, asInfoPolicy)
Expand All @@ -189,7 +189,7 @@ func (a *Aerospike) gatherServer(acc telegraf.Accumulator, hostPort string) erro
return nil
}

func (a *Aerospike) getNodeInfo(n *as.Node, infoPolicy *as.InfoPolicy) (map[string]string, error) {
func getNodeInfo(n *as.Node, infoPolicy *as.InfoPolicy) (map[string]string, error) {
stats, err := n.RequestInfo(infoPolicy, "statistics")
if err != nil {
return nil, err
Expand All @@ -198,7 +198,7 @@ func (a *Aerospike) getNodeInfo(n *as.Node, infoPolicy *as.InfoPolicy) (map[stri
return stats, nil
}

func (a *Aerospike) parseNodeInfo(acc telegraf.Accumulator, stats map[string]string, hostPort, nodeName string) {
func parseNodeInfo(acc telegraf.Accumulator, stats map[string]string, hostPort, nodeName string) {
nTags := map[string]string{
"aerospike_host": hostPort,
"node_name": nodeName,
Expand Down Expand Up @@ -231,15 +231,16 @@ func (a *Aerospike) getNamespaces(n *as.Node, infoPolicy *as.InfoPolicy) ([]stri
return namespaces, nil
}

func (a *Aerospike) getNamespaceInfo(namespace string, n *as.Node, infoPolicy *as.InfoPolicy) (map[string]string, error) {
func getNamespaceInfo(namespace string, n *as.Node, infoPolicy *as.InfoPolicy) (map[string]string, error) {
stats, err := n.RequestInfo(infoPolicy, "namespace/"+namespace)
if err != nil {
return nil, err
}

return stats, err
}
func (a *Aerospike) parseNamespaceInfo(acc telegraf.Accumulator, stats map[string]string, hostPort, namespace, nodeName string) {

func parseNamespaceInfo(acc telegraf.Accumulator, stats map[string]string, hostPort, namespace, nodeName string) {
nTags := map[string]string{
"aerospike_host": hostPort,
"node_name": nodeName,
Expand Down Expand Up @@ -296,15 +297,15 @@ func (a *Aerospike) getSets(n *as.Node, infoPolicy *as.InfoPolicy) ([]string, er
return namespaceSets, nil
}

func (a *Aerospike) getSetInfo(namespaceSet string, n *as.Node, infoPolicy *as.InfoPolicy) (map[string]string, error) {
func getSetInfo(namespaceSet string, n *as.Node, infoPolicy *as.InfoPolicy) (map[string]string, error) {
stats, err := n.RequestInfo(infoPolicy, "sets/"+namespaceSet)
if err != nil {
return nil, err
}
return stats, nil
}

func (a *Aerospike) parseSetInfo(acc telegraf.Accumulator, stats map[string]string, hostPort, namespaceSet, nodeName string) {
func parseSetInfo(acc telegraf.Accumulator, stats map[string]string, hostPort, namespaceSet, nodeName string) {
stat := strings.Split(
strings.TrimSuffix(
stats["sets/"+namespaceSet], ";"), ":")
Expand All @@ -327,7 +328,7 @@ func (a *Aerospike) parseSetInfo(acc telegraf.Accumulator, stats map[string]stri
}

func (a *Aerospike) getTTLHistogram(acc telegraf.Accumulator, hostPort, namespace, set string, n *as.Node, infoPolicy *as.InfoPolicy) error {
stats, err := a.getHistogram(namespace, set, "ttl", n, infoPolicy)
stats, err := getHistogram(namespace, set, "ttl", n, infoPolicy)
if err != nil {
return err
}
Expand All @@ -339,7 +340,7 @@ func (a *Aerospike) getTTLHistogram(acc telegraf.Accumulator, hostPort, namespac
}

func (a *Aerospike) getObjectSizeLinearHistogram(acc telegraf.Accumulator, hostPort, namespace, set string, n *as.Node, infoPolicy *as.InfoPolicy) error {
stats, err := a.getHistogram(namespace, set, "object-size-linear", n, infoPolicy)
stats, err := getHistogram(namespace, set, "object-size-linear", n, infoPolicy)
if err != nil {
return err
}
Expand All @@ -350,7 +351,7 @@ func (a *Aerospike) getObjectSizeLinearHistogram(acc telegraf.Accumulator, hostP
return nil
}

func (a *Aerospike) getHistogram(namespace, set, histogramType string, n *as.Node, infoPolicy *as.InfoPolicy) (map[string]string, error) {
func getHistogram(namespace, set, histogramType string, n *as.Node, infoPolicy *as.InfoPolicy) (map[string]string, error) {
var queryArg string
if len(set) > 0 {
queryArg = fmt.Sprintf("histogram:type=%s;namespace=%v;set=%v", histogramType, namespace, set)
Expand Down
20 changes: 7 additions & 13 deletions plugins/inputs/aerospike/aerospike_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,6 @@ func TestDisableObjectSizeLinearHistogramIntegration(t *testing.T) {
}

func TestParseNodeInfo(t *testing.T) {
a := &Aerospike{}
var acc testutil.Accumulator

stats := map[string]string{
"statistics": "early_tsvc_from_proxy_error=0;cluster_principal=BB9020012AC4202;cluster_is_member=true",
}
Expand All @@ -327,14 +324,12 @@ func TestParseNodeInfo(t *testing.T) {
"node_name": "TestNodeName",
}

a.parseNodeInfo(&acc, stats, "127.0.0.1:3000", "TestNodeName")
var acc testutil.Accumulator
parseNodeInfo(&acc, stats, "127.0.0.1:3000", "TestNodeName")
acc.AssertContainsTaggedFields(t, "aerospike_node", expectedFields, expectedTags)
}

func TestParseNamespaceInfo(t *testing.T) {
a := &Aerospike{}
var acc testutil.Accumulator

stats := map[string]string{
"namespace/test": "ns_cluster_size=1;effective_replication_factor=1;objects=2;tombstones=0;master_objects=2",
}
Expand All @@ -353,15 +348,12 @@ func TestParseNamespaceInfo(t *testing.T) {
"namespace": "test",
}

a.parseNamespaceInfo(&acc, stats, "127.0.0.1:3000", "test", "TestNodeName")
var acc testutil.Accumulator
parseNamespaceInfo(&acc, stats, "127.0.0.1:3000", "test", "TestNodeName")
acc.AssertContainsTaggedFields(t, "aerospike_namespace", expectedFields, expectedTags)
}

func TestParseSetInfo(t *testing.T) {
a := &Aerospike{}

var acc testutil.Accumulator

stats := map[string]string{
"sets/test/foo": "objects=1:tombstones=0:memory_data_bytes=26;",
}
Expand All @@ -377,7 +369,9 @@ func TestParseSetInfo(t *testing.T) {
"node_name": "TestNodeName",
"set": "test/foo",
}
a.parseSetInfo(&acc, stats, "127.0.0.1:3000", "test/foo", "TestNodeName")

var acc testutil.Accumulator
parseSetInfo(&acc, stats, "127.0.0.1:3000", "test/foo", "TestNodeName")
acc.AssertContainsTaggedFields(t, "aerospike_set", expectedFields, expectedTags)
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/aliyuncms/aliyuncms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const inputTitle = "inputs.aliyuncms"

type mockGatherAliyunCMSClient struct{}

func (m *mockGatherAliyunCMSClient) DescribeMetricList(request *cms.DescribeMetricListRequest) (*cms.DescribeMetricListResponse, error) {
func (*mockGatherAliyunCMSClient) DescribeMetricList(request *cms.DescribeMetricListRequest) (*cms.DescribeMetricListResponse, error) {
resp := new(cms.DescribeMetricListResponse)

// switch request.Metric {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/amd_rocm_smi/amd_rocm_smi.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (rsmi *ROCmSMI) Gather(acc telegraf.Accumulator) error {
return gatherROCmSMI(data, acc)
}

func (rsmi *ROCmSMI) Stop() {}
func (*ROCmSMI) Stop() {}

func (rsmi *ROCmSMI) pollROCmSMI() ([]byte, error) {
// Construct and execute metrics query, there currently exist (ROCm v4.3.x) a "-a" option
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/amqp_consumer/amqp_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ type AMQPConsumer struct {
decoder internal.ContentDecoder
}

func (a *externalAuth) Mechanism() string {
func (*externalAuth) Mechanism() string {
return "EXTERNAL"
}

func (a *externalAuth) Response() string {
func (*externalAuth) Response() string {
return "\000"
}

Expand Down Expand Up @@ -175,7 +175,7 @@ func (a *AMQPConsumer) Start(acc telegraf.Accumulator) error {
return nil
}

func (a *AMQPConsumer) Gather(_ telegraf.Accumulator) error {
func (*AMQPConsumer) Gather(_ telegraf.Accumulator) error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/apache/apache.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (n *Apache) gatherURL(addr *url.URL, acc telegraf.Accumulator) error {

switch key {
case "Scoreboard":
for field, value := range n.gatherScores(part) {
for field, value := range gatherScores(part) {
fields[field] = value
}
default:
Expand All @@ -137,7 +137,7 @@ func (n *Apache) gatherURL(addr *url.URL, acc telegraf.Accumulator) error {
return nil
}

func (n *Apache) gatherScores(data string) map[string]interface{} {
func gatherScores(data string) map[string]interface{} {
var waiting, open = 0, 0
var s, r, w, k, d, c, l, g, i = 0, 0, 0, 0, 0, 0, 0, 0, 0

Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/azure_monitor/azure_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type azureClientsCreator interface {
//go:embed sample.conf
var sampleConfig string

func (am *AzureMonitor) SampleConfig() string {
func (*AzureMonitor) SampleConfig() string {
return sampleConfig
}

Expand Down Expand Up @@ -170,7 +170,7 @@ func (am *AzureMonitor) setReceiver() error {
return err
}

func (acm *azureClientsManager) createAzureClients(
func (*azureClientsManager) createAzureClients(
subscriptionID, clientID, clientSecret, tenantID string,
clientOptions azcore.ClientOptions,
) (*receiver.AzureClients, error) {
Expand Down
10 changes: 5 additions & 5 deletions plugins/inputs/azure_monitor/azure_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type mockAzureMetricDefinitionsClient struct{}

type mockAzureMetricsClient struct{}

func (mam *mockAzureClientsManager) createAzureClients(_, _, _, _ string, _ azcore.ClientOptions) (*receiver.AzureClients, error) {
func (*mockAzureClientsManager) createAzureClients(_, _, _, _ string, _ azcore.ClientOptions) (*receiver.AzureClients, error) {
return &receiver.AzureClients{
Ctx: context.Background(),
ResourcesClient: &mockAzureResourcesClient{},
Expand All @@ -36,7 +36,7 @@ func (mam *mockAzureClientsManager) createAzureClients(_, _, _, _ string, _ azco
}, nil
}

func (marc *mockAzureResourcesClient) List(_ context.Context, _ *armresources.ClientListOptions) ([]*armresources.ClientListResponse, error) {
func (*mockAzureResourcesClient) List(_ context.Context, _ *armresources.ClientListOptions) ([]*armresources.ClientListResponse, error) {
var responses []*armresources.ClientListResponse

file, err := os.ReadFile("testdata/json/azure_resources_response.json")
Expand All @@ -59,7 +59,7 @@ func (marc *mockAzureResourcesClient) List(_ context.Context, _ *armresources.Cl
return responses, nil
}

func (marc *mockAzureResourcesClient) ListByResourceGroup(
func (*mockAzureResourcesClient) ListByResourceGroup(
_ context.Context,
resourceGroup string,
_ *armresources.ClientListByResourceGroupOptions) ([]*armresources.ClientListByResourceGroupResponse, error) {
Expand Down Expand Up @@ -105,7 +105,7 @@ func (marc *mockAzureResourcesClient) ListByResourceGroup(
return nil, errors.New("resource group was not found")
}

func (mamdc *mockAzureMetricDefinitionsClient) List(
func (*mockAzureMetricDefinitionsClient) List(
_ context.Context,
resourceID string,
_ *armmonitor.MetricDefinitionsClientListOptions) (armmonitor.MetricDefinitionsClientListResponse, error) {
Expand Down Expand Up @@ -146,7 +146,7 @@ func (mamdc *mockAzureMetricDefinitionsClient) List(
return armmonitor.MetricDefinitionsClientListResponse{}, errors.New("resource ID was not found")
}

func (mamc *mockAzureMetricsClient) List(
func (*mockAzureMetricsClient) List(
_ context.Context,
resourceID string,
_ *armmonitor.MetricsClientListOptions) (armmonitor.MetricsClientListResponse, error) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/bcache/bcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (b *Bcache) Gather(acc telegraf.Accumulator) error {
continue
}
}
if err := b.gatherBcache(bdev, acc); err != nil {
if err := gatherBcache(bdev, acc); err != nil {
return fmt.Errorf("gathering bcache failed: %w", err)
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func prettyToBytes(v string) uint64 {
return uint64(result)
}

func (b *Bcache) gatherBcache(bdev string, acc telegraf.Accumulator) error {
func gatherBcache(bdev string, acc telegraf.Accumulator) error {
tags := getTags(bdev)
metrics, err := filepath.Glob(bdev + "/stats_total/*")
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/bond/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (bond *Bond) Gather(acc telegraf.Accumulator) error {
if err != nil {
acc.AddError(err)
}
bond.gatherSysDetails(bondName, files, acc)
gatherSysDetails(bondName, files, acc)
}
}
return nil
Expand Down Expand Up @@ -164,7 +164,7 @@ func (bond *Bond) readSysFiles(bondDir string) (sysFiles, error) {
return output, nil
}

func (bond *Bond) gatherSysDetails(bondName string, files sysFiles, acc telegraf.Accumulator) {
func gatherSysDetails(bondName string, files sysFiles, acc telegraf.Accumulator) {
var slaves []string
var adPortCount int

Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/bond/bond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestGatherBondInterface(t *testing.T) {

acc = testutil.Accumulator{}
require.NoError(t, bond.gatherBondInterface("bondLACP", sampleTestLACP, &acc))
bond.gatherSysDetails("bondLACP", sysFiles{ModeFile: sampleSysMode, SlaveFile: sampleSysSlaves, ADPortsFile: sampleSysAdPorts}, &acc)
gatherSysDetails("bondLACP", sysFiles{ModeFile: sampleSysMode, SlaveFile: sampleSysSlaves, ADPortsFile: sampleSysAdPorts}, &acc)
acc.AssertContainsTaggedFields(t, "bond", map[string]interface{}{"status": 1}, map[string]string{"bond": "bondLACP"})
acc.AssertContainsTaggedFields(
t,
Expand All @@ -169,7 +169,7 @@ func TestGatherBondInterface(t *testing.T) {

acc = testutil.Accumulator{}
require.NoError(t, bond.gatherBondInterface("bondLACPUpDown", sampleTestLACPFirstUpSecondDown, &acc))
bond.gatherSysDetails("bondLACPUpDown", sysFiles{ModeFile: sampleSysMode, SlaveFile: sampleSysSlaves, ADPortsFile: sampleSysAdPorts}, &acc)
gatherSysDetails("bondLACPUpDown", sysFiles{ModeFile: sampleSysMode, SlaveFile: sampleSysSlaves, ADPortsFile: sampleSysAdPorts}, &acc)
acc.AssertContainsTaggedFields(t, "bond", map[string]interface{}{"status": 1}, map[string]string{"bond": "bondLACPUpDown"})
acc.AssertContainsTaggedFields(
t,
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/burrow/burrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ func (b *Burrow) gatherTopics(guard chan struct{}, src *url.URL, cluster string,
return
}

b.genTopicMetrics(tr, cluster, topic, acc)
genTopicMetrics(tr, cluster, topic, acc)
}(topic)
}

wg.Wait()
}

func (b *Burrow) genTopicMetrics(r *apiResponse, cluster, topic string, acc telegraf.Accumulator) {
func genTopicMetrics(r *apiResponse, cluster, topic string, acc telegraf.Accumulator) {
for i, offset := range r.Offsets {
tags := map[string]string{
"cluster": cluster,
Expand Down Expand Up @@ -346,15 +346,15 @@ func (b *Burrow) gatherGroups(guard chan struct{}, src *url.URL, cluster string,
return
}

b.genGroupStatusMetrics(gr, cluster, group, acc)
genGroupStatusMetrics(gr, cluster, group, acc)
b.genGroupLagMetrics(gr, cluster, group, acc)
}(group)
}

wg.Wait()
}

func (b *Burrow) genGroupStatusMetrics(r *apiResponse, cluster, group string, acc telegraf.Accumulator) {
func genGroupStatusMetrics(r *apiResponse, cluster, group string, acc telegraf.Accumulator) {
partitionCount := r.Status.PartitionCount
if partitionCount == 0 {
partitionCount = len(r.Status.Partitions)
Expand Down
Loading

0 comments on commit 1c02371

Please sign in to comment.