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(s3exporter): migrate to AWS Go SDK v2 #33698

Closed
wants to merge 3 commits into from
Closed
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
21 changes: 21 additions & 0 deletions exporter/awss3exporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ require (
)

require (
github.com/aws/aws-sdk-go-v2 v1.29.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.20 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.7 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.13 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.13 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.11 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.21.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.25.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.29.0 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
)

require (
github.com/aws/aws-sdk-go-v2/config v1.27.20
github.com/aws/aws-sdk-go-v2/service/s3 v1.56.0
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand Down
36 changes: 36 additions & 0 deletions exporter/awss3exporter/go.sum

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

51 changes: 19 additions & 32 deletions exporter/awss3exporter/s3_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
"strconv"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"

"github.com/aws/aws-sdk-go-v2/service/s3"

"go.opentelemetry.io/collector/config/configcompression"
)

Expand Down Expand Up @@ -58,30 +59,15 @@ func getS3Key(time time.Time, keyPrefix string, partition string, filePrefix str
return s3Key
}

func getSessionConfig(config *Config) *aws.Config {
sessionConfig := &aws.Config{
Region: aws.String(config.S3Uploader.Region),
S3ForcePathStyle: &config.S3Uploader.S3ForcePathStyle,
DisableSSL: &config.S3Uploader.DisableSSL,
}

endpoint := config.S3Uploader.Endpoint
if endpoint != "" {
sessionConfig.Endpoint = aws.String(endpoint)
}

return sessionConfig
}

func getSession(config *Config, sessionConfig *aws.Config) (*session.Session, error) {
sess, err := session.NewSession(sessionConfig)

if config.S3Uploader.RoleArn != "" {
credentials := stscreds.NewCredentials(sess, config.S3Uploader.RoleArn)
sess.Config.Credentials = credentials
func getConfig(s3Config *Config) (aws.Config, error) {
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion(s3Config.S3Uploader.Region),
)
if err != nil {
return aws.Config{}, err
}

return sess, err
return cfg, nil
}

func (s3writer *s3Writer) writeBuffer(_ context.Context, buf []byte, config *Config, metadata string, format string) error {
Expand Down Expand Up @@ -111,21 +97,22 @@ func (s3writer *s3Writer) writeBuffer(_ context.Context, buf []byte, config *Con
reader = bytes.NewReader(buf)
}

sessionConfig := getSessionConfig(config)
sess, err := getSession(config, sessionConfig)

s3Config, err := getConfig(config)
if err != nil {
return err
}

uploader := s3manager.NewUploader(sess)
s3Client := s3.NewFromConfig(s3Config)

_, err = uploader.Upload(&s3manager.UploadInput{
inputObj := &s3.PutObjectInput{
Bucket: aws.String(config.S3Uploader.S3Bucket),
Key: aws.String(key),
Body: reader,
ContentEncoding: &encoding,
})
}

_, err = s3Client.PutObject(context.TODO(), inputObj)

if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions exporter/awss3exporter/s3_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ func TestGetSessionConfigWithEndpoint(t *testing.T) {
Endpoint: endpoint,
},
}
sessionConfig := getSessionConfig(config)
assert.Equal(t, sessionConfig.Endpoint, aws.String(endpoint))
assert.Equal(t, sessionConfig.Region, aws.String(region))
cfg, _ := getConfig(config)
assert.Equal(t, cfg.EndpointResolver, aws.String(endpoint))
assert.Equal(t, cfg.Region, aws.String(region))
}

func TestGetSessionConfigNoEndpoint(t *testing.T) {
Expand All @@ -104,9 +104,9 @@ func TestGetSessionConfigNoEndpoint(t *testing.T) {
Region: region,
},
}
sessionConfig := getSessionConfig(config)
assert.Empty(t, sessionConfig.Endpoint)
assert.Equal(t, sessionConfig.Region, aws.String(region))
cfg, _ := getConfig(config)
assert.Empty(t, cfg.EndpointResolver)
assert.Equal(t, cfg.Region, aws.String(region))
}

func TestGetSessionConfigWithRoleArn(t *testing.T) {
Expand Down
28 changes: 14 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -336,26 +336,26 @@ require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.53.11 // indirect
github.com/aws/aws-sdk-go-v2 v1.27.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.29.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.16 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.16 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.3 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.20 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.20 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.7 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.7 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.7 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.9 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.13 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.13 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.11 // indirect
github.com/aws/aws-sdk-go-v2/service/kinesis v1.27.8 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.56.0 // indirect
github.com/aws/aws-sdk-go-v2/service/servicediscovery v1.29.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.9 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.28.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.21.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.25.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.29.0 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
Loading
Loading