Skip to content

[internal/aws] Migrate k8s and xray/testdata to aws-sdk-go-v2 #39497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions internal/aws/k8s/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8
go 1.23.0

require (
github.com/aws/aws-sdk-go v1.55.7
github.com/aws/aws-sdk-go-v2 v1.36.3
github.com/stretchr/testify v1.10.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
Expand All @@ -13,6 +13,7 @@ require (
)

require (
github.com/aws/smithy-go v1.22.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
Expand All @@ -26,7 +27,6 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -47,7 +47,6 @@ require (
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
Expand Down
13 changes: 4 additions & 9 deletions internal/aws/k8s/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions internal/aws/k8s/k8sclient/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -377,7 +376,7 @@ func TestEpClient_PodKeyToServiceNames(t *testing.T) {
"namespace:default,podName:guestbook-qbdv8": {"guestbook"},
}
resultMap := client.PodKeyToServiceNames()
log.Printf("PodKeyToServiceNames (len=%v): %v", len(resultMap), awsutil.Prettify(resultMap))
log.Printf("PodKeyToServiceNames (len=%v): %v", len(resultMap), resultMap)
assert.Equal(t, expectedMap, resultMap)
}

Expand All @@ -393,7 +392,7 @@ func TestEpClient_ServiceNameToPodNum(t *testing.T) {
NewService("guestbook", "default"): 3,
}
resultMap := client.ServiceToPodNum()
log.Printf("ServiceNameToPodNum (len=%v): %v", len(resultMap), awsutil.Prettify(resultMap))
log.Printf("ServiceNameToPodNum (len=%v): %v", len(resultMap), resultMap)
assert.Equal(t, expectedMap, resultMap)
client.shutdown()
time.Sleep(2 * time.Millisecond)
Expand Down
3 changes: 1 addition & 2 deletions internal/aws/k8s/k8sclient/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log"
"testing"

"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -180,7 +179,7 @@ func TestPodClient_NamespaceToRunningPodNum(t *testing.T) {
"default": 7,
}
resultMap := client.NamespaceToRunningPodNum()
log.Printf("NamespaceToRunningPodNum (len=%v): %v", len(resultMap), awsutil.Prettify(resultMap))
log.Printf("NamespaceToRunningPodNum (len=%v): %v", len(resultMap), resultMap)
assert.Equal(t, expectedMap, resultMap)
client.shutdown()
assert.True(t, client.stopped)
Expand Down
22 changes: 18 additions & 4 deletions internal/aws/xray/testdata/sampleapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xr
go 1.23.0

require (
github.com/aws/aws-sdk-go v1.55.7
github.com/aws/aws-xray-sdk-go v1.8.5
github.com/aws/aws-sdk-go-v2 v1.36.3
github.com/aws/aws-sdk-go-v2/config v1.29.14
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.18.12
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.42.4
github.com/aws/aws-xray-sdk-go/v2 v2.0.0
)

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.67 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.25.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.10.15 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19 // indirect
github.com/aws/smithy-go v1.22.2 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.10.0 // indirect
Expand All @@ -23,7 +38,6 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect
google.golang.org/grpc v1.70.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

retract (
Expand Down
50 changes: 38 additions & 12 deletions internal/aws/xray/testdata/sampleapp/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 18 additions & 18 deletions internal/aws/xray/testdata/sampleapp/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ package main
import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
"github.com/aws/aws-xray-sdk-go/xray"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-xray-sdk-go/v2/instrumentation/awsv2"
"github.com/aws/aws-xray-sdk-go/v2/xray"
)

var dynamo *dynamodb.DynamoDB

const (
existingTableName = "xray_sample_table"
nonExistingTableName = "does_not_exist"
Expand All @@ -26,20 +25,21 @@ type Record struct {
}

func main() {
dynamo = dynamodb.New(session.Must(session.NewSession(
&aws.Config{
Region: aws.String("us-west-2"),
},
)))
xray.AWS(dynamo.Client)
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion("us-west-2"))
if err != nil {
panic(err)
}
awsv2.AWSV2Instrumentor(&cfg.APIOptions)

client := dynamodb.NewFromConfig(cfg)

ctx, seg := xray.BeginSegment(context.Background(), "DDB")
seg.User = "xraysegmentdump"
err := ddbExpectedFailure(ctx)
err = ddbExpectedFailure(ctx, client)
seg.Close(err)
}

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

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

item, err := dynamodbattribute.MarshalMap(&r)
item, err := attributevalue.MarshalMap(&r)
if err != nil {
return err
}

_, err = dynamo.PutItemWithContext(ctx1, &dynamodb.PutItemInput{
_, err = client.PutItem(ctx1, &dynamodb.PutItemInput{
TableName: aws.String(nonExistingTableName),
Item: item,
})
Expand Down
4 changes: 1 addition & 3 deletions internal/aws/xray/testdata/sampleserver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xr

go 1.23.0

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

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/aws/aws-sdk-go v1.47.10 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.10.0 // indirect
Expand Down
Loading
Loading