Skip to content
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

feat: add support for aws-sdk-go-v2 #244

Merged
merged 13 commits into from
Aug 30, 2024
14 changes: 11 additions & 3 deletions _integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ require (
github.com/IBM/sarama v1.43.3
github.com/Shopify/sarama v1.38.1
github.com/aws/aws-sdk-go v1.55.5
github.com/aws/aws-sdk-go-v2 v1.30.4
github.com/aws/aws-sdk-go-v2/config v1.27.30
github.com/aws/aws-sdk-go-v2/credentials v1.17.29
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.6
github.com/datadog/orchestrion v0.7.4
github.com/dave/jennifer v1.7.0
github.com/docker/go-connections v0.5.0
Expand Down Expand Up @@ -72,22 +76,26 @@ require (
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/armon/go-radix v1.0.1-0.20221118154546-54df44f2176c // indirect
github.com/aws/aws-sdk-go-v2 v1.30.4 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.30 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.29 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.12 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.14 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.16 // indirect
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.38.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ec2 v1.176.0 // indirect
github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.18 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.17 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.18 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.16 // indirect
github.com/aws/aws-sdk-go-v2/service/kinesis v1.29.5 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.60.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sfn v1.30.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sns v1.31.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sqs v1.34.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.22.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.30.5 // indirect
Expand Down
16 changes: 16 additions & 0 deletions _integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,32 @@ github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.16 h1:mimdLQkIX1zr8GIPY1ZtALdBQGx
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.16/go.mod h1:YHk6owoSwrIsok+cAH9PENCOGoH5PU2EllX4vLtSrsY=
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.38.5 h1:t7ZIhyAbD9zDH7rzEuUIagnPz6dJRB8HesgygHUbpsc=
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.38.5/go.mod h1:Jnkkf+olxCcacqhQIjY8BlG4JL2/ZsPLsiBh6xnNsu4=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.6 h1:LKZuRTlh8RszjuWcUwEDvCGwjx5olHPp6ZOepyZV5p8=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.6/go.mod h1:s2fYaueBuCnwv1XQn6T8TfShxJWusv5tWPMcL+GY6+g=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.176.0 h1:fWhkSvaQqa5eWiRwBw10FUnk1YatAQ9We4GdGxKiCtg=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.176.0/go.mod h1:ISODge3zgdwOEa4Ou6WM9PKbxJWJ15DYKnr2bfmCAIA=
github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.5 h1:wL8V4pdudr0mHbZ/tj9YacfRak5klKz9omV0uXBt5Sk=
github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.5/go.mod h1:AudiowtxywCESLsT3fvGcAEEcN4l7nusiW2nZMaCo+g=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4 h1:KypMCbLPPHEmf9DgMGw51jMj77VfGPAN2Kv4cfhlfgI=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4/go.mod h1:Vz1JQXliGcQktFTN/LN6uGppAIRoLBR2bMvIMP0gOjc=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.18 h1:GckUnpm4EJOAio1c8o25a+b3lVfwVzC9gnSBqiiNmZM=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.18/go.mod h1:Br6+bxfG33Dk3ynmkhsW2Z/t9D4+lRqdLDNCKi85w0U=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.17 h1:HDJGz1jlV7RokVgTPfx1UHBHANC0N5Uk++xgyYgz5E0=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.17/go.mod h1:5szDu6TWdRDytfDxUQVv2OYfpTQMKApVFyqpm+TcA98=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.18 h1:tJ5RnkHCiSH0jyd6gROjlJtNwov0eGYNz8s8nFcR0jQ=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.18/go.mod h1:++NHzT+nAF7ZPrHPsA+ENvsXkOO8wEu+C6RXltAG4/c=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.16 h1:jg16PhLPUiHIj8zYIW6bqzeQSuHVEiWnGA0Brz5Xv2I=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.16/go.mod h1:Uyk1zE1VVdsHSU7096h/rwnXDzOzYQVl+FNPhPw7ShY=
github.com/aws/aws-sdk-go-v2/service/kinesis v1.29.5 h1:iirGMva2IXw4kcqsvuF+uc8ARweuVqoQJjzRZGaiV1E=
github.com/aws/aws-sdk-go-v2/service/kinesis v1.29.5/go.mod h1:pKTvEQz1PcNd+gKArVyeHpVM63AWnFqYyg07WAQQANQ=
github.com/aws/aws-sdk-go-v2/service/s3 v1.60.1 h1:mx2ucgtv+MWzJesJY9Ig/8AFHgoE5FwLXwUVgW/FGdI=
github.com/aws/aws-sdk-go-v2/service/s3 v1.60.1/go.mod h1:BSPI0EfnYUuNHPS0uqIo5VrRwzie+Fp+YhQOUs16sKI=
github.com/aws/aws-sdk-go-v2/service/sfn v1.30.2 h1:FO9wG1mXg1tb8iizrN5+t5NR2Tu5Mo+KJ7u2TlhWxPI=
github.com/aws/aws-sdk-go-v2/service/sfn v1.30.2/go.mod h1:jIKXvGI0iFk5QXBW8FntPO/tqdmfC3OS0Z38twH9a08=
github.com/aws/aws-sdk-go-v2/service/sns v1.31.5 h1:q8R1hxwOHE4e6TInafToa8AHTLQpJrxWXYk7GINJoyw=
github.com/aws/aws-sdk-go-v2/service/sns v1.31.5/go.mod h1:wDacBq+NshhM8KhdysbM4wRFxVyghyj7AAI+l8+o9f0=
github.com/aws/aws-sdk-go-v2/service/sqs v1.34.5 h1:HYyVDOC2/PIg+3oBX1q0wtDU5kONki6lrgIG0afrBkY=
github.com/aws/aws-sdk-go-v2/service/sqs v1.34.5/go.mod h1:7idt3XszF6sE9WPS1GqZRiDJOxw4oPtlRBXodWnCGjU=
github.com/aws/aws-sdk-go-v2/service/sso v1.22.5 h1:zCsFCKvbj25i7p1u94imVoO447I/sFv8qq+lGJhRN0c=
github.com/aws/aws-sdk-go-v2/service/sso v1.22.5/go.mod h1:ZeDX1SnKsVlejeuz41GiajjZpRSWR7/42q/EyA/QEiM=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.5 h1:SKvPgvdvmiTWoi0GAJ7AsJfOz3ngVkD/ERbs5pUnHNI=
Expand Down
43 changes: 6 additions & 37 deletions _integration-tests/tests/aws.v1/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ package awsv1
import (
"context"
"fmt"
"orchestrion/integration/utils"
"orchestrion/integration/validator/trace"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"

"orchestrion/integration/utils"
"orchestrion/integration/validator/trace"
)

type TestCase struct {
Expand All @@ -31,42 +30,12 @@ type TestCase struct {
}

func (tc *TestCase) Setup(t *testing.T) {
port := "8000/tcp"
req := testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "amazon/dynamodb-local:latest",
ExposedPorts: []string{port},
WaitingFor: wait.ForHTTP("").WithStatusCodeMatcher(func(int) bool { return true }),
Name: "dynamodb-local",
WorkingDir: "/home/dynamodblocal",
Cmd: []string{
"-jar", "DynamoDBLocal.jar",
"-inMemory",
"-disableTelemetry",
},
LogConsumerCfg: &testcontainers.LogConsumerConfig{
Consumers: []testcontainers.LogConsumer{utils.TestLogConsumer(t)},
},
},
Started: true,
Logger: testcontainers.TestLogger(t),
}

ctx := context.Background()
var err error
tc.server, err = testcontainers.GenericContainer(ctx, req)
if err != nil {
t.Skipf("Failed to start dynamodb local container: %v\n", err)
}

mappedPort, err := tc.server.MappedPort(ctx, nat.Port(port))
require.NoError(t, err)
hostIp, err := tc.server.Host(ctx)
require.NoError(t, err)
server, host, port := utils.StartDynamoDBTestContainer(t)
tc.server = server

tc.cfg = &aws.Config{
Credentials: credentials.NewStaticCredentials("NOTANACCESSKEY", "NOTASECRETKEY", ""),
Endpoint: aws.String(fmt.Sprintf("http://%s:%s", hostIp, mappedPort.Port())),
Endpoint: aws.String(fmt.Sprintf("http://%s:%s", host, port)),
Region: aws.String("test-region-1337"),
}
}
Expand Down
87 changes: 87 additions & 0 deletions _integration-tests/tests/aws.v2/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023-present Datadog, Inc.

//go:build integration

package awsv2

import (
"context"
"fmt"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"

"orchestrion/integration/utils"
"orchestrion/integration/validator/trace"
)

type base struct {
server testcontainers.Container
cfg aws.Config
host string
port string
}

func (b *base) setup(t *testing.T) {
b.server, b.host, b.port = utils.StartDynamoDBTestContainer(t)
}

func (b *base) teardown(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
require.NoError(t, b.server.Terminate(ctx))
}

func (b *base) run(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
ddb := dynamodb.NewFromConfig(b.cfg)
_, err := ddb.ListTables(ctx, nil)
require.NoError(t, err)
}

func (b *base) expectedSpans() trace.Spans {
return trace.Spans{
{
Tags: map[string]any{
"name": "DynamoDB.request",
"service": "aws.DynamoDB",
"resource": "DynamoDB.ListTables",
"type": "http",
},
Meta: map[string]any{
"aws.operation": "ListTables",
"aws.region": "test-region-1337",
"aws_service": "DynamoDB",
"http.method": "POST",
"component": "aws/aws-sdk-go-v2/aws",
"span.kind": "client",
},
Children: []*trace.Span{
{
Tags: map[string]any{
"name": "http.request",
"service": "aws.DynamoDB",
"resource": "POST /",
"type": "http",
},
Meta: map[string]any{
"http.method": "POST",
"http.status_code": "200",
"http.url": fmt.Sprintf("http://localhost:%s/", b.port),
"network.destination.name": "localhost",
"component": "net/http",
"span.kind": "client",
},
},
},
},
}
}
49 changes: 49 additions & 0 deletions _integration-tests/tests/aws.v2/load_default_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023-present Datadog, Inc.

//go:build integration

package awsv2

import (
"context"
"fmt"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/stretchr/testify/require"

"orchestrion/integration/validator/trace"
)

type TestCaseLoadDefaultConfig struct {
base
}

func (tc *TestCaseLoadDefaultConfig) Setup(t *testing.T) {
tc.setup(t)

cfg, err := config.LoadDefaultConfig(context.Background(),
config.WithRegion("test-region-1337"),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("NOTANACCESSKEY", "NOTASECRETKEY", "")),
)
require.NoError(t, err)
cfg.BaseEndpoint = aws.String(fmt.Sprintf("http://%s:%s", tc.host, tc.port))
tc.cfg = cfg
}

