Skip to content

Commit

Permalink
add logging to s3 client and pass context to calls (#390)
Browse files Browse the repository at this point in the history
Co-authored-by: Vladimir Palevich <scaiper@nebius.com>
  • Loading branch information
scaiper and scaiper authored Oct 31, 2023
1 parent d8bf86b commit 112df34
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 177 deletions.
6 changes: 3 additions & 3 deletions yandex/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"strings"
"time"

"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/google/uuid"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -70,7 +70,7 @@ type Config struct {
userAgent string
sdk *ycsdk.SDK
sharedCredentials *SharedCredentials
defaultS3Client *s3.S3
defaultS3Session *session.Session
}

// this function return context with added client trace id
Expand Down Expand Up @@ -183,7 +183,7 @@ func (c *Config) initializeDefaultS3Client() (err error) {
return fmt.Errorf("both storage access key and storage secret key should be specified or not specified")
}

c.defaultS3Client, err = newS3Client(c.StorageEndpoint, accessKey, secretKey)
c.defaultS3Session, err = newS3Session(c.StorageEndpoint, accessKey, secretKey)

return err
}
Expand Down
8 changes: 4 additions & 4 deletions yandex/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func TestConfigInitDefaultS3ClientFromSharedCredentials(t *testing.T) {
if err != nil {
t.Fatalf("failed to initAndValidate config: \"%v\"", err.Error())
}
require.NotNilf(t, config.defaultS3Client, "expected defaultS3Client to be initialized")
credentials, err := config.defaultS3Client.Config.Credentials.Get()
require.NotNilf(t, config.defaultS3Session, "expected defaultS3Session to be initialized")
credentials, err := config.defaultS3Session.Config.Credentials.Get()
if err != nil {
return
}
Expand All @@ -181,8 +181,8 @@ func TestConfigInitDefaultS3Client_PreferAccessKeysFromConfig(t *testing.T) {
if err != nil {
t.Fatalf("failed to initAndValidate config: \"%v\"", err.Error())
}
require.NotNilf(t, config.defaultS3Client, "expected defaultS3Client to be initialized")
credentials, err := config.defaultS3Client.Config.Credentials.Get()
require.NotNilf(t, config.defaultS3Session, "expected defaultS3Session to be initialized")
credentials, err := config.defaultS3Session.Config.Credentials.Get()
if err != nil {
return
}
Expand Down
Loading

0 comments on commit 112df34

Please sign in to comment.