From f3918eda2c1ee73e232445dcaed4c5036b7c3cf7 Mon Sep 17 00:00:00 2001 From: Chad Patel Date: Thu, 19 Dec 2024 16:32:54 -0600 Subject: [PATCH] fix linter errors --- extension/entitystore/extension_test.go | 2 +- extension/entitystore/serviceprovider.go | 3 ++- internal/ec2metadataprovider/ec2metadataprovider.go | 8 ++++---- plugins/processors/ec2tagger/ec2tagger_test.go | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/extension/entitystore/extension_test.go b/extension/entitystore/extension_test.go index 172d2dc49d..982be1ee47 100644 --- a/extension/entitystore/extension_test.go +++ b/extension/entitystore/extension_test.go @@ -109,7 +109,7 @@ func (m *mockMetadataProvider) InstanceID(ctx context.Context) (string, error) { return "MockInstanceID", nil } -func (m *mockMetadataProvider) InstanceTags(ctx context.Context) ([]string, error) { +func (m *mockMetadataProvider) InstanceTags(_ context.Context) ([]string, error) { if m.InstanceTagError { return nil, errors.New("an error occurred for instance tag retrieval") } diff --git a/extension/entitystore/serviceprovider.go b/extension/entitystore/serviceprovider.go index e2718430af..b43fceeea5 100644 --- a/extension/entitystore/serviceprovider.go +++ b/extension/entitystore/serviceprovider.go @@ -266,7 +266,7 @@ func (s *serviceprovider) scrapeImdsServiceNameAndASG() error { } } // case sensitive - if originalCaseKey, _ := lowerTagKeys[strings.ToLower(ec2tagger.Ec2InstanceTagKeyASG)]; originalCaseKey == ec2tagger.Ec2InstanceTagKeyASG { + if originalCaseKey := lowerTagKeys[strings.ToLower(ec2tagger.Ec2InstanceTagKeyASG)]; originalCaseKey == ec2tagger.Ec2InstanceTagKeyASG { asg, err := s.metadataProvider.InstanceTagValue(context.Background(), ec2tagger.Ec2InstanceTagKeyASG) if err == nil { s.logger.Debug("AutoScalingGroup retrieved through IMDS") @@ -279,6 +279,7 @@ func (s *serviceprovider) scrapeImdsServiceNameAndASG() error { s.mutex.Unlock() } } + if s.GetIMDSServiceName() == "" { s.logger.Debug("Service name not found through IMDS") } diff --git a/internal/ec2metadataprovider/ec2metadataprovider.go b/internal/ec2metadataprovider/ec2metadataprovider.go index 146fbc775c..5134c1ce5a 100644 --- a/internal/ec2metadataprovider/ec2metadataprovider.go +++ b/internal/ec2metadataprovider/ec2metadataprovider.go @@ -69,13 +69,13 @@ func (c *metadataClient) ClientIAMRole(ctx context.Context) (string, error) { } func (c *metadataClient) InstanceTags(ctx context.Context) ([]string, error) { - if tags, err := withMetadataFallbackRetry(ctx, c, func(metadataClient *ec2metadata.EC2Metadata) (string, error) { + tags, err := withMetadataFallbackRetry(ctx, c, func(metadataClient *ec2metadata.EC2Metadata) (string, error) { return metadataClient.GetMetadataWithContext(ctx, "tags/instance") - }); err != nil { + }) + if err != nil { return nil, err - } else { - return strings.Fields(tags), nil } + return strings.Fields(tags), nil } func (c *metadataClient) InstanceTagValue(ctx context.Context, tagKey string) (string, error) { diff --git a/plugins/processors/ec2tagger/ec2tagger_test.go b/plugins/processors/ec2tagger/ec2tagger_test.go index 0d12c0cefe..93642e3c6e 100644 --- a/plugins/processors/ec2tagger/ec2tagger_test.go +++ b/plugins/processors/ec2tagger/ec2tagger_test.go @@ -144,7 +144,7 @@ func (m *mockMetadataProvider) InstanceID(ctx context.Context) (string, error) { return "MockInstanceID", nil } -func (m *mockMetadataProvider) InstanceTags(ctx context.Context) ([]string, error) { +func (m *mockMetadataProvider) InstanceTags(_ context.Context) ([]string, error) { return []string{"MockInstanceTag"}, nil }