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

Commit

Permalink
log download object routine
Browse files Browse the repository at this point in the history
Signed-off-by: hatfieldbrian <[email protected]>
  • Loading branch information
hatfieldbrian committed Dec 11, 2022
1 parent c72791a commit 1cd1758
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
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
26 changes: 23 additions & 3 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,13 @@ 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 @@ -544,11 +552,23 @@ func (s *s3ObjectStore) DownloadObject(key string,
}

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, %w",
bucket, key, err)
}

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

s.log.Info("s3 download object decode",
"bucket", bucket,
"key", key,
"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

0 comments on commit 1cd1758

Please sign in to comment.