Skip to content

Commit

Permalink
added debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
awitas committed Mar 21, 2023
1 parent 85944a4 commit 47bc1e4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion s3/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *storager) assignMetadata(options []storage.Option, object *s3.GetObject
func (s *storager) Get(ctx context.Context, location string, options ...storage.Option) (os.FileInfo, error) {
started := time.Now()
defer func() {
fmt.Printf("s3:Get %v %s\n", location, time.Since(started))
s.logF("s3:Get %v %s\n", location, time.Since(started))
}()
location = strings.Trim(location, "/")
info, err := s.get(ctx, location, options)
Expand Down
3 changes: 1 addition & 2 deletions s3/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package s3

import (
"context"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/s3"
Expand Down Expand Up @@ -77,7 +76,7 @@ func (s *storager) addFiles(parent string, result *[]os.FileInfo, objects []*s3.
func (s *storager) list(ctx context.Context, parent string, result *[]os.FileInfo, page *option.Page, matcher option.Match) error {
started := time.Now()
defer func() {
fmt.Printf("s3:List %v %s\n", parent, time.Since(started))
s.logF("s3:List %v %s\n", parent, time.Since(started))
}()

input := &s3.ListObjectsInput{
Expand Down
5 changes: 5 additions & 0 deletions s3/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import (
"github.com/viant/afs/storage"
"path"
"strings"
"time"
)

func (s *storager) Move(ctx context.Context, sourcePath, destBucket, destPath string, options ...storage.Option) error {
started := time.Now()
defer func() {
s.logF("s3:Move %v-> %v/%v %s\n", sourcePath, destBucket, destPath, time.Since(started))
}()
sourcePath = strings.Trim(sourcePath, "/")
destPath = strings.Trim(destPath, "/")
source, err := s.get(ctx, sourcePath, options)
Expand Down
2 changes: 1 addition & 1 deletion s3/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
func (s *storager) Open(ctx context.Context, location string, options ...storage.Option) (io.ReadCloser, error) {
started := time.Now()
defer func() {
fmt.Printf("s3:Open %v %s\n", location, time.Since(started))
s.logF("s3:Open %v %s\n", location, time.Since(started))
}()
var sess *session.Session
if s.config == nil {
Expand Down
14 changes: 12 additions & 2 deletions s3/storager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package s3

import (
"context"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
Expand All @@ -28,13 +27,21 @@ type storager struct {
bucket string
region string
config *aws.Config
logger *option.Logger
}

//Close closes storager
func (s *storager) Close() error {
return nil
}

func (s storager) logF(format string, args ...interface{}) {
if s.logger == nil {
return
}
s.logger.Logf(format, args...)
}

//FilterAuthOptions filters auth options
func (s storager) FilterAuthOptions(options []storage.Option) []storage.Option {
var authOptions = make([]storage.Option, 0)
Expand Down Expand Up @@ -113,12 +120,15 @@ func newStorager(ctx context.Context, baseURL string, options ...storage.Option)
result := &storager{
bucket: url.Host(baseURL),
}

var err error
result.config, err = getAwsConfig(options)
if err != nil {
return nil, errors.Wrapf(err, "failed to get aws config")
}
result.initS3Client()
result.logger = &option.Logger{}
option.Assign(options, &result.logger)
return result, nil
}

Expand All @@ -139,7 +149,7 @@ func (s *storager) initS3Client() {
func (s *storager) adjustRegionIfNeeded() {
started := time.Now()
defer func() {
fmt.Printf("s3:GetBucketLocation %v %s\n", s.bucket, time.Since(started))
s.logF("s3:GetBucketLocation %v %s\n", s.bucket, time.Since(started))
}()
output, err := s.S3.GetBucketLocation(&s3.GetBucketLocationInput{Bucket: &s.bucket})
if err != nil {
Expand Down

0 comments on commit 47bc1e4

Please sign in to comment.