Skip to content

Commit b2b5c49

Browse files
mjlshenAkshayS198
authored andcommitted
[processor/resourcedetection] update to aws-sdk-go-v2 (open-telemetry#39368)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description aws-sdk-go is being [deprecated on July 31, 2025](https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-go-v1-on-july-31-2025/). This PR updates `processor/resourcedetection` to aws-sdk-go-v2. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#37730 <!--Describe what testing was performed and which tests were added.--> #### Testing I converted the existing unit tests to aws-sdk-go-v2 as well, keeping the original intent of the tests. Signed-off-by: Michael Shen <[email protected]>
1 parent 2a46f85 commit b2b5c49

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

processor/resourcedetectionprocessor/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.23.0
55
require (
66
cloud.google.com/go/compute/metadata v0.6.0
77
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0
8-
github.com/aws/aws-sdk-go v1.55.6
98
github.com/aws/aws-sdk-go-v2 v1.36.3
109
github.com/aws/aws-sdk-go-v2/config v1.29.13
1110
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30
@@ -93,7 +92,6 @@ require (
9392
github.com/hashicorp/go-version v1.7.0 // indirect
9493
github.com/hashicorp/golang-lru v1.0.2 // indirect
9594
github.com/hashicorp/serf v0.10.1 // indirect
96-
github.com/jmespath/go-jmespath v0.4.0 // indirect
9795
github.com/josharian/intern v1.0.0 // indirect
9896
github.com/json-iterator/go v1.1.12 // indirect
9997
github.com/klauspost/compress v1.18.0 // indirect

processor/resourcedetectionprocessor/go.sum

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/resourcedetectionprocessor/internal/aws/eks/detector.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"os"
1111
"strings"
1212

13-
"github.com/aws/aws-sdk-go/aws"
14-
"github.com/aws/aws-sdk-go/aws/ec2metadata"
15-
"github.com/aws/aws-sdk-go/aws/session"
16-
"github.com/aws/aws-sdk-go/service/ec2"
13+
"github.com/aws/aws-sdk-go-v2/config"
14+
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
15+
"github.com/aws/aws-sdk-go-v2/service/ec2"
16+
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
1717
"go.opentelemetry.io/collector/pdata/pcommon"
1818
"go.opentelemetry.io/collector/processor"
1919
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
@@ -43,7 +43,7 @@ const (
4343
type detectorUtils interface {
4444
getConfigMap(ctx context.Context, namespace string, name string) (map[string]string, error)
4545
getClusterName(ctx context.Context, logger *zap.Logger) string
46-
getClusterNameTagFromReservations([]*ec2.Reservation) string
46+
getClusterNameTagFromReservations([]types.Reservation) string
4747
getCloudAccountID(ctx context.Context, logger *zap.Logger) string
4848
}
4949

@@ -142,29 +142,31 @@ func (e eksDetectorUtils) getConfigMap(ctx context.Context, namespace string, na
142142

143143
func (e eksDetectorUtils) getClusterName(ctx context.Context, logger *zap.Logger) string {
144144
defaultErrorMessage := "Unable to get EKS cluster name"
145-
sess, err := session.NewSession()
145+
cfg, err := config.LoadDefaultConfig(ctx)
146146
if err != nil {
147147
logger.Warn(defaultErrorMessage, zap.Error(err))
148148
return ""
149149
}
150150

151-
ec2Svc := ec2metadata.New(sess)
152-
region, err := ec2Svc.Region()
151+
imdsClient := imds.NewFromConfig(cfg)
152+
resp, err := imdsClient.GetRegion(ctx, &imds.GetRegionInput{})
153153
if err != nil {
154154
logger.Warn(defaultErrorMessage, zap.Error(err))
155155
return ""
156156
}
157157

158-
svc := ec2.New(sess, aws.NewConfig().WithRegion(region))
159-
instanceIdentityDocument, err := ec2Svc.GetInstanceIdentityDocumentWithContext(ctx)
158+
cfg.Region = resp.Region
159+
ec2Client := ec2.NewFromConfig(cfg)
160+
161+
instanceIdentityDocument, err := imdsClient.GetInstanceIdentityDocument(ctx, &imds.GetInstanceIdentityDocumentInput{})
160162
if err != nil {
161163
logger.Warn(defaultErrorMessage, zap.Error(err))
162164
return ""
163165
}
164166

165-
instances, err := svc.DescribeInstances(&ec2.DescribeInstancesInput{
166-
InstanceIds: []*string{
167-
aws.String(instanceIdentityDocument.InstanceID),
167+
instances, err := ec2Client.DescribeInstances(ctx, &ec2.DescribeInstancesInput{
168+
InstanceIds: []string{
169+
instanceIdentityDocument.InstanceID,
168170
},
169171
})
170172
if err != nil {
@@ -181,7 +183,7 @@ func (e eksDetectorUtils) getClusterName(ctx context.Context, logger *zap.Logger
181183
return clusterName
182184
}
183185

184-
func (e eksDetectorUtils) getClusterNameTagFromReservations(reservations []*ec2.Reservation) string {
186+
func (e eksDetectorUtils) getClusterNameTagFromReservations(reservations []types.Reservation) string {
185187
for _, reservation := range reservations {
186188
for _, instance := range reservation.Instances {
187189
for _, tag := range instance.Tags {
@@ -203,14 +205,14 @@ func (e eksDetectorUtils) getClusterNameTagFromReservations(reservations []*ec2.
203205

204206
func (e eksDetectorUtils) getCloudAccountID(ctx context.Context, logger *zap.Logger) string {
205207
defaultErrorMessage := "Unable to get EKS cluster account ID"
206-
sess, err := session.NewSession()
208+
cfg, err := config.LoadDefaultConfig(ctx)
207209
if err != nil {
208210
logger.Warn(defaultErrorMessage, zap.Error(err))
209211
return ""
210212
}
211213

212-
ec2Svc := ec2metadata.New(sess)
213-
instanceIdentityDocument, err := ec2Svc.GetInstanceIdentityDocumentWithContext(ctx)
214+
imdsClient := imds.NewFromConfig(cfg)
215+
instanceIdentityDocument, err := imdsClient.GetInstanceIdentityDocument(ctx, &imds.GetInstanceIdentityDocumentInput{})
214216
if err != nil {
215217
logger.Warn(defaultErrorMessage, zap.Error(err))
216218
return ""

processor/resourcedetectionprocessor/internal/aws/eks/detector_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"context"
88
"testing"
99

10-
"github.com/aws/aws-sdk-go/service/ec2"
10+
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/mock"
1313
"github.com/stretchr/testify/require"
@@ -33,11 +33,11 @@ func (detectorUtils *MockDetectorUtils) getConfigMap(_ context.Context, namespac
3333
}
3434

3535
func (detectorUtils *MockDetectorUtils) getClusterName(_ context.Context, _ *zap.Logger) string {
36-
var reservations []*ec2.Reservation
36+
var reservations []types.Reservation
3737
return detectorUtils.getClusterNameTagFromReservations(reservations)
3838
}
3939

40-
func (detectorUtils *MockDetectorUtils) getClusterNameTagFromReservations(_ []*ec2.Reservation) string {
40+
func (detectorUtils *MockDetectorUtils) getClusterNameTagFromReservations(_ []types.Reservation) string {
4141
return clusterName
4242
}
4343

0 commit comments

Comments
 (0)