Skip to content

Commit

Permalink
chore(linters): Enable import-alias-naming and `redundant-import-al…
Browse files Browse the repository at this point in the history
…ias` rules for revive
  • Loading branch information
zak-pawel committed Sep 3, 2024
1 parent 88bca70 commit 93a36f1
Show file tree
Hide file tree
Showing 109 changed files with 1,087 additions and 1,069 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ linters-settings:
arguments: [ 3 ]
- name: identical-branches
- name: if-return
- name: import-alias-naming
arguments:
- "^[a-z][a-z0-9_]*[a-z0-9]+$"
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
Expand All @@ -269,6 +272,7 @@ linters-settings:
- name: range-val-in-closure
- name: receiver-naming
- name: redefines-builtin-id
- name: redundant-import-alias
- name: string-of-int
- name: struct-tag
- name: superfluous-else
Expand Down
4 changes: 2 additions & 2 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bufio"
"compress/gzip"
"context"
cryptoRand "crypto/rand"
crypto_rand "crypto/rand"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -94,7 +94,7 @@ func ReadLines(filename string) ([]string, error) {
// RandomString returns a random string of alphanumeric characters
func RandomString(n int) (string, error) {
var bytes = make([]byte, n)
_, err := cryptoRand.Read(bytes)
_, err := crypto_rand.Read(bytes)
if err != nil {
return "", err
}
Expand Down
12 changes: 6 additions & 6 deletions plugins/aggregators/histogram/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/influxdata/telegraf"
telegrafConfig "github.com/influxdata/telegraf/config"
telegraf_config "github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/aggregators"
)

Expand All @@ -29,11 +29,11 @@ const bucketNegInf = "-Inf"

// HistogramAggregator is aggregator with histogram configs and particular histograms for defined metrics
type HistogramAggregator struct {
Configs []config `toml:"config"`
ResetBuckets bool `toml:"reset"`
Cumulative bool `toml:"cumulative"`
ExpirationInterval telegrafConfig.Duration `toml:"expiration_interval"`
PushOnlyOnUpdate bool `toml:"push_only_on_update"`
Configs []config `toml:"config"`
ResetBuckets bool `toml:"reset"`
Cumulative bool `toml:"cumulative"`
ExpirationInterval telegraf_config.Duration `toml:"expiration_interval"`
PushOnlyOnUpdate bool `toml:"push_only_on_update"`

buckets bucketsByMetrics
cache map[uint64]metricHistogramCollection
Expand Down
6 changes: 3 additions & 3 deletions plugins/aggregators/histogram/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf"
telegrafConfig "github.com/influxdata/telegraf/config"
telegraf_config "github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/metric"
"github.com/influxdata/telegraf/testutil"
)
Expand All @@ -26,7 +26,7 @@ func NewTestHistogramWithExpirationInterval(
reset bool,
cumulative bool,
pushOnlyOnUpdate bool,
expirationInterval telegrafConfig.Duration,
expirationInterval telegraf_config.Duration,
) telegraf.Aggregator {
htm := NewHistogramAggregator()
htm.Configs = cfg
Expand Down Expand Up @@ -435,7 +435,7 @@ func TestHistogramMetricExpiration(t *testing.T) {
{Metric: "first_metric_name", Fields: []string{"a"}, Buckets: []float64{0.0, 10.0, 20.0, 30.0, 40.0}},
{Metric: "second_metric_name", Buckets: []float64{0.0, 4.0, 10.0, 23.0, 30.0}},
}
histogram := NewTestHistogramWithExpirationInterval(cfg, false, true, false, telegrafConfig.Duration(30))
histogram := NewTestHistogramWithExpirationInterval(cfg, false, true, false, telegraf_config.Duration(30))

acc := &testutil.Accumulator{}

Expand Down
42 changes: 21 additions & 21 deletions plugins/common/aws/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package aws
import (
"context"

awsV2 "github.com/aws/aws-sdk-go-v2/aws"
configV2 "github.com/aws/aws-sdk-go-v2/config"
credentialsV2 "github.com/aws/aws-sdk-go-v2/credentials"
stscredsV2 "github.com/aws/aws-sdk-go-v2/credentials/stscreds"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
"github.com/aws/aws-sdk-go-v2/service/sts"
)

Expand All @@ -24,61 +24,61 @@ type CredentialConfig struct {
WebIdentityTokenFile string `toml:"web_identity_token_file"`
}

func (c *CredentialConfig) Credentials() (awsV2.Config, error) {
func (c *CredentialConfig) Credentials() (aws.Config, error) {
if c.RoleARN != "" {
return c.configWithAssumeCredentials()
}
return c.configWithRootCredentials()
}

func (c *CredentialConfig) configWithRootCredentials() (awsV2.Config, error) {
options := []func(*configV2.LoadOptions) error{
configV2.WithRegion(c.Region),
func (c *CredentialConfig) configWithRootCredentials() (aws.Config, error) {
options := []func(*config.LoadOptions) error{
config.WithRegion(c.Region),
}

if c.Profile != "" {
options = append(options, configV2.WithSharedConfigProfile(c.Profile))
options = append(options, config.WithSharedConfigProfile(c.Profile))
}
if c.Filename != "" {
options = append(options, configV2.WithSharedCredentialsFiles([]string{c.Filename}))
options = append(options, config.WithSharedCredentialsFiles([]string{c.Filename}))
}

if c.AccessKey != "" || c.SecretKey != "" {
provider := credentialsV2.NewStaticCredentialsProvider(c.AccessKey, c.SecretKey, c.Token)
options = append(options, configV2.WithCredentialsProvider(provider))
provider := credentials.NewStaticCredentialsProvider(c.AccessKey, c.SecretKey, c.Token)
options = append(options, config.WithCredentialsProvider(provider))
}

return configV2.LoadDefaultConfig(context.Background(), options...)
return config.LoadDefaultConfig(context.Background(), options...)
}

func (c *CredentialConfig) configWithAssumeCredentials() (awsV2.Config, error) {
func (c *CredentialConfig) configWithAssumeCredentials() (aws.Config, error) {
// To generate credentials using assumeRole, we need to create AWS STS client with the default AWS endpoint,
defaultConfig, err := c.configWithRootCredentials()
if err != nil {
return awsV2.Config{}, err
return aws.Config{}, err
}

var provider awsV2.CredentialsProvider
var provider aws.CredentialsProvider
stsService := sts.NewFromConfig(defaultConfig)
if c.WebIdentityTokenFile != "" {
provider = stscredsV2.NewWebIdentityRoleProvider(
provider = stscreds.NewWebIdentityRoleProvider(
stsService,
c.RoleARN,
stscredsV2.IdentityTokenFile(c.WebIdentityTokenFile),
func(opts *stscredsV2.WebIdentityRoleOptions) {
stscreds.IdentityTokenFile(c.WebIdentityTokenFile),
func(opts *stscreds.WebIdentityRoleOptions) {
if c.RoleSessionName != "" {
opts.RoleSessionName = c.RoleSessionName
}
},
)
} else {
provider = stscredsV2.NewAssumeRoleProvider(stsService, c.RoleARN, func(opts *stscredsV2.AssumeRoleOptions) {
provider = stscreds.NewAssumeRoleProvider(stsService, c.RoleARN, func(opts *stscreds.AssumeRoleOptions) {
if c.RoleSessionName != "" {
opts.RoleSessionName = c.RoleSessionName
}
})
}

defaultConfig.Credentials = awsV2.NewCredentialsCache(provider)
defaultConfig.Credentials = aws.NewCredentialsCache(provider)
return defaultConfig, nil
}
4 changes: 2 additions & 2 deletions plugins/common/http/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/common/cookie"
oauthConfig "github.com/influxdata/telegraf/plugins/common/oauth"
"github.com/influxdata/telegraf/plugins/common/oauth"
"github.com/influxdata/telegraf/plugins/common/proxy"
"github.com/influxdata/telegraf/plugins/common/tls"
)
Expand All @@ -27,7 +27,7 @@ type HTTPClientConfig struct {

proxy.HTTPProxy
tls.ClientConfig
oauthConfig.OAuth2Config
oauth.OAuth2Config
cookie.CookieAuthConfig
}

Expand Down
22 changes: 11 additions & 11 deletions plugins/common/kafka/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/IBM/sarama"

"github.com/influxdata/telegraf"
tgConf "github.com/influxdata/telegraf/config"
telegraf_config "github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/common/tls"
)

Expand Down Expand Up @@ -55,16 +55,16 @@ type Config struct {
SASLAuth
tls.ClientConfig

Version string `toml:"version"`
ClientID string `toml:"client_id"`
CompressionCodec int `toml:"compression_codec"`
EnableTLS *bool `toml:"enable_tls"`
KeepAlivePeriod *tgConf.Duration `toml:"keep_alive_period"`
Version string `toml:"version"`
ClientID string `toml:"client_id"`
CompressionCodec int `toml:"compression_codec"`
EnableTLS *bool `toml:"enable_tls"`
KeepAlivePeriod *telegraf_config.Duration `toml:"keep_alive_period"`

MetadataRetryMax int `toml:"metadata_retry_max"`
MetadataRetryType string `toml:"metadata_retry_type"`
MetadataRetryBackoff tgConf.Duration `toml:"metadata_retry_backoff"`
MetadataRetryMaxDuration tgConf.Duration `toml:"metadata_retry_max_duration"`
MetadataRetryMax int `toml:"metadata_retry_max"`
MetadataRetryType string `toml:"metadata_retry_type"`
MetadataRetryBackoff telegraf_config.Duration `toml:"metadata_retry_backoff"`
MetadataRetryMaxDuration telegraf_config.Duration `toml:"metadata_retry_max_duration"`

// Disable full metadata fetching
MetadataFull *bool `toml:"metadata_full"`
Expand Down Expand Up @@ -145,7 +145,7 @@ func (k *Config) SetConfig(config *sarama.Config, log telegraf.Logger) error {
return errors.New("invalid metadata retry type")
case "exponential":
if k.MetadataRetryBackoff == 0 {
k.MetadataRetryBackoff = tgConf.Duration(250 * time.Millisecond)
k.MetadataRetryBackoff = telegraf_config.Duration(250 * time.Millisecond)
log.Warnf("metadata_retry_backoff is 0, using %s", time.Duration(k.MetadataRetryBackoff))
}
config.Metadata.Retry.BackoffFunc = makeBackoffFunc(
Expand Down
14 changes: 7 additions & 7 deletions plugins/common/proxy/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"net/http"
"net/url"

netProxy "golang.org/x/net/proxy"
"golang.org/x/net/proxy"
)

// httpConnectProxy proxies (only?) TCP over a HTTP tunnel using the CONNECT method
type httpConnectProxy struct {
forward netProxy.Dialer
forward proxy.Dialer
url *url.URL
}

Expand All @@ -25,7 +25,7 @@ func (c *httpConnectProxy) DialContext(ctx context.Context, network, addr string

var proxyConn net.Conn
var err error
if dialer, ok := c.forward.(netProxy.ContextDialer); ok {
if dialer, ok := c.forward.(proxy.ContextDialer); ok {
proxyConn, err = dialer.DialContext(ctx, "tcp", c.url.Host)
} else {
shim := contextDialerShim{c.forward}
Expand Down Expand Up @@ -93,22 +93,22 @@ func (c *httpConnectProxy) Dial(network, addr string) (net.Conn, error) {
return c.DialContext(context.Background(), network, addr)
}

func newHTTPConnectProxy(proxyURL *url.URL, forward netProxy.Dialer) (netProxy.Dialer, error) {
func newHTTPConnectProxy(proxyURL *url.URL, forward proxy.Dialer) (proxy.Dialer, error) {
return &httpConnectProxy{forward, proxyURL}, nil
}

func init() {
// Register new proxy types
netProxy.RegisterDialerType("http", newHTTPConnectProxy)
netProxy.RegisterDialerType("https", newHTTPConnectProxy)
proxy.RegisterDialerType("http", newHTTPConnectProxy)
proxy.RegisterDialerType("https", newHTTPConnectProxy)
}

// contextDialerShim allows cancellation of the dial from a context even if the underlying
// dialer does not implement `proxy.ContextDialer`. Arguably, this shouldn't actually get run,
// unless a new proxy type is added that doesn't implement `proxy.ContextDialer`, as all the
// standard library dialers implement `proxy.ContextDialer`.
type contextDialerShim struct {
dialer netProxy.Dialer
dialer proxy.Dialer
}

func (cd *contextDialerShim) Dial(network, addr string) (net.Conn, error) {
Expand Down
6 changes: 3 additions & 3 deletions plugins/common/proxy/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
"net"
"time"

netProxy "golang.org/x/net/proxy"
"golang.org/x/net/proxy"
)

type ProxiedDialer struct {
dialer netProxy.Dialer
dialer proxy.Dialer
}

func (pd *ProxiedDialer) Dial(network, addr string) (net.Conn, error) {
return pd.dialer.Dial(network, addr)
}

func (pd *ProxiedDialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error) {
if contextDialer, ok := pd.dialer.(netProxy.ContextDialer); ok {
if contextDialer, ok := pd.dialer.(proxy.ContextDialer); ok {
return contextDialer.DialContext(ctx, network, addr)
}

Expand Down
8 changes: 4 additions & 4 deletions plugins/common/shim/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf"
tgConfig "github.com/influxdata/telegraf/config"
telegraf_config "github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/telegraf/plugins/processors"
)
Expand Down Expand Up @@ -61,9 +61,9 @@ func TestLoadingProcessorWithConfig(t *testing.T) {
}

type testDurationInput struct {
Duration tgConfig.Duration `toml:"duration"`
Size tgConfig.Size `toml:"size"`
Hex int64 `toml:"hex"`
Duration telegraf_config.Duration `toml:"duration"`
Size telegraf_config.Size `toml:"size"`
Hex int64 `toml:"hex"`
}

func (i *testDurationInput) SampleConfig() string {
Expand Down
4 changes: 2 additions & 2 deletions plugins/common/shim/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/metric"
"github.com/influxdata/telegraf/plugins/parsers/influx"
influxSerializer "github.com/influxdata/telegraf/plugins/serializers/influx"
influx_serializer "github.com/influxdata/telegraf/plugins/serializers/influx"
)

func TestProcessorShim(t *testing.T) {
Expand Down Expand Up @@ -52,7 +52,7 @@ func testSendAndReceive(t *testing.T, fieldKey string, fieldValue string) {
wg.Done()
}()

serializer := &influxSerializer.Serializer{}
serializer := &influx_serializer.Serializer{}
require.NoError(t, serializer.Init())

parser := influx.Parser{}
Expand Down
4 changes: 2 additions & 2 deletions plugins/common/socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
tlsint "github.com/influxdata/telegraf/plugins/common/tls"
common_tls "github.com/influxdata/telegraf/plugins/common/tls"
)

type CallbackData func(net.Addr, []byte)
Expand All @@ -34,7 +34,7 @@ type Config struct {
SocketMode string `toml:"socket_mode"`
ContentEncoding string `toml:"content_encoding"`
MaxDecompressionSize config.Size `toml:"max_decompression_size"`
tlsint.ServerConfig
common_tls.ServerConfig
}

type Socket struct {
Expand Down
Loading

0 comments on commit 93a36f1

Please sign in to comment.