Skip to content

Commit 718753e

Browse files
authored
[internal/aws] Migrate k8s and xray/testdata to aws-sdk-go-v2 (#39497)
#### Description Migrates all usages of the deprecated aws-sdk-go -> aws-sdk-go-v2 in the k8s and xray/testdata packages of internal/aws. These usages are small and contained compared to the other usages remaining in internal/aws. #### Link to tracking issue Related to #37728 #### Testing I followed https://github.com/kgeckhart/opentelemetry-collector-contrib/blob/3bb7b25d1e14524d7afdc33d4d444ebabf9bf303/internal/aws/xray/testdata/README.md to verify the xray/testdata sampleapp + sampleserver produced traces as expected.
1 parent 7333a37 commit 718753e

File tree

10 files changed

+88
-69
lines changed

10 files changed

+88
-69
lines changed

internal/aws/k8s/go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8
33
go 1.23.0
44

55
require (
6-
github.com/aws/aws-sdk-go v1.55.7
6+
github.com/aws/aws-sdk-go-v2 v1.36.3
77
github.com/stretchr/testify v1.10.0
88
go.uber.org/goleak v1.3.0
99
go.uber.org/zap v1.27.0
@@ -13,6 +13,7 @@ require (
1313
)
1414

1515
require (
16+
github.com/aws/smithy-go v1.22.2 // indirect
1617
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1718
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
1819
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
@@ -26,7 +27,6 @@ require (
2627
github.com/google/go-cmp v0.6.0 // indirect
2728
github.com/google/gofuzz v1.2.0 // indirect
2829
github.com/google/uuid v1.6.0 // indirect
29-
github.com/jmespath/go-jmespath v0.4.0 // indirect
3030
github.com/josharian/intern v1.0.0 // indirect
3131
github.com/json-iterator/go v1.1.12 // indirect
3232
github.com/mailru/easyjson v0.7.7 // indirect
@@ -47,7 +47,6 @@ require (
4747
google.golang.org/protobuf v1.36.5 // indirect
4848
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
4949
gopkg.in/inf.v0 v0.9.1 // indirect
50-
gopkg.in/yaml.v2 v2.4.0 // indirect
5150
gopkg.in/yaml.v3 v3.0.1 // indirect
5251
k8s.io/klog/v2 v2.130.1 // indirect
5352
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect

internal/aws/k8s/go.sum

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

internal/aws/k8s/k8sclient/endpoint_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import (
99
"testing"
1010
"time"
1111

12-
"github.com/aws/aws-sdk-go/aws"
13-
"github.com/aws/aws-sdk-go/aws/awsutil"
12+
"github.com/aws/aws-sdk-go-v2/aws"
1413
"github.com/stretchr/testify/assert"
1514
"go.uber.org/zap"
1615
v1 "k8s.io/api/core/v1"
@@ -377,7 +376,7 @@ func TestEpClient_PodKeyToServiceNames(t *testing.T) {
377376
"namespace:default,podName:guestbook-qbdv8": {"guestbook"},
378377
}
379378
resultMap := client.PodKeyToServiceNames()
380-
log.Printf("PodKeyToServiceNames (len=%v): %v", len(resultMap), awsutil.Prettify(resultMap))
379+
log.Printf("PodKeyToServiceNames (len=%v): %v", len(resultMap), resultMap)
381380
assert.Equal(t, expectedMap, resultMap)
382381
}
383382

@@ -393,7 +392,7 @@ func TestEpClient_ServiceNameToPodNum(t *testing.T) {
393392
NewService("guestbook", "default"): 3,
394393
}
395394
resultMap := client.ServiceToPodNum()
396-
log.Printf("ServiceNameToPodNum (len=%v): %v", len(resultMap), awsutil.Prettify(resultMap))
395+
log.Printf("ServiceNameToPodNum (len=%v): %v", len(resultMap), resultMap)
397396
assert.Equal(t, expectedMap, resultMap)
398397
client.shutdown()
399398
time.Sleep(2 * time.Millisecond)

internal/aws/k8s/k8sclient/pod_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"log"
88
"testing"
99

10-
"github.com/aws/aws-sdk-go/aws/awsutil"
1110
"github.com/stretchr/testify/assert"
1211
"go.uber.org/zap"
1312
v1 "k8s.io/api/core/v1"
@@ -180,7 +179,7 @@ func TestPodClient_NamespaceToRunningPodNum(t *testing.T) {
180179
"default": 7,
181180
}
182181
resultMap := client.NamespaceToRunningPodNum()
183-
log.Printf("NamespaceToRunningPodNum (len=%v): %v", len(resultMap), awsutil.Prettify(resultMap))
182+
log.Printf("NamespaceToRunningPodNum (len=%v): %v", len(resultMap), resultMap)
184183
assert.Equal(t, expectedMap, resultMap)
185184
client.shutdown()
186185
assert.True(t, client.stopped)

internal/aws/xray/testdata/sampleapp/go.mod

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,28 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xr
33
go 1.23.0
44

55
require (
6-
github.com/aws/aws-sdk-go v1.55.7
7-
github.com/aws/aws-xray-sdk-go v1.8.5
6+
github.com/aws/aws-sdk-go-v2 v1.36.3
7+
github.com/aws/aws-sdk-go-v2/config v1.29.14
8+
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.18.12
9+
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.42.4
10+
github.com/aws/aws-xray-sdk-go/v2 v2.0.0
811
)
912

1013
require (
1114
github.com/andybalholm/brotli v1.1.0 // indirect
12-
github.com/jmespath/go-jmespath v0.4.0 // indirect
15+
github.com/aws/aws-sdk-go-v2/credentials v1.17.67 // indirect
16+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
17+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
18+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
19+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
20+
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.25.3 // indirect
21+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 // indirect
22+
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.10.15 // indirect
23+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 // indirect
24+
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 // indirect
25+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 // indirect
26+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19 // indirect
27+
github.com/aws/smithy-go v1.22.2 // indirect
1328
github.com/klauspost/compress v1.17.6 // indirect
1429
github.com/pkg/errors v0.9.1 // indirect
1530
github.com/stretchr/testify v1.10.0 // indirect
@@ -23,7 +38,6 @@ require (
2338
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect
2439
google.golang.org/grpc v1.70.0 // indirect
2540
google.golang.org/protobuf v1.36.5 // indirect
26-
gopkg.in/yaml.v2 v2.4.0 // indirect
2741
)
2842

2943
retract (

internal/aws/xray/testdata/sampleapp/go.sum

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

internal/aws/xray/testdata/sampleapp/sample.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ package main
66
import (
77
"context"
88

9-
"github.com/aws/aws-sdk-go/aws"
10-
"github.com/aws/aws-sdk-go/aws/session"
11-
"github.com/aws/aws-sdk-go/service/dynamodb"
12-
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
13-
"github.com/aws/aws-xray-sdk-go/xray"
9+
"github.com/aws/aws-sdk-go-v2/aws"
10+
"github.com/aws/aws-sdk-go-v2/config"
11+
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
12+
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
13+
"github.com/aws/aws-xray-sdk-go/v2/instrumentation/awsv2"
14+
"github.com/aws/aws-xray-sdk-go/v2/xray"
1415
)
1516

16-
var dynamo *dynamodb.DynamoDB
17-
1817
const (
1918
existingTableName = "xray_sample_table"
2019
nonExistingTableName = "does_not_exist"
@@ -26,20 +25,21 @@ type Record struct {
2625
}
2726

2827
func main() {
29-
dynamo = dynamodb.New(session.Must(session.NewSession(
30-
&aws.Config{
31-
Region: aws.String("us-west-2"),
32-
},
33-
)))
34-
xray.AWS(dynamo.Client)
28+
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion("us-west-2"))
29+
if err != nil {
30+
panic(err)
31+
}
32+
awsv2.AWSV2Instrumentor(&cfg.APIOptions)
33+
34+
client := dynamodb.NewFromConfig(cfg)
3535

3636
ctx, seg := xray.BeginSegment(context.Background(), "DDB")
3737
seg.User = "xraysegmentdump"
38-
err := ddbExpectedFailure(ctx)
38+
err = ddbExpectedFailure(ctx, client)
3939
seg.Close(err)
4040
}
4141

42-
func ddbExpectedFailure(ctx context.Context) error {
42+
func ddbExpectedFailure(ctx context.Context, client *dynamodb.Client) error {
4343
err := xray.Capture(ctx, "DDB.DescribeExistingTableAndPutToMissingTable", func(ctx1 context.Context) error {
4444
err := xray.AddAnnotation(ctx1, "DDB.DescribeExistingTableAndPutToMissingTable.Annotation", "anno")
4545
if err != nil {
@@ -50,7 +50,7 @@ func ddbExpectedFailure(ctx context.Context) error {
5050
return err
5151
}
5252

53-
_, err = dynamo.DescribeTableWithContext(ctx1, &dynamodb.DescribeTableInput{
53+
_, err = client.DescribeTable(ctx1, &dynamodb.DescribeTableInput{
5454
TableName: aws.String(existingTableName),
5555
})
5656
if err != nil {
@@ -62,12 +62,12 @@ func ddbExpectedFailure(ctx context.Context) error {
6262
URL: "https://example.com/first/link",
6363
}
6464

65-
item, err := dynamodbattribute.MarshalMap(&r)
65+
item, err := attributevalue.MarshalMap(&r)
6666
if err != nil {
6767
return err
6868
}
6969

70-
_, err = dynamo.PutItemWithContext(ctx1, &dynamodb.PutItemInput{
70+
_, err = client.PutItem(ctx1, &dynamodb.PutItemInput{
7171
TableName: aws.String(nonExistingTableName),
7272
Item: item,
7373
})

internal/aws/xray/testdata/sampleserver/go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xr
22

33
go 1.23.0
44

5-
require github.com/aws/aws-xray-sdk-go v1.8.5
5+
require github.com/aws/aws-xray-sdk-go/v2 v2.0.0
66

77
require (
88
github.com/andybalholm/brotli v1.1.0 // indirect
9-
github.com/aws/aws-sdk-go v1.47.10 // indirect
10-
github.com/jmespath/go-jmespath v0.4.0 // indirect
119
github.com/klauspost/compress v1.17.6 // indirect
1210
github.com/pkg/errors v0.9.1 // indirect
1311
github.com/stretchr/testify v1.10.0 // indirect

0 commit comments

Comments
 (0)