func (tc *TestCaseLoadDefaultConfig) Run(t *testing.T) {
tc.base.run(t)
}

func (tc *TestCaseLoadDefaultConfig) Teardown(t *testing.T) {
tc.base.teardown(t)
}

func (tc *TestCaseLoadDefaultConfig) ExpectedTraces() trace.Spans {
return tc.base.expectedSpans()
}
43 changes: 43 additions & 0 deletions _integration-tests/tests/aws.v2/new_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023-present Datadog, Inc.

//go:build integration

package awsv2

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/credentials"
"orchestrion/integration/validator/trace"
)

type TestCaseNewConfig struct {
base
}

func (tc *TestCaseNewConfig) Setup(t *testing.T) {
tc.setup(t)

cfg := aws.NewConfig()
cfg.Region = "test-region-1337"
cfg.Credentials = credentials.NewStaticCredentialsProvider("NOTANACCESSKEY", "NOTASECRETKEY", "")
cfg.BaseEndpoint = aws.String(fmt.Sprintf("http://%s:%s", tc.host, tc.port))
tc.cfg = *cfg
}

func (tc *TestCaseNewConfig) Run(t *testing.T) {
tc.base.run(t)
}

func (tc *TestCaseNewConfig) Teardown(t *testing.T) {
tc.base.teardown(t)
}

func (tc *TestCaseNewConfig) ExpectedTraces() trace.Spans {
return tc.base.expectedSpans()
}
44 changes: 44 additions & 0 deletions _integration-tests/tests/aws.v2/struct_literal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023-present Datadog, Inc.

//go:build integration

package awsv2

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/credentials"

"orchestrion/integration/validator/trace"
)

type TestCaseStructLiteral struct {
base
}

func (tc *TestCaseStructLiteral) Setup(t *testing.T) {
tc.setup(t)

tc.cfg = aws.Config{
Region: "test-region-1337",
Credentials: credentials.NewStaticCredentialsProvider("NOTANACCESSKEY", "NOTASECRETKEY", ""),
BaseEndpoint: aws.String(fmt.Sprintf("http://%s:%s", tc.host, tc.port)),
}
}

func (tc *TestCaseStructLiteral) Run(t *testing.T) {
tc.base.run(t)
}

func (tc *TestCaseStructLiteral) Teardown(t *testing.T) {
tc.base.teardown(t)
}

func (tc *TestCaseStructLiteral) ExpectedTraces() trace.Spans {
return tc.base.expectedSpans()
}
Loading
Loading