From 8c73b4ea1eac9f206995efd947682df026940c45 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Wed, 20 Nov 2024 14:27:02 +0100 Subject: [PATCH] [chore]: enable gofumpt linter for extension (#36370) #### Description [gofumpt](https://golangci-lint.run/usage/linters/#gofumpt) enforces a stricter format than gofmt Part of https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/36363 Signed-off-by: Matthieu MOREL --- extension/awsproxy/config.go | 1 - extension/awsproxy/extension.go | 1 - extension/basicauthextension/config.go | 1 - .../basicauthextension/extension_test.go | 52 +++++++++---------- .../bearertokenauth_test.go | 8 +-- extension/bearertokenauthextension/config.go | 7 +-- .../avrologencodingextension/extension.go | 4 +- .../jaegerencodingextension/extension.go | 6 ++- .../jaegerencodingextension/jaeger.go | 6 +-- .../otlpencodingextension/extension_test.go | 8 +-- .../headerssetterextension/config_test.go | 3 +- extension/headerssetterextension/extension.go | 2 +- extension/healthcheckv2extension/extension.go | 8 +-- .../internal/http/server.go | 6 ++- extension/httpforwarderextension/config.go | 1 - extension/httpforwarderextension/extension.go | 2 +- .../httpforwarderextension/extension_test.go | 2 +- .../internal/grpc_test.go | 2 + .../jaegerremotesampling/internal/http.go | 4 +- extension/oauth2clientauthextension/config.go | 1 - extension/observer/ecsobserver/config.go | 1 - extension/observer/ecsobserver/fetcher.go | 3 +- .../ecsobserver/internal/ecsmock/service.go | 1 - extension/observer/ecsobserver/sd.go | 2 +- extension/observer/ecsobserver/target.go | 4 +- .../observer/ecstaskobserver/extension.go | 9 ++-- .../observer/hostobserver/extension_test.go | 3 +- extension/observer/k8sobserver/extension.go | 10 ++-- extension/observer/k8sobserver/handler.go | 6 ++- .../observer/k8sobserver/handler_test.go | 33 ++++++++---- .../observer/k8sobserver/k8s_fixtures_test.go | 28 +++++----- .../observer/k8sobserver/pod_endpoint_test.go | 16 ++++-- .../k8sobserver/service_endpoint_test.go | 3 +- extension/oidcauthextension/config.go | 1 - extension/opampextension/auth_test.go | 1 + extension/opampextension/opamp_agent.go | 8 +-- extension/pprofextension/config.go | 1 - .../extension.go | 2 +- extension/storage/filestorage/client.go | 8 +-- extension/storage/filestorage/config.go | 6 ++- extension/storage/filestorage/config_test.go | 1 + extension/storage/filestorage/extension.go | 1 - .../storage/filestorage/extension_test.go | 8 +-- extension/storage/storagetest/client.go | 6 +-- .../credentials/credentialsstore_localfs.go | 9 ++-- .../credentialsstore_localfs_test.go | 6 +-- .../sumologicextension/credentials/encrypt.go | 2 - extension/sumologicextension/extension.go | 6 ++- .../sumologicextension/extension_test.go | 5 +- 49 files changed, 171 insertions(+), 144 deletions(-) diff --git a/extension/awsproxy/config.go b/extension/awsproxy/config.go index a2d0f5f0c9f3..a568feaf5caa 100644 --- a/extension/awsproxy/config.go +++ b/extension/awsproxy/config.go @@ -9,7 +9,6 @@ import ( // Config defines the configuration for an AWS X-Ray proxy. type Config struct { - // ProxyServer defines configurations related to the local TCP proxy server. ProxyConfig proxy.Config `mapstructure:",squash"` } diff --git a/extension/awsproxy/extension.go b/extension/awsproxy/extension.go index 2b05655e7637..dddaf7700b6e 100644 --- a/extension/awsproxy/extension.go +++ b/extension/awsproxy/extension.go @@ -27,7 +27,6 @@ var _ extension.Extension = (*xrayProxy)(nil) func (x *xrayProxy) Start(_ context.Context, host component.Host) error { srv, err := proxy.NewServer(&x.config.ProxyConfig, x.settings.Logger) - if err != nil { return err } diff --git a/extension/basicauthextension/config.go b/extension/basicauthextension/config.go index 2a1cb40891fd..62aab9be2780 100644 --- a/extension/basicauthextension/config.go +++ b/extension/basicauthextension/config.go @@ -28,7 +28,6 @@ type ClientAuthSettings struct { Password configopaque.String `mapstructure:"password"` } type Config struct { - // Htpasswd settings. Htpasswd *HtpasswdSettings `mapstructure:"htpasswd,omitempty"` diff --git a/extension/basicauthextension/extension_test.go b/extension/basicauthextension/extension_test.go index 01569d3db242..2dab5cc5b8c7 100644 --- a/extension/basicauthextension/extension_test.go +++ b/extension/basicauthextension/extension_test.go @@ -17,33 +17,31 @@ import ( "go.opentelemetry.io/collector/component/componenttest" ) -var ( - credentials = [][]string{ - {"htpasswd-md5", "$apr1$FVVioVP7$ZdIWPG1p4E/ErujO7kA2n0"}, - {"openssl-apr1", "$apr1$peiE49Vv$lo.z77Z.6.a.Lm7GMjzQh0"}, - {"openssl-md5", "$1$mvmz31IB$U9KpHBLegga2doA0e3s3N0"}, - {"htpasswd-sha", "{SHA}vFznddje0Ht4+pmO0FaxwrUKN/M="}, - {"htpasswd-bcrypt", "$2y$10$Q6GeMFPd0dAxhQULPDdAn.DFy6NDmLaU0A7e2XoJz7PFYAEADFKbC"}, - {"", "$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s."}, - {"", "$2a$08$HqWuK6/Ng6sg9gQzbLrgb.Tl.ZHfXLhvt/SgVyWhQqgqcZ7ZuUtye"}, - {"", "$2a$10$k1wbIrmNyFAPwPVPSVa/zecw2BCEnBwVS2GbrmgzxFUOqW9dk4TCW"}, - {"", "$2a$12$k42ZFHFWqBp3vWli.nIn8uYyIkbvYRvodzbfbK18SSsY.CsIQPlxO"}, - {"a", "$2a$06$m0CrhHm10qJ3lXRY.5zDGO3rS2KdeeWLuGmsfGlMfOxih58VYVfxe"}, - {"a", "$2a$08$cfcvVd2aQ8CMvoMpP2EBfeodLEkkFJ9umNEfPD18.hUF62qqlC/V."}, - {"a", "$2a$10$k87L/MF28Q673VKh8/cPi.SUl7MU/rWuSiIDDFayrKk/1tBsSQu4u"}, - {"a", "$2a$12$8NJH3LsPrANStV6XtBakCez0cKHXVxmvxIlcz785vxAIZrihHZpeS"}, - {"abc", "$2a$06$If6bvum7DFjUnE9p2uDeDu0YHzrHM6tf.iqN8.yx.jNN1ILEf7h0i"}, - {"abcdefghijklmnopqrstuvwxyz", "$2a$06$.rCVZVOThsIa97pEDOxvGuRRgzG64bvtJ0938xuqzv18d3ZpQhstC"}, - {"abcdefghijklmnopqrstuvwxyz", "$2a$08$aTsUwsyowQuzRrDqFflhgekJ8d9/7Z3GV3UcgvzQW3J5zMyrTvlz."}, - {"abcdefghijklmnopqrstuvwxyz", "$2a$10$fVH8e28OQRj9tqiDXs1e1uxpsjN0c7II7YPKXua2NAKYvM6iQk7dq"}, - {"abcdefghijklmnopqrstuvwxyz", "$2a$12$D4G5f18o7aMMfwasBL7GpuQWuP3pkrZrOAnqP.bmezbMng.QwJ/pG"}, - {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$06$fPIsBO8qRqkjj273rfaOI.HtSV9jLDpTbZn782DC6/t7qT67P6FfO"}, - {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$08$Eq2r4G/76Wv39MzSX262huzPz612MZiYHVUJe/OcOql2jo4.9UxTW"}, - {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$10$LgfYWkbzEvQ4JakH7rOvHe0y8pHKF9OaFgwUZ2q7W2FFZmZzJYlfS"}, - {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$12$WApznUOJfkEGSmYRfnkrPOr466oFDCaj4b6HY3EXGvfxm43seyhgC"}, - {"ππππππππ", "$2a$10$.TtQJ4Jr6isd4Hp.mVfZeuh6Gws4rOQ/vdBczhDx.19NFK0Y84Dle"}, - } -) +var credentials = [][]string{ + {"htpasswd-md5", "$apr1$FVVioVP7$ZdIWPG1p4E/ErujO7kA2n0"}, + {"openssl-apr1", "$apr1$peiE49Vv$lo.z77Z.6.a.Lm7GMjzQh0"}, + {"openssl-md5", "$1$mvmz31IB$U9KpHBLegga2doA0e3s3N0"}, + {"htpasswd-sha", "{SHA}vFznddje0Ht4+pmO0FaxwrUKN/M="}, + {"htpasswd-bcrypt", "$2y$10$Q6GeMFPd0dAxhQULPDdAn.DFy6NDmLaU0A7e2XoJz7PFYAEADFKbC"}, + {"", "$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s."}, + {"", "$2a$08$HqWuK6/Ng6sg9gQzbLrgb.Tl.ZHfXLhvt/SgVyWhQqgqcZ7ZuUtye"}, + {"", "$2a$10$k1wbIrmNyFAPwPVPSVa/zecw2BCEnBwVS2GbrmgzxFUOqW9dk4TCW"}, + {"", "$2a$12$k42ZFHFWqBp3vWli.nIn8uYyIkbvYRvodzbfbK18SSsY.CsIQPlxO"}, + {"a", "$2a$06$m0CrhHm10qJ3lXRY.5zDGO3rS2KdeeWLuGmsfGlMfOxih58VYVfxe"}, + {"a", "$2a$08$cfcvVd2aQ8CMvoMpP2EBfeodLEkkFJ9umNEfPD18.hUF62qqlC/V."}, + {"a", "$2a$10$k87L/MF28Q673VKh8/cPi.SUl7MU/rWuSiIDDFayrKk/1tBsSQu4u"}, + {"a", "$2a$12$8NJH3LsPrANStV6XtBakCez0cKHXVxmvxIlcz785vxAIZrihHZpeS"}, + {"abc", "$2a$06$If6bvum7DFjUnE9p2uDeDu0YHzrHM6tf.iqN8.yx.jNN1ILEf7h0i"}, + {"abcdefghijklmnopqrstuvwxyz", "$2a$06$.rCVZVOThsIa97pEDOxvGuRRgzG64bvtJ0938xuqzv18d3ZpQhstC"}, + {"abcdefghijklmnopqrstuvwxyz", "$2a$08$aTsUwsyowQuzRrDqFflhgekJ8d9/7Z3GV3UcgvzQW3J5zMyrTvlz."}, + {"abcdefghijklmnopqrstuvwxyz", "$2a$10$fVH8e28OQRj9tqiDXs1e1uxpsjN0c7II7YPKXua2NAKYvM6iQk7dq"}, + {"abcdefghijklmnopqrstuvwxyz", "$2a$12$D4G5f18o7aMMfwasBL7GpuQWuP3pkrZrOAnqP.bmezbMng.QwJ/pG"}, + {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$06$fPIsBO8qRqkjj273rfaOI.HtSV9jLDpTbZn782DC6/t7qT67P6FfO"}, + {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$08$Eq2r4G/76Wv39MzSX262huzPz612MZiYHVUJe/OcOql2jo4.9UxTW"}, + {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$10$LgfYWkbzEvQ4JakH7rOvHe0y8pHKF9OaFgwUZ2q7W2FFZmZzJYlfS"}, + {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$12$WApznUOJfkEGSmYRfnkrPOr466oFDCaj4b6HY3EXGvfxm43seyhgC"}, + {"ππππππππ", "$2a$10$.TtQJ4Jr6isd4Hp.mVfZeuh6Gws4rOQ/vdBczhDx.19NFK0Y84Dle"}, +} func TestBasicAuth_Valid(t *testing.T) { t.Parallel() diff --git a/extension/bearertokenauthextension/bearertokenauth_test.go b/extension/bearertokenauthextension/bearertokenauth_test.go index 55d3cc6c3805..a6257a8511bd 100644 --- a/extension/bearertokenauthextension/bearertokenauth_test.go +++ b/extension/bearertokenauthextension/bearertokenauth_test.go @@ -127,7 +127,7 @@ func TestBearerStartWatchStop(t *testing.T) { assert.True(t, credential.RequireTransportSecurity()) // change file content once - assert.NoError(t, os.WriteFile(bauth.filename, []byte(fmt.Sprintf("%stest", token)), 0600)) + assert.NoError(t, os.WriteFile(bauth.filename, []byte(fmt.Sprintf("%stest", token)), 0o600)) time.Sleep(5 * time.Second) credential, _ = bauth.PerRPCCredentials() md, err = credential.GetRequestMetadata(context.Background()) @@ -136,7 +136,7 @@ func TestBearerStartWatchStop(t *testing.T) { assert.NoError(t, err) // change file content back - assert.NoError(t, os.WriteFile(bauth.filename, token, 0600)) + assert.NoError(t, os.WriteFile(bauth.filename, token, 0o600)) time.Sleep(5 * time.Second) credential, _ = bauth.PerRPCCredentials() md, err = credential.GetRequestMetadata(context.Background()) @@ -177,7 +177,7 @@ func TestBearerTokenFileContentUpdate(t *testing.T) { assert.Equal(t, authHeaderValue, fmt.Sprintf("%s %s", scheme, string(token))) // change file content once - assert.NoError(t, os.WriteFile(bauth.filename, []byte(fmt.Sprintf("%stest", token)), 0600)) + assert.NoError(t, os.WriteFile(bauth.filename, []byte(fmt.Sprintf("%stest", token)), 0o600)) time.Sleep(5 * time.Second) tokenNew, err := os.ReadFile(bauth.filename) @@ -191,7 +191,7 @@ func TestBearerTokenFileContentUpdate(t *testing.T) { assert.Equal(t, authHeaderValue, fmt.Sprintf("%s %s", scheme, string(tokenNew))) // change file content back - assert.NoError(t, os.WriteFile(bauth.filename, token, 0600)) + assert.NoError(t, os.WriteFile(bauth.filename, token, 0o600)) time.Sleep(5 * time.Second) // check if request is updated with the old token diff --git a/extension/bearertokenauthextension/config.go b/extension/bearertokenauthextension/config.go index f8513c1ef011..f136d635ea32 100644 --- a/extension/bearertokenauthextension/config.go +++ b/extension/bearertokenauthextension/config.go @@ -12,7 +12,6 @@ import ( // Config specifies how the Per-RPC bearer token based authentication data should be obtained. type Config struct { - // Scheme specifies the auth-scheme for the token. Defaults to "Bearer" Scheme string `mapstructure:"scheme,omitempty"` @@ -23,8 +22,10 @@ type Config struct { Filename string `mapstructure:"filename,omitempty"` } -var _ component.Config = (*Config)(nil) -var errNoTokenProvided = errors.New("no bearer token provided") +var ( + _ component.Config = (*Config)(nil) + errNoTokenProvided = errors.New("no bearer token provided") +) // Validate checks if the extension configuration is valid func (cfg *Config) Validate() error { diff --git a/extension/encoding/avrologencodingextension/extension.go b/extension/encoding/avrologencodingextension/extension.go index 522421823cec..32a2886d64ef 100644 --- a/extension/encoding/avrologencodingextension/extension.go +++ b/extension/encoding/avrologencodingextension/extension.go @@ -15,9 +15,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding" ) -var ( - _ encoding.LogsUnmarshalerExtension = (*avroLogExtension)(nil) -) +var _ encoding.LogsUnmarshalerExtension = (*avroLogExtension)(nil) type avroLogExtension struct { deserializer avroDeserializer diff --git a/extension/encoding/jaegerencodingextension/extension.go b/extension/encoding/jaegerencodingextension/extension.go index a035a589b970..97af945e3736 100644 --- a/extension/encoding/jaegerencodingextension/extension.go +++ b/extension/encoding/jaegerencodingextension/extension.go @@ -13,8 +13,10 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding" ) -var _ encoding.TracesUnmarshalerExtension = &jaegerExtension{} -var _ ptrace.Unmarshaler = &jaegerExtension{} +var ( + _ encoding.TracesUnmarshalerExtension = &jaegerExtension{} + _ ptrace.Unmarshaler = &jaegerExtension{} +) type jaegerExtension struct { config *Config diff --git a/extension/encoding/jaegerencodingextension/jaeger.go b/extension/encoding/jaegerencodingextension/jaeger.go index c3321882a9ff..3f56a723cdd1 100644 --- a/extension/encoding/jaegerencodingextension/jaeger.go +++ b/extension/encoding/jaegerencodingextension/jaeger.go @@ -13,8 +13,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" ) -type jaegerProtobufTrace struct { -} +type jaegerProtobufTrace struct{} func (j jaegerProtobufTrace) UnmarshalTraces(buf []byte) (ptrace.Traces, error) { span := &jaegerproto.Span{} @@ -25,8 +24,7 @@ func (j jaegerProtobufTrace) UnmarshalTraces(buf []byte) (ptrace.Traces, error) return jaegerSpanToTraces(span) } -type jaegerJSONTrace struct { -} +type jaegerJSONTrace struct{} func (j jaegerJSONTrace) UnmarshalTraces(buf []byte) (ptrace.Traces, error) { span := &jaegerproto.Span{} diff --git a/extension/encoding/otlpencodingextension/extension_test.go b/extension/encoding/otlpencodingextension/extension_test.go index 77e42e748108..ddb0df0ed780 100644 --- a/extension/encoding/otlpencodingextension/extension_test.go +++ b/extension/encoding/otlpencodingextension/extension_test.go @@ -147,7 +147,7 @@ func createAndExtension0(c *Config, t *testing.T) *otlpExtension { } func generateTraces() ptrace.Traces { - var num = 10 + num := 10 now := time.Now() md := ptrace.NewTraces() ilm := md.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty() @@ -162,7 +162,7 @@ func generateTraces() ptrace.Traces { } func generateLogs() plog.Logs { - var num = 10 + num := 10 md := plog.NewLogs() ilm := md.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty() ilm.LogRecords().EnsureCapacity(num) @@ -174,7 +174,7 @@ func generateLogs() plog.Logs { } func generateMetrics() pmetric.Metrics { - var num = 10 + num := 10 now := time.Now() startTime := pcommon.NewTimestampFromTime(now.Add(-10 * time.Second)) endTime := pcommon.NewTimestampFromTime(now) @@ -194,7 +194,7 @@ func generateMetrics() pmetric.Metrics { } func generateProfiles() pprofile.Profiles { - var num = 10 + num := 10 now := time.Now() pd := pprofile.NewProfiles() ilm := pd.ResourceProfiles().AppendEmpty().ScopeProfiles().AppendEmpty() diff --git a/extension/headerssetterextension/config_test.go b/extension/headerssetterextension/config_test.go index 188d116898a5..cfdef96f024c 100644 --- a/extension/headerssetterextension/config_test.go +++ b/extension/headerssetterextension/config_test.go @@ -36,7 +36,8 @@ func TestLoadConfig(t *testing.T) { Action: INSERT, FromContext: stringp("tenant_id"), Value: nil, - }, { + }, + { Key: stringp("X-Scope-OrgID"), Action: INSERT, FromContext: stringp("tenant_id"), diff --git a/extension/headerssetterextension/extension.go b/extension/headerssetterextension/extension.go index 72eb56278671..f9e3118d1946 100644 --- a/extension/headerssetterextension/extension.go +++ b/extension/headerssetterextension/extension.go @@ -35,7 +35,7 @@ func newHeadersSetterExtension(cfg *Config, logger *zap.Logger) (auth.Client, er Value: *header.Value, } } else if header.FromContext != nil { - var defaultValue = "" + defaultValue := "" if header.DefaultValue != nil { defaultValue = *header.DefaultValue } diff --git a/extension/healthcheckv2extension/extension.go b/extension/healthcheckv2extension/extension.go index 23a307c9a9cf..ba3594b2fa40 100644 --- a/extension/healthcheckv2extension/extension.go +++ b/extension/healthcheckv2extension/extension.go @@ -34,9 +34,11 @@ type healthCheckExtension struct { host component.Host } -var _ component.Component = (*healthCheckExtension)(nil) -var _ extensioncapabilities.ConfigWatcher = (*healthCheckExtension)(nil) -var _ extensioncapabilities.PipelineWatcher = (*healthCheckExtension)(nil) +var ( + _ component.Component = (*healthCheckExtension)(nil) + _ extensioncapabilities.ConfigWatcher = (*healthCheckExtension)(nil) + _ extensioncapabilities.PipelineWatcher = (*healthCheckExtension)(nil) +) func newExtension( ctx context.Context, diff --git a/extension/healthcheckv2extension/internal/http/server.go b/extension/healthcheckv2extension/internal/http/server.go index d38f9f3944c0..0d14bdd6e966 100644 --- a/extension/healthcheckv2extension/internal/http/server.go +++ b/extension/healthcheckv2extension/internal/http/server.go @@ -35,8 +35,10 @@ type Server struct { doneCh chan struct{} } -var _ component.Component = (*Server)(nil) -var _ extensioncapabilities.ConfigWatcher = (*Server)(nil) +var ( + _ component.Component = (*Server)(nil) + _ extensioncapabilities.ConfigWatcher = (*Server)(nil) +) func NewServer( config *Config, diff --git a/extension/httpforwarderextension/config.go b/extension/httpforwarderextension/config.go index 96d5b3f0a155..0ca9b602358f 100644 --- a/extension/httpforwarderextension/config.go +++ b/extension/httpforwarderextension/config.go @@ -9,7 +9,6 @@ import ( // Config defines configuration for http forwarder extension. type Config struct { - // Ingress holds config settings for HTTP server listening for requests. Ingress confighttp.ServerConfig `mapstructure:"ingress"` diff --git a/extension/httpforwarderextension/extension.go b/extension/httpforwarderextension/extension.go index 5ee39096a437..daa0e99ae1a7 100644 --- a/extension/httpforwarderextension/extension.go +++ b/extension/httpforwarderextension/extension.go @@ -116,7 +116,7 @@ func newHTTPForwarder(config *Config, settings component.TelemetrySettings) (ext return nil, errors.New("'egress.endpoint' config option cannot be empty") } - var url, err = url.Parse(config.Egress.Endpoint) + url, err := url.Parse(config.Egress.Endpoint) if err != nil { return nil, fmt.Errorf("enter a valid URL for 'egress.endpoint': %w", err) } diff --git a/extension/httpforwarderextension/extension_test.go b/extension/httpforwarderextension/extension_test.go index fb2106413a32..c398a70595bc 100644 --- a/extension/httpforwarderextension/extension_test.go +++ b/extension/httpforwarderextension/extension_test.go @@ -266,7 +266,7 @@ func readBody(body io.ReadCloser) []byte { } func getParsedURL(t *testing.T, rawURL string) *url.URL { - var url, err = url.Parse(rawURL) + url, err := url.Parse(rawURL) require.NoError(t, err) return url } diff --git a/extension/jaegerremotesampling/internal/grpc_test.go b/extension/jaegerremotesampling/internal/grpc_test.go index 931a88b08af0..40cc01de9998 100644 --- a/extension/jaegerremotesampling/internal/grpc_test.go +++ b/extension/jaegerremotesampling/internal/grpc_test.go @@ -94,9 +94,11 @@ func (g *grpcServerMock) Serve(_ net.Listener) error { g.quit = make(chan bool) return nil } + func (g *grpcServerMock) Stop() { g.quit <- true } + func (g *grpcServerMock) GracefulStop() { select { case <-g.quit: diff --git a/extension/jaegerremotesampling/internal/http.go b/extension/jaegerremotesampling/internal/http.go index 6bd406c0ef42..6ab9f75cba78 100644 --- a/extension/jaegerremotesampling/internal/http.go +++ b/extension/jaegerremotesampling/internal/http.go @@ -18,9 +18,7 @@ import ( "go.opentelemetry.io/collector/config/confighttp" ) -var ( - errMissingStrategyStore = errors.New("the strategy store has not been provided") -) +var errMissingStrategyStore = errors.New("the strategy store has not been provided") var _ component.Component = (*SamplingHTTPServer)(nil) diff --git a/extension/oauth2clientauthextension/config.go b/extension/oauth2clientauthextension/config.go index ea99916f4d73..ad4758052d2f 100644 --- a/extension/oauth2clientauthextension/config.go +++ b/extension/oauth2clientauthextension/config.go @@ -21,7 +21,6 @@ var ( // Config stores the configuration for OAuth2 Client Credentials (2-legged OAuth2 flow) setup. type Config struct { - // ClientID is the application's ID. // See https://datatracker.ietf.org/doc/html/rfc6749#section-2.2 ClientID string `mapstructure:"client_id"` diff --git a/extension/observer/ecsobserver/config.go b/extension/observer/ecsobserver/config.go index 0633995a25db..15615c1b3770 100644 --- a/extension/observer/ecsobserver/config.go +++ b/extension/observer/ecsobserver/config.go @@ -17,7 +17,6 @@ const ( ) type Config struct { - // ClusterName is the target ECS cluster name for service discovery. ClusterName string `mapstructure:"cluster_name" yaml:"cluster_name"` // ClusterRegion is the target ECS cluster's AWS region. diff --git a/extension/observer/ecsobserver/fetcher.go b/extension/observer/ecsobserver/fetcher.go index 4276ddfacf6f..f69dcf5223fa 100644 --- a/extension/observer/ecsobserver/fetcher.go +++ b/extension/observer/ecsobserver/fetcher.go @@ -289,7 +289,8 @@ func (f *taskFetcher) attachContainerInstance(ctx context.Context, tasks []*task // Run ecs.DescribeContainerInstances and ec2.DescribeInstances for a batch (less than 100 container instances). func (f *taskFetcher) describeContainerInstances(ctx context.Context, instanceList []*string, - ci2EC2 map[string]*ec2.Instance) error { + ci2EC2 map[string]*ec2.Instance, +) error { // Get container instances res, err := f.ecs.DescribeContainerInstancesWithContext(ctx, &ecs.DescribeContainerInstancesInput{ Cluster: aws.String(f.cluster), diff --git a/extension/observer/ecsobserver/internal/ecsmock/service.go b/extension/observer/ecsobserver/internal/ecsmock/service.go index 1d9dc1050d74..77ac558cd5e3 100644 --- a/extension/observer/ecsobserver/internal/ecsmock/service.go +++ b/extension/observer/ecsobserver/internal/ecsmock/service.go @@ -26,7 +26,6 @@ type PageLimit struct { DescribeServiceInput int // max 10 DescribeContainerInstanceInput int // max 100 DescribeInstanceOutput int // max 1000 - } func DefaultPageLimit() PageLimit { diff --git a/extension/observer/ecsobserver/sd.go b/extension/observer/ecsobserver/sd.go index cbf49bfa9f6f..234a7e181704 100644 --- a/extension/observer/ecsobserver/sd.go +++ b/extension/observer/ecsobserver/sd.go @@ -83,7 +83,7 @@ func (s *serviceDiscovery) runAndWriteFile(ctx context.Context) error { return err } // NOTE: We assume the folder already exists and does NOT try to create one. - if err := os.WriteFile(s.cfg.ResultFile, b, 0600); err != nil { + if err := os.WriteFile(s.cfg.ResultFile, b, 0o600); err != nil { return err } } diff --git a/extension/observer/ecsobserver/target.go b/extension/observer/ecsobserver/target.go index 70f8d0bb66a3..710ef631a2f7 100644 --- a/extension/observer/ecsobserver/target.go +++ b/extension/observer/ecsobserver/target.go @@ -121,9 +121,7 @@ func trimEmptyValueByKeyPrefix(m map[string]string, prefix string) { } } -var ( - invalidLabelCharRE = regexp.MustCompile(`[^a-zA-Z0-9_]`) -) +var invalidLabelCharRE = regexp.MustCompile(`[^a-zA-Z0-9_]`) // Copied from https://github.com/prometheus/prometheus/blob/8d2a8f493905e46fe6181e8c1b79ccdfcbdb57fc/util/strutil/strconv.go#L40-L44 func sanitizeLabelName(s string) string { diff --git a/extension/observer/ecstaskobserver/extension.go b/extension/observer/ecstaskobserver/extension.go index c800f86cc389..e74394d22771 100644 --- a/extension/observer/ecstaskobserver/extension.go +++ b/extension/observer/ecstaskobserver/extension.go @@ -19,9 +19,11 @@ import ( const runningStatus = "RUNNING" -var _ extension.Extension = (*ecsTaskObserver)(nil) -var _ observer.EndpointsLister = (*ecsTaskObserver)(nil) -var _ observer.Observable = (*ecsTaskObserver)(nil) +var ( + _ extension.Extension = (*ecsTaskObserver)(nil) + _ observer.EndpointsLister = (*ecsTaskObserver)(nil) + _ observer.Observable = (*ecsTaskObserver)(nil) +) type ecsTaskObserver struct { extension.Extension @@ -97,7 +99,6 @@ func (e *ecsTaskObserver) portFromLabels(labels map[string]string) uint16 { for _, portLabel := range e.config.PortLabels { if p, ok := labels[portLabel]; ok { port, err := strconv.ParseUint(p, 10, 16) - if err != nil { e.telemetry.Logger.Warn("failed parsing port label", zap.String("label", portLabel), zap.Error(err)) continue diff --git a/extension/observer/hostobserver/extension_test.go b/extension/observer/hostobserver/extension_test.go index e46aed434c2c..964136b84a4b 100644 --- a/extension/observer/hostobserver/extension_test.go +++ b/extension/observer/hostobserver/extension_test.go @@ -155,7 +155,8 @@ func getExpectedHost(host string, isIPv6 bool) string { func startAndStopObserver( t *testing.T, - getConnectionsOverride func() (conns []psnet.ConnectionStat, err error)) mockNotifier { + getConnectionsOverride func() (conns []psnet.ConnectionStat, err error), +) mockNotifier { ml := endpointsLister{ logger: zap.NewNop(), observerName: "host_observer/1", diff --git a/extension/observer/k8sobserver/extension.go b/extension/observer/k8sobserver/extension.go index ddb663c1955b..907b770e73fe 100644 --- a/extension/observer/k8sobserver/extension.go +++ b/extension/observer/k8sobserver/extension.go @@ -21,8 +21,10 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" ) -var _ extension.Extension = (*k8sObserver)(nil) -var _ observer.Observable = (*k8sObserver)(nil) +var ( + _ extension.Extension = (*k8sObserver)(nil) + _ observer.Observable = (*k8sObserver)(nil) +) type k8sObserver struct { *observer.EndpointsWatcher @@ -111,7 +113,7 @@ func newObserver(config *Config, set extension.Settings) (extension.Extension, e var serviceListerWatcher cache.ListerWatcher if config.ObserveServices { - var serviceSelector = fields.Everything() + serviceSelector := fields.Everything() set.Logger.Debug("observing services") serviceListerWatcher = cache.NewListWatchFromClient(restClient, "services", v1.NamespaceAll, serviceSelector) } @@ -130,7 +132,7 @@ func newObserver(config *Config, set extension.Settings) (extension.Extension, e var ingressListerWatcher cache.ListerWatcher if config.ObserveIngresses { - var ingressSelector = fields.Everything() + ingressSelector := fields.Everything() set.Logger.Debug("observing ingresses") ingressListerWatcher = cache.NewListWatchFromClient(client.NetworkingV1().RESTClient(), "ingresses", v1.NamespaceAll, ingressSelector) } diff --git a/extension/observer/k8sobserver/handler.go b/extension/observer/k8sobserver/handler.go index f1c89bb24b4b..7e1e64c03f21 100644 --- a/extension/observer/k8sobserver/handler.go +++ b/extension/observer/k8sobserver/handler.go @@ -15,8 +15,10 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer" ) -var _ cache.ResourceEventHandler = (*handler)(nil) -var _ observer.EndpointsLister = (*handler)(nil) +var ( + _ cache.ResourceEventHandler = (*handler)(nil) + _ observer.EndpointsLister = (*handler)(nil) +) // handler handles k8s cache informer callbacks. type handler struct { diff --git a/extension/observer/k8sobserver/handler_test.go b/extension/observer/k8sobserver/handler_test.go index d93275eb2ff3..5e74264c1707 100644 --- a/extension/observer/k8sobserver/handler_test.go +++ b/extension/observer/k8sobserver/handler_test.go @@ -48,7 +48,10 @@ func TestPodEndpointsAdded(t *testing.T) { Name: "pod-2", Namespace: "default", UID: "pod-2-UID", - Labels: map[string]string{"env": "prod"}}}}, + Labels: map[string]string{"env": "prod"}, + }, + }, + }, { ID: "test-1/pod-2-UID/https(443)", Target: "1.2.3.4:443", @@ -63,7 +66,8 @@ func TestPodEndpointsAdded(t *testing.T) { Port: 443, Transport: observer.ProtocolTCP, }, - }}, th.ListEndpoints()) + }, + }, th.ListEndpoints()) } func TestPodEndpointsRemoved(t *testing.T) { @@ -102,7 +106,9 @@ func TestPodEndpointsChanged(t *testing.T) { Name: "pod-2", Namespace: "default", UID: "pod-2-UID", - Labels: map[string]string{"env": "prod", "updated-label": "true"}}}, + Labels: map[string]string{"env": "prod", "updated-label": "true"}, + }, + }, { ID: "test-1/pod-2-UID/container-2", Target: "1.2.3.4", @@ -114,7 +120,10 @@ func TestPodEndpointsChanged(t *testing.T) { Name: "pod-2", Namespace: "default", UID: "pod-2-UID", - Labels: map[string]string{"env": "prod", "updated-label": "true"}}}}, + Labels: map[string]string{"env": "prod", "updated-label": "true"}, + }, + }, + }, { ID: "test-1/pod-2-UID/https(443)", Target: "1.2.3.4:443", @@ -123,9 +132,12 @@ func TestPodEndpointsChanged(t *testing.T) { Name: "pod-2", Namespace: "default", UID: "pod-2-UID", - Labels: map[string]string{"env": "prod", "updated-label": "true"}}, + Labels: map[string]string{"env": "prod", "updated-label": "true"}, + }, Port: 443, - Transport: observer.ProtocolTCP}}, + Transport: observer.ProtocolTCP, + }, + }, }, th.ListEndpoints()) } @@ -144,7 +156,8 @@ func TestServiceEndpointsAdded(t *testing.T) { ServiceType: "ClusterIP", ClusterIP: "1.2.3.4", }, - }}, th.ListEndpoints()) + }, + }, th.ListEndpoints()) } func TestServiceEndpointsRemoved(t *testing.T) { @@ -186,7 +199,8 @@ func TestServiceEndpointsChanged(t *testing.T) { Labels: map[string]string{"env": "prod", "updated-label": "true"}, ServiceType: "ClusterIP", ClusterIP: "1.2.3.4", - }}, + }, + }, }, th.ListEndpoints()) } @@ -206,7 +220,8 @@ func TestIngressEndpointsAdded(t *testing.T) { Host: "host-1", Path: "/", }, - }}, th.ListEndpoints()) + }, + }, th.ListEndpoints()) } func TestIngressEndpointsRemoved(t *testing.T) { diff --git a/extension/observer/k8sobserver/k8s_fixtures_test.go b/extension/observer/k8sobserver/k8s_fixtures_test.go index 506b2c27b42c..4ba6d62ee79e 100644 --- a/extension/observer/k8sobserver/k8s_fixtures_test.go +++ b/extension/observer/k8sobserver/k8s_fixtures_test.go @@ -39,12 +39,14 @@ func newPod(name, host string) *v1.Pod { return pod } -var pod1V1 = newPod("pod1", "localhost") -var pod1V2 = func() *v1.Pod { - pod := pod1V1.DeepCopy() - pod.Labels["pod-version"] = "2" - return pod -}() +var ( + pod1V1 = newPod("pod1", "localhost") + pod1V2 = func() *v1.Pod { + pod := pod1V1.DeepCopy() + pod.Labels["pod-version"] = "2" + return pod + }() +) var container1 = v1.Container{ Name: "container-1", @@ -276,9 +278,11 @@ func newNode(name, hostname string) *v1.Node { } } -var node1V1 = newNode("node1", "localhost") -var node1V2 = func() *v1.Node { - node := node1V1.DeepCopy() - node.Labels["node-version"] = "2" - return node -}() +var ( + node1V1 = newNode("node1", "localhost") + node1V2 = func() *v1.Node { + node := node1V1.DeepCopy() + node.Labels["node-version"] = "2" + return node + }() +) diff --git a/extension/observer/k8sobserver/pod_endpoint_test.go b/extension/observer/k8sobserver/pod_endpoint_test.go index d28953f982aa..8adeb20cab8d 100644 --- a/extension/observer/k8sobserver/pod_endpoint_test.go +++ b/extension/observer/k8sobserver/pod_endpoint_test.go @@ -20,7 +20,9 @@ func TestPodObjectToPortEndpoint(t *testing.T) { Name: "pod-2", Namespace: "default", UID: "pod-2-UID", - Labels: map[string]string{"env": "prod"}}}, + Labels: map[string]string{"env": "prod"}, + }, + }, { ID: "namespace/pod-2-UID/container-2", Target: "1.2.3.4", @@ -32,7 +34,10 @@ func TestPodObjectToPortEndpoint(t *testing.T) { Name: "pod-2", Namespace: "default", UID: "pod-2-UID", - Labels: map[string]string{"env": "prod"}}}}, + Labels: map[string]string{"env": "prod"}, + }, + }, + }, { ID: "namespace/pod-2-UID/https(443)", Target: "1.2.3.4:443", @@ -41,9 +46,12 @@ func TestPodObjectToPortEndpoint(t *testing.T) { Name: "pod-2", Namespace: "default", UID: "pod-2-UID", - Labels: map[string]string{"env": "prod"}}, + Labels: map[string]string{"env": "prod"}, + }, Port: 443, - Transport: observer.ProtocolTCP}}, + Transport: observer.ProtocolTCP, + }, + }, } endpoints := convertPodToEndpoints("namespace", podWithNamedPorts) diff --git a/extension/observer/k8sobserver/service_endpoint_test.go b/extension/observer/k8sobserver/service_endpoint_test.go index 391fd448b633..beda83a74c45 100644 --- a/extension/observer/k8sobserver/service_endpoint_test.go +++ b/extension/observer/k8sobserver/service_endpoint_test.go @@ -23,7 +23,8 @@ func TestServiceObjectToEndpoint(t *testing.T) { Labels: map[string]string{"env": "prod"}, ServiceType: "ClusterIP", ClusterIP: "1.2.3.4", - }}, + }, + }, } endpoints := convertServiceToEndpoints("namespace", serviceWithClusterIP) diff --git a/extension/oidcauthextension/config.go b/extension/oidcauthextension/config.go index 327baea5365f..ff4ef3cdd42f 100644 --- a/extension/oidcauthextension/config.go +++ b/extension/oidcauthextension/config.go @@ -5,7 +5,6 @@ package oidcauthextension // import "github.com/open-telemetry/opentelemetry-col // Config has the configuration for the OIDC Authenticator extension. type Config struct { - // The attribute (header name) to look for auth data. Optional, default value: "authorization". Attribute string `mapstructure:"attribute"` diff --git a/extension/opampextension/auth_test.go b/extension/opampextension/auth_test.go index 15f2c64bb9da..e8447d693b06 100644 --- a/extension/opampextension/auth_test.go +++ b/extension/opampextension/auth_test.go @@ -113,6 +113,7 @@ func (m mockAuthClient) RoundTripper(base http.RoundTripper) (http.RoundTripper, base: base, }, nil } + func (mockAuthClient) PerRPCCredentials() (credentials.PerRPCCredentials, error) { return nil, nil } diff --git a/extension/opampextension/opamp_agent.go b/extension/opampextension/opamp_agent.go index 3f16aa7f3349..3482dc4fc071 100644 --- a/extension/opampextension/opamp_agent.go +++ b/extension/opampextension/opamp_agent.go @@ -64,9 +64,11 @@ type opampAgent struct { customCapabilityRegistry *customCapabilityRegistry } -var _ opampcustommessages.CustomCapabilityRegistry = (*opampAgent)(nil) -var _ extensioncapabilities.Dependent = (*opampAgent)(nil) -var _ extensioncapabilities.ConfigWatcher = (*opampAgent)(nil) +var ( + _ opampcustommessages.CustomCapabilityRegistry = (*opampAgent)(nil) + _ extensioncapabilities.Dependent = (*opampAgent)(nil) + _ extensioncapabilities.ConfigWatcher = (*opampAgent)(nil) +) func (o *opampAgent) Start(ctx context.Context, host component.Host) error { o.reportFunc = func(event *componentstatus.Event) { diff --git a/extension/pprofextension/config.go b/extension/pprofextension/config.go index b289e2a05b52..0ab9149c6f67 100644 --- a/extension/pprofextension/config.go +++ b/extension/pprofextension/config.go @@ -11,7 +11,6 @@ import ( // Config has the configuration for the extension enabling the golang // net/http/pprof (Performance Profiler) extension. type Config struct { - // TCPAddr is the address and port in which the pprof will be listening to. // Use localhost: to make it available only locally, or ":" to // make it available on all network interfaces. diff --git a/extension/solarwindsapmsettingsextension/extension.go b/extension/solarwindsapmsettingsextension/extension.go index 9e81b1cadb8e..67804da75bb5 100644 --- a/extension/solarwindsapmsettingsextension/extension.go +++ b/extension/solarwindsapmsettingsextension/extension.go @@ -165,7 +165,7 @@ func refresh(extension *solarwindsapmSettingsExtension, filename string) { if content, err := json.Marshal(settings); err != nil { extension.telemetrySettings.Logger.Error("unable to marshal setting JSON[] byte from settings", zap.Error(err)) } else { - if err := os.WriteFile(filename, content, 0600); err != nil { + if err := os.WriteFile(filename, content, 0o600); err != nil { extension.telemetrySettings.Logger.Error("unable to write "+filename, zap.Error(err)) } else { if len(response.GetWarning()) > 0 { diff --git a/extension/storage/filestorage/client.go b/extension/storage/filestorage/client.go index b97cad73c044..bff4b03d283d 100644 --- a/extension/storage/filestorage/client.go +++ b/extension/storage/filestorage/client.go @@ -50,7 +50,7 @@ func bboltOptions(timeout time.Duration, noSync bool) *bbolt.Options { func newClient(logger *zap.Logger, filePath string, timeout time.Duration, compactionCfg *CompactionConfig, noSync bool) (*fileStorageClient, error) { options := bboltOptions(timeout, noSync) - db, err := bbolt.Open(filePath, 0600, options) + db, err := bbolt.Open(filePath, 0o600, options) if err != nil { return nil, err } @@ -188,7 +188,7 @@ func (c *fileStorageClient) Compact(compactionDirectory string, timeout time.Dur zap.String(tempDirectoryKey, file.Name())) // cannot reuse newClient as db shouldn't contain any bucket - compactedDb, err = bbolt.Open(file.Name(), 0600, options) + compactedDb, err = bbolt.Open(file.Name(), 0o600, options) if err != nil { return err } @@ -209,7 +209,7 @@ func (c *fileStorageClient) Compact(compactionDirectory string, timeout time.Dur // replace current db file with compacted db file // we reopen the DB file irrespective of the success of the replace, as we can't leave it closed moveErr := moveFileWithFallback(compactedDbPath, dbPath) - c.db, openErr = bbolt.Open(dbPath, 0600, options) + c.db, openErr = bbolt.Open(dbPath, 0o600, options) // if we got errors for both rename and open, we'd rather return the open one // this should not happen in any kind of normal circumstance - maybe we should panic instead? @@ -337,7 +337,7 @@ func moveFileWithFallback(src string, dest string) error { return err } - if err = os.WriteFile(dest, data, 0600); err != nil { + if err = os.WriteFile(dest, data, 0o600); err != nil { return err } diff --git a/extension/storage/filestorage/config.go b/extension/storage/filestorage/config.go index 8e665d6ad7d8..ef842a93b616 100644 --- a/extension/storage/filestorage/config.go +++ b/extension/storage/filestorage/config.go @@ -12,8 +12,10 @@ import ( "time" ) -var errInvalidOctal = errors.New("directory_permissions value must be a valid octal representation") -var errInvalidPermissionBits = errors.New("directory_permissions contain invalid bits for file access") +var ( + errInvalidOctal = errors.New("directory_permissions value must be a valid octal representation") + errInvalidPermissionBits = errors.New("directory_permissions contain invalid bits for file access") +) // Config defines configuration for file storage extension. type Config struct { diff --git a/extension/storage/filestorage/config_test.go b/extension/storage/filestorage/config_test.go index 8f14a3ec88fc..8fad1509698f 100644 --- a/extension/storage/filestorage/config_test.go +++ b/extension/storage/filestorage/config_test.go @@ -99,6 +99,7 @@ func TestHandleProvidingFilePathAsDirWithAnError(t *testing.T) { require.Error(t, err) require.EqualError(t, err, file.Name()+" is not a directory") } + func TestDirectoryCreateConfig(t *testing.T) { tests := []struct { name string diff --git a/extension/storage/filestorage/extension.go b/extension/storage/filestorage/extension.go index 4b8650892359..f26474e936c9 100644 --- a/extension/storage/filestorage/extension.go +++ b/extension/storage/filestorage/extension.go @@ -72,7 +72,6 @@ func (lfs *localFileStorage) GetClient(_ context.Context, kind component.Kind, e rawName = sanitize(rawName) absoluteName := filepath.Join(lfs.cfg.Directory, rawName) client, err := newClient(lfs.logger, absoluteName, lfs.cfg.Timeout, lfs.cfg.Compaction, !lfs.cfg.FSync) - if err != nil { return nil, err } diff --git a/extension/storage/filestorage/extension_test.go b/extension/storage/filestorage/extension_test.go index dd49cf9a2295..10f9b9a473a2 100644 --- a/extension/storage/filestorage/extension_test.go +++ b/extension/storage/filestorage/extension_test.go @@ -551,9 +551,9 @@ func TestDirectoryCreation(t *testing.T) { require.NoError(t, err) var expectedFileMode os.FileMode if runtime.GOOS == "windows" { // on Windows, we get 0777 for writable directories - expectedFileMode = os.FileMode(0777) + expectedFileMode = os.FileMode(0o777) } else { - expectedFileMode = os.FileMode(0750) + expectedFileMode = os.FileMode(0o750) } require.Equal(t, expectedFileMode, s.Mode()&os.ModePerm) }, @@ -576,9 +576,9 @@ func TestDirectoryCreation(t *testing.T) { require.NoError(t, err) var expectedFileMode os.FileMode if runtime.GOOS == "windows" { // on Windows, we get 0777 for writable directories - expectedFileMode = os.FileMode(0777) + expectedFileMode = os.FileMode(0o777) } else { - expectedFileMode = os.FileMode(0700) + expectedFileMode = os.FileMode(0o700) } require.Equal(t, expectedFileMode, s.Mode()&os.ModePerm) }, diff --git a/extension/storage/storagetest/client.go b/extension/storage/storagetest/client.go index 0b1a173fd836..97b99de4cfe4 100644 --- a/extension/storage/storagetest/client.go +++ b/extension/storage/storagetest/client.go @@ -16,9 +16,7 @@ import ( "go.opentelemetry.io/collector/extension/experimental/storage" ) -var ( - errClientClosed = errors.New("client closed") -) +var errClientClosed = errors.New("client closed") type TestClient struct { cache map[string][]byte @@ -139,7 +137,7 @@ func (p *TestClient) Close(_ context.Context) error { return err } - return os.WriteFile(p.storageFile, contents, os.FileMode(0600)) + return os.WriteFile(p.storageFile, contents, os.FileMode(0o600)) } const clientCreatorID = "client_creator_id" diff --git a/extension/sumologicextension/credentials/credentialsstore_localfs.go b/extension/sumologicextension/credentials/credentialsstore_localfs.go index 4d6283681582..1210d2abb1c0 100644 --- a/extension/sumologicextension/credentials/credentialsstore_localfs.go +++ b/extension/sumologicextension/credentials/credentialsstore_localfs.go @@ -133,7 +133,6 @@ func (cr LocalFsStore) Get(key string) (CollectorCredentials, error) { } creds, err := f(_getHasher(), key) - if err != nil { return CollectorCredentials{}, err } @@ -170,7 +169,7 @@ func (cr LocalFsStore) Store(key string, creds CollectorCredentials) error { return err } - if err = os.WriteFile(path, encryptedCreds, 0600); err != nil { + if err = os.WriteFile(path, encryptedCreds, 0o600); err != nil { return fmt.Errorf("failed to save credentials file '%s': %w", path, err, ) @@ -239,7 +238,7 @@ func (cr LocalFsStore) Validate() error { func ensureDir(path string) error { fi, err := os.Stat(path) if err != nil { - if err := os.Mkdir(path, 0700); err != nil { + if err := os.Mkdir(path, 0o700); err != nil { return err } return nil @@ -247,8 +246,8 @@ func ensureDir(path string) error { // If the directory doesn't have the execution bit then // set it so that we can 'exec' into it. - if fi.Mode().Perm() != 0700 { - if err := os.Chmod(path, 0700); err != nil { + if fi.Mode().Perm() != 0o700 { + if err := os.Chmod(path, 0o700); err != nil { return err } } diff --git a/extension/sumologicextension/credentials/credentialsstore_localfs_test.go b/extension/sumologicextension/credentials/credentialsstore_localfs_test.go index e367b9a0586b..2f857894e69f 100644 --- a/extension/sumologicextension/credentials/credentialsstore_localfs_test.go +++ b/extension/sumologicextension/credentials/credentialsstore_localfs_test.go @@ -69,11 +69,11 @@ func TestCredentialsStoreValidate(t *testing.T) { var expectedFileMode fs.FileMode dir := filepath.Join(t.TempDir(), "store") if runtime.GOOS == "windows" { // on Windows, we get 0777 for writable directories - expectedFileMode = fs.FileMode(0777) + expectedFileMode = fs.FileMode(0o777) } else { - expectedFileMode = fs.FileMode(0700) + expectedFileMode = fs.FileMode(0o700) } - err := os.Mkdir(dir, 0400) + err := os.Mkdir(dir, 0o400) require.NoError(t, err) store, err := NewLocalFsStore(WithCredentialsDirectory(dir), WithLogger(zap.NewNop())) diff --git a/extension/sumologicextension/credentials/encrypt.go b/extension/sumologicextension/credentials/encrypt.go index 986e1aa8a094..8a9dd35412ab 100644 --- a/extension/sumologicextension/credentials/encrypt.go +++ b/extension/sumologicextension/credentials/encrypt.go @@ -83,7 +83,6 @@ func encrypt(data []byte, encryptionKey []byte) ([]byte, error) { } ret, err := f(_getHasher(), data, encryptionKey) - if err != nil { return ret, err } @@ -115,7 +114,6 @@ func decrypt(data []byte, encryptionKey []byte) ([]byte, error) { } ret, err := f(_getHasher(), data, encryptionKey) - if err != nil { return ret, err } diff --git a/extension/sumologicextension/extension.go b/extension/sumologicextension/extension.go index 13904c184cdc..c0548299a050 100644 --- a/extension/sumologicextension/extension.go +++ b/extension/sumologicextension/extension.go @@ -621,8 +621,10 @@ func (se *SumologicExtension) heartbeatLoop() { } } -var errUnauthorizedHeartbeat = errors.New("heartbeat unauthorized") -var errUnauthorizedMetadata = errors.New("metadata update unauthorized") +var ( + errUnauthorizedHeartbeat = errors.New("heartbeat unauthorized") + errUnauthorizedMetadata = errors.New("metadata update unauthorized") +) type ErrorAPI struct { status int diff --git a/extension/sumologicextension/extension_test.go b/extension/sumologicextension/extension_test.go index 3773e004a02e..5ea1377a654f 100644 --- a/extension/sumologicextension/extension_test.go +++ b/extension/sumologicextension/extension_test.go @@ -31,7 +31,6 @@ import ( func setupTestMain(m *testing.M) { // Enable the feature gates before all tests to avoid flaky tests. err := featuregate.GlobalRegistry().Set(updateCollectorMetadataID, true) - if err != nil { panic("unable to set feature gates") } @@ -236,7 +235,7 @@ func TestStoreCredentials(t *testing.T) { cfg.CollectorCredentialsDirectory = dir // Ensure the directory has 600 permissions - require.NoError(t, os.Chmod(dir, 0600)) + require.NoError(t, os.Chmod(dir, 0o600)) se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0") require.NoError(t, err) @@ -261,7 +260,7 @@ func TestStoreCredentials(t *testing.T) { cfg.CollectorCredentialsDirectory = dir // Ensure the directory has 700 permissions - require.NoError(t, os.Chmod(dir, 0700)) + require.NoError(t, os.Chmod(dir, 0o700)) se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0") require.NoError(t, err)