From 9d7a7e5b3620171a49d59aebd011e14c08d4093e Mon Sep 17 00:00:00 2001 From: Pawel Zak Date: Wed, 4 Sep 2024 09:24:35 +0200 Subject: [PATCH] chore(linters): Enable `import-alias-naming` and `redundant-import-alias` rules for revive --- plugins/common/auth/basic_auth_test.go | 3 +- plugins/inputs/aerospike/aerospike.go | 32 +++++++++---------- plugins/inputs/azure_monitor/azure_monitor.go | 3 +- .../azure_monitor/azure_monitor_test.go | 4 +-- .../cisco_telemetry_mdt.go | 2 +- .../cisco_telemetry_mdt_test.go | 2 +- .../inputs/cloud_pubsub/subscription_gcp.go | 3 +- .../eventhub_consumer/eventhub_consumer.go | 2 +- plugins/inputs/exec/run_windows.go | 7 ++-- plugins/inputs/infiniband/infiniband_test.go | 4 ++- .../intel_baseband/sock_connector_test.go | 2 +- .../jti_openconfig_telemetry.go | 4 +-- plugins/inputs/ldap/ldap_test.go | 2 +- .../riemann_listener/riemann_listener.go | 2 +- .../gen-go/zipkincore/zipkinCore-consts.go | 3 +- plugins/outputs/cloud_pubsub/topic_gcp.go | 3 +- 16 files changed, 43 insertions(+), 35 deletions(-) diff --git a/plugins/common/auth/basic_auth_test.go b/plugins/common/auth/basic_auth_test.go index 781f36ab87af4..04f313f2d8e98 100644 --- a/plugins/common/auth/basic_auth_test.go +++ b/plugins/common/auth/basic_auth_test.go @@ -1,9 +1,10 @@ package auth import ( - "github.com/stretchr/testify/require" "net/http/httptest" "testing" + + "github.com/stretchr/testify/require" ) func TestBasicAuth_VerifyWithCredentials(t *testing.T) { diff --git a/plugins/inputs/aerospike/aerospike.go b/plugins/inputs/aerospike/aerospike.go index 44a3819b2cdb8..f65787e74707b 100644 --- a/plugins/inputs/aerospike/aerospike.go +++ b/plugins/inputs/aerospike/aerospike.go @@ -11,7 +11,7 @@ import ( "sync" "time" - "github.com/aerospike/aerospike-client-go/v5" + as "github.com/aerospike/aerospike-client-go/v5" "github.com/influxdata/telegraf" common_tls "github.com/influxdata/telegraf/plugins/common/tls" @@ -98,11 +98,11 @@ func (a *Aerospike) Gather(acc telegraf.Accumulator) error { } func (a *Aerospike) gatherServer(acc telegraf.Accumulator, hostPort string) error { - policy := aerospike.NewClientPolicy() + policy := as.NewClientPolicy() policy.User = a.Username policy.Password = a.Password policy.TlsConfig = a.tlsConfig - asHosts, err := aerospike.NewHosts(hostPort) + asHosts, err := as.NewHosts(hostPort) if err != nil { return err } @@ -111,11 +111,11 @@ func (a *Aerospike) gatherServer(acc telegraf.Accumulator, hostPort string) erro asHost.TLSName = a.TLSName } } - c, err := aerospike.NewClientWithPolicyAndHost(policy, asHosts...) + c, err := as.NewClientWithPolicyAndHost(policy, asHosts...) if err != nil { return err } - asInfoPolicy := aerospike.NewInfoPolicy() + asInfoPolicy := as.NewInfoPolicy() defer c.Close() nodes := c.GetNodes() @@ -189,7 +189,7 @@ func (a *Aerospike) gatherServer(acc telegraf.Accumulator, hostPort string) erro return nil } -func (a *Aerospike) getNodeInfo(n *aerospike.Node, infoPolicy *aerospike.InfoPolicy) (map[string]string, error) { +func (a *Aerospike) getNodeInfo(n *as.Node, infoPolicy *as.InfoPolicy) (map[string]string, error) { stats, err := n.RequestInfo(infoPolicy, "statistics") if err != nil { return nil, err @@ -216,7 +216,7 @@ func (a *Aerospike) parseNodeInfo(acc telegraf.Accumulator, stats map[string]str acc.AddFields("aerospike_node", nFields, nTags, time.Now()) } -func (a *Aerospike) getNamespaces(n *aerospike.Node, infoPolicy *aerospike.InfoPolicy) ([]string, error) { +func (a *Aerospike) getNamespaces(n *as.Node, infoPolicy *as.InfoPolicy) ([]string, error) { var namespaces []string if len(a.Namespaces) == 0 { info, err := n.RequestInfo(infoPolicy, "namespaces") @@ -231,7 +231,7 @@ func (a *Aerospike) getNamespaces(n *aerospike.Node, infoPolicy *aerospike.InfoP return namespaces, nil } -func (a *Aerospike) getNamespaceInfo(namespace string, n *aerospike.Node, infoPolicy *aerospike.InfoPolicy) (map[string]string, error) { +func (a *Aerospike) 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 @@ -259,7 +259,7 @@ func (a *Aerospike) parseNamespaceInfo(acc telegraf.Accumulator, stats map[strin acc.AddFields("aerospike_namespace", nFields, nTags, time.Now()) } -func (a *Aerospike) getSets(n *aerospike.Node, infoPolicy *aerospike.InfoPolicy) ([]string, error) { +func (a *Aerospike) getSets(n *as.Node, infoPolicy *as.InfoPolicy) ([]string, error) { var namespaceSets []string // Gather all sets if len(a.Sets) == 0 { @@ -296,7 +296,7 @@ func (a *Aerospike) getSets(n *aerospike.Node, infoPolicy *aerospike.InfoPolicy) return namespaceSets, nil } -func (a *Aerospike) getSetInfo(namespaceSet string, n *aerospike.Node, infoPolicy *aerospike.InfoPolicy) (map[string]string, error) { +func (a *Aerospike) 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 @@ -331,8 +331,8 @@ func (a *Aerospike) getTTLHistogram( hostPort string, namespace string, set string, - n *aerospike.Node, - infoPolicy *aerospike.InfoPolicy, + n *as.Node, + infoPolicy *as.InfoPolicy, ) error { stats, err := a.getHistogram(namespace, set, "ttl", n, infoPolicy) if err != nil { @@ -350,8 +350,8 @@ func (a *Aerospike) getObjectSizeLinearHistogram( hostPort string, namespace string, set string, - n *aerospike.Node, - infoPolicy *aerospike.InfoPolicy, + n *as.Node, + infoPolicy *as.InfoPolicy, ) error { stats, err := a.getHistogram(namespace, set, "object-size-linear", n, infoPolicy) if err != nil { @@ -368,8 +368,8 @@ func (a *Aerospike) getHistogram( namespace string, set string, histogramType string, - n *aerospike.Node, - infoPolicy *aerospike.InfoPolicy, + n *as.Node, + infoPolicy *as.InfoPolicy, ) (map[string]string, error) { var queryArg string if len(set) > 0 { diff --git a/plugins/inputs/azure_monitor/azure_monitor.go b/plugins/inputs/azure_monitor/azure_monitor.go index 46806a560022a..45c82f6bd2934 100644 --- a/plugins/inputs/azure_monitor/azure_monitor.go +++ b/plugins/inputs/azure_monitor/azure_monitor.go @@ -4,10 +4,11 @@ package azure_monitor import ( _ "embed" "fmt" + "sync" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "sync" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" diff --git a/plugins/inputs/azure_monitor/azure_monitor_test.go b/plugins/inputs/azure_monitor/azure_monitor_test.go index ffbfc4adaa991..8477a6a98cd09 100644 --- a/plugins/inputs/azure_monitor/azure_monitor_test.go +++ b/plugins/inputs/azure_monitor/azure_monitor_test.go @@ -5,11 +5,11 @@ import ( "encoding/json" "errors" "fmt" - "github.com/Azure/azure-sdk-for-go/sdk/azcore" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "os" "testing" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "github.com/influxdata/toml" diff --git a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go index 373379eae27a2..e5d88367c029b 100644 --- a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go +++ b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go @@ -16,7 +16,7 @@ import ( "sync" "time" - "github.com/cisco-ie/nx-telemetry-proto/mdt_dialout" + mdtdialout "github.com/cisco-ie/nx-telemetry-proto/mdt_dialout" "github.com/cisco-ie/nx-telemetry-proto/telemetry_bis" "google.golang.org/grpc" "google.golang.org/grpc/credentials" diff --git a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go index 4fb1a6789614a..30a75f09e991c 100644 --- a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go +++ b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/cisco-ie/nx-telemetry-proto/mdt_dialout" + mdtdialout "github.com/cisco-ie/nx-telemetry-proto/mdt_dialout" "github.com/cisco-ie/nx-telemetry-proto/telemetry_bis" "github.com/stretchr/testify/require" "google.golang.org/grpc" diff --git a/plugins/inputs/cloud_pubsub/subscription_gcp.go b/plugins/inputs/cloud_pubsub/subscription_gcp.go index f436d521923ce..86a76372f287f 100644 --- a/plugins/inputs/cloud_pubsub/subscription_gcp.go +++ b/plugins/inputs/cloud_pubsub/subscription_gcp.go @@ -1,9 +1,10 @@ package cloud_pubsub import ( - "cloud.google.com/go/pubsub" "context" "time" + + "cloud.google.com/go/pubsub" ) type ( diff --git a/plugins/inputs/eventhub_consumer/eventhub_consumer.go b/plugins/inputs/eventhub_consumer/eventhub_consumer.go index 6445117f990ed..48d28c3b9aa16 100644 --- a/plugins/inputs/eventhub_consumer/eventhub_consumer.go +++ b/plugins/inputs/eventhub_consumer/eventhub_consumer.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/Azure/azure-event-hubs-go/v3" + eventhub "github.com/Azure/azure-event-hubs-go/v3" "github.com/Azure/azure-event-hubs-go/v3/persist" "github.com/influxdata/telegraf" diff --git a/plugins/inputs/exec/run_windows.go b/plugins/inputs/exec/run_windows.go index 2d825a5ac1fcb..e88d268b46633 100644 --- a/plugins/inputs/exec/run_windows.go +++ b/plugins/inputs/exec/run_windows.go @@ -6,12 +6,13 @@ import ( "bytes" "fmt" "os" - osExec "os/exec" + "os/exec" "syscall" "time" - "github.com/influxdata/telegraf/internal" "github.com/kballard/go-shellquote" + + "github.com/influxdata/telegraf/internal" ) func (c CommandRunner) Run( @@ -24,7 +25,7 @@ func (c CommandRunner) Run( return nil, nil, fmt.Errorf("exec: unable to parse command: %w", err) } - cmd := osExec.Command(splitCmd[0], splitCmd[1:]...) + cmd := exec.Command(splitCmd[0], splitCmd[1:]...) cmd.SysProcAttr = &syscall.SysProcAttr{ CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP, } diff --git a/plugins/inputs/infiniband/infiniband_test.go b/plugins/inputs/infiniband/infiniband_test.go index ccaded0fc7e80..bb9d5de3cdc95 100644 --- a/plugins/inputs/infiniband/infiniband_test.go +++ b/plugins/inputs/infiniband/infiniband_test.go @@ -3,9 +3,11 @@ package infiniband import ( + "testing" + "github.com/Mellanox/rdmamap" + "github.com/influxdata/telegraf/testutil" - "testing" ) func TestInfiniband(t *testing.T) { diff --git a/plugins/inputs/intel_baseband/sock_connector_test.go b/plugins/inputs/intel_baseband/sock_connector_test.go index 76b6eb2a62e91..a290af3ea6dfa 100644 --- a/plugins/inputs/intel_baseband/sock_connector_test.go +++ b/plugins/inputs/intel_baseband/sock_connector_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "github.com/influxdata/telegraf/plugins/inputs/intel_baseband/mock" + mocks "github.com/influxdata/telegraf/plugins/inputs/intel_baseband/mock" ) func TestWriteCommandToSocket(t *testing.T) { diff --git a/plugins/inputs/jti_openconfig_telemetry/jti_openconfig_telemetry.go b/plugins/inputs/jti_openconfig_telemetry/jti_openconfig_telemetry.go index f8859f627c5f5..b572d8d346f38 100644 --- a/plugins/inputs/jti_openconfig_telemetry/jti_openconfig_telemetry.go +++ b/plugins/inputs/jti_openconfig_telemetry/jti_openconfig_telemetry.go @@ -24,8 +24,8 @@ import ( "github.com/influxdata/telegraf/config" common_tls "github.com/influxdata/telegraf/plugins/common/tls" "github.com/influxdata/telegraf/plugins/inputs" - "github.com/influxdata/telegraf/plugins/inputs/jti_openconfig_telemetry/auth" - "github.com/influxdata/telegraf/plugins/inputs/jti_openconfig_telemetry/oc" + authentication "github.com/influxdata/telegraf/plugins/inputs/jti_openconfig_telemetry/auth" + telemetry "github.com/influxdata/telegraf/plugins/inputs/jti_openconfig_telemetry/oc" ) //go:embed sample.conf diff --git a/plugins/inputs/ldap/ldap_test.go b/plugins/inputs/ldap/ldap_test.go index c67c57f56e39e..ad70654d5f2a5 100644 --- a/plugins/inputs/ldap/ldap_test.go +++ b/plugins/inputs/ldap/ldap_test.go @@ -272,7 +272,7 @@ func TestOpenLDAPReverseDNIntegration(t *testing.T) { testutil.RequireMetricsStructureEqual(t, expected, actual, testutil.IgnoreTime()) } -func TestOpenLDAPStarttls_internalegration(t *testing.T) { +func TestOpenLDAPStartTLSIntegration(t *testing.T) { if testing.Short() { t.Skip("Skipping integration test in short mode") } diff --git a/plugins/inputs/riemann_listener/riemann_listener.go b/plugins/inputs/riemann_listener/riemann_listener.go index 5777668a65396..b94c3f9371173 100644 --- a/plugins/inputs/riemann_listener/riemann_listener.go +++ b/plugins/inputs/riemann_listener/riemann_listener.go @@ -16,7 +16,7 @@ import ( "sync" "time" - "github.com/riemann/riemann-go-client" + riemanngo "github.com/riemann/riemann-go-client" riemango_proto "github.com/riemann/riemann-go-client/proto" "google.golang.org/protobuf/proto" diff --git a/plugins/inputs/zipkin/codec/thrift/gen-go/zipkincore/zipkinCore-consts.go b/plugins/inputs/zipkin/codec/thrift/gen-go/zipkincore/zipkinCore-consts.go index 7c5b5825acaa6..0dadbce643260 100644 --- a/plugins/inputs/zipkin/codec/thrift/gen-go/zipkincore/zipkinCore-consts.go +++ b/plugins/inputs/zipkin/codec/thrift/gen-go/zipkincore/zipkinCore-consts.go @@ -6,8 +6,9 @@ import ( "bytes" "context" "fmt" - "github.com/apache/thrift/lib/go/thrift" "time" + + "github.com/apache/thrift/lib/go/thrift" ) // (needed to ensure safety because of naive import list construction.) diff --git a/plugins/outputs/cloud_pubsub/topic_gcp.go b/plugins/outputs/cloud_pubsub/topic_gcp.go index 72ef50efcba79..acad7eb83cd9b 100644 --- a/plugins/outputs/cloud_pubsub/topic_gcp.go +++ b/plugins/outputs/cloud_pubsub/topic_gcp.go @@ -1,8 +1,9 @@ package cloud_pubsub import ( - "cloud.google.com/go/pubsub" "context" + + "cloud.google.com/go/pubsub" ) type (