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: presign url using blob storage #82

Merged
merged 11 commits into from
Jan 25, 2024
3 changes: 2 additions & 1 deletion internal/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,8 @@ func (s *Server) newBlockFile(block *api.BlockMetadata) (*api.BlockFile, error)
compression := storage_utils.GetCompressionType(key)
fileUrl, err := s.blobStorage.PreSign(context.Background(), key)
if err != nil {
return nil, err
s.logger.Error("block file s3 presign error", zap.String("key", key), zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a logging interceptor taking care of the logs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

return nil, status.Errorf(codes.Internal, "internal block file url generation error: %+v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all errors are by default mapped to internal by the error interceptor. no need to repeat it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}

return &api.BlockFile{
Expand Down
5 changes: 1 addition & 4 deletions internal/storage/blobstorage/gcs/blob_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import (
"time"

"cloud.google.com/go/storage"
"github.com/gogo/status"
"github.com/uber-go/tally/v4"
"go.uber.org/fx"
"go.uber.org/zap"
"golang.org/x/xerrors"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/proto"

"github.com/coinbase/chainstorage/internal/config"
Expand Down Expand Up @@ -239,8 +237,7 @@ func (s *blobStorageImpl) PreSign(ctx context.Context, objectKey string) (string
Expires: time.Now().Add(s.presignedUrlExpiration),
})
if err != nil {
s.logger.Error("block file gcs presign error", zap.String("key", objectKey), zap.Error(err))
return "", status.Errorf(codes.Internal, "internal block file url generation error: %+v", err)
return "", xerrors.Errorf("failed to generate presigned url: %w", err)
}
return fileUrl, nil
}
Expand Down
5 changes: 1 addition & 4 deletions internal/storage/blobstorage/s3/blob_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ import (
"github.com/aws/aws-sdk-go/aws/request"
awss3 "github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/gogo/status"
"github.com/uber-go/tally/v4"
"go.uber.org/fx"
"go.uber.org/zap"
"golang.org/x/xerrors"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/proto"

"github.com/coinbase/chainstorage/internal/config"
Expand Down Expand Up @@ -228,8 +226,7 @@ func (s *blobStorageImpl) PreSign(ctx context.Context, objectKey string) (string
})
fileUrl, err := getObjectReq.Presign(s.config.AWS.PresignedUrlExpiration)
if err != nil {
s.logger.Error("block file s3 presign error", zap.Reflect("key", objectKey), zap.Error(err))
return "", status.Errorf(codes.Internal, "internal block file url generation error: %+v", err)
return "", xerrors.Errorf("failed to generate presigned url: %w", err)
}
return fileUrl, nil
}
Expand Down