Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

log download object routine #86

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (s *ProtectedVolumeReplicationGroupListInstance) getVrgContentsFromS3(prefi
// download VRGs
prefixInS3 := fmt.Sprintf("%s/%s/", namespace, vrgName)

s.log.Info("downloadVRGs", "namespace", namespace, "vrg", vrgName, "prefix", prefixInS3)
vrgs, err := DownloadVRGs(objectStore, prefixInS3)
if err != nil {
return vrgsAll, fmt.Errorf("error during DownloadVRGs on '%s': %w", prefixInS3, err)
Expand Down
37 changes: 30 additions & 7 deletions controllers/s3utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
ramen "github.com/ramendr/ramen/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -172,6 +173,7 @@ func (s3ObjectStoreGetter) ObjectStore(ctx context.Context,
s3Bucket: s3StoreProfile.S3Bucket,
callerTag: callerTag,
name: s3ProfileName,
log: log,
}

return s3Conn, s3StoreProfile, nil
Expand Down Expand Up @@ -210,6 +212,7 @@ type s3ObjectStore struct {
s3Bucket string
callerTag string
name string
log logr.Logger
}

// CreateBucket creates the given bucket; does not return an error if the bucket
Expand Down Expand Up @@ -462,8 +465,14 @@ func DownloadTypedObjects(s ObjectStorer, keyPrefix string, objectsPointer inter
objects := reflect.MakeSlice(reflect.SliceOf(objectType),
len(keys), len(keys))

log := ctrl.Log
log.Info("s3 download typed objects", "keys", keys, "objectsValue", objectsValue, "objectType", objectType)

for i := range keys {
objectReceiver := objects.Index(i).Addr().Interface()

log.Info("s3 download typed object", "i", i, "key", keys[i], "objectReceiver", objectReceiver)

if err := s.DownloadObject(keys[i], objectReceiver); err != nil {
return fmt.Errorf("unable to DownloadObject of key %s, %w",
keys[i], err)
Expand Down Expand Up @@ -535,20 +544,34 @@ func (s *s3ObjectStore) DownloadObject(key string,
ctx, cancel := context.WithDeadline(context.TODO(), time.Now().Add(s3Timeout))
defer cancel()

if _, err := s.downloader.DownloadWithContext(ctx, writerAt, &s3.GetObjectInput{
byteCount, err := s.downloader.DownloadWithContext(ctx, writerAt, &s3.GetObjectInput{
Bucket: &bucket,
Key: &key,
}); err != nil {
return fmt.Errorf("failed to download data of %s:%s, %w",
bucket, key, err)
})
if err != nil {
return fmt.Errorf("failed to download data of %s:%s byte count: %d, %w",
bucket, key, byteCount, err)
}

gzReader, err := gzip.NewReader(bytes.NewReader(writerAt.Bytes()))
if err != nil && !errorswrapper.Is(err, io.EOF) {
return fmt.Errorf("failed to unzip data of %s:%s, %w",
bucket, key, err)
if err != nil {
if !errorswrapper.Is(err, io.EOF) {
return fmt.Errorf("failed to unzip data of %s:%s byte count: %d, %w",
bucket, key, byteCount, err)
}

s.log.Info("s3 download object end-of-file", "error", err)
}

s.log.Info("s3 download object decode",
"bucket", bucket,
"key", key,
"byte count", byteCount,
"downloadContent", downloadContent,
"writerAt", writerAt,
"gzReader", gzReader,
)

if err := json.NewDecoder(gzReader).Decode(downloadContent); err != nil {
return fmt.Errorf("failed to decode json decoder of %s:%s, %w",
bucket, key, err)
Expand Down