Skip to content

Commit

Permalink
More logging
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Nov 28, 2023
1 parent 98250c7 commit 896fd33
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion pkg/storage/utils/metadata/cs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/net"
"github.com/cs3org/reva/v2/pkg/appctx"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
Expand Down Expand Up @@ -134,14 +135,30 @@ func (cs3 *CS3) SimpleUpload(ctx context.Context, uploadpath string, content []b
Path: uploadpath,
Content: content,
})
appctx.GetLogger(ctx).Info().Msg("returning from cs3.SimpleUpload")
return err
}

// Upload uploads a file to the metadata storage
func (cs3 *CS3) Upload(ctx context.Context, req UploadRequest) (*UploadResponse, error) {
log := appctx.GetLogger(ctx).With().Logger()
ctx, span := tracer.Start(ctx, "Upload")
defer span.End()

quit := make(chan bool)
go func() {
for {
select {
case <-quit:
return
default:
log.Info().Msg("Upload tick")
time.Sleep(1 * time.Second)
}
}
}()
defer func() { quit <- true }()

client, err := cs3.providerClient()
if err != nil {
return nil, err
Expand Down Expand Up @@ -186,7 +203,9 @@ func (cs3 *CS3) Upload(ctx context.Context, req UploadRequest) (*UploadResponse,
ifuReq.Opaque = utils.AppendPlainToOpaque(ifuReq.Opaque, net.HeaderUploadLength, strconv.FormatInt(int64(len(req.Content)), 10))

fmt.Println("client.InitiateFileUpload")
log.Info().Str("path", req.Path).Msg("cs3.Upload InitiateFileUpload...")
res, err := client.InitiateFileUpload(ctx, ifuReq)
log.Info().Str("path", req.Path).Msg("cs3.Upload InitiateFileUpload done")
fmt.Printf("client.InitiateFileUpload err=%v\n", err)
if err != nil {
return nil, err
Expand Down Expand Up @@ -218,19 +237,32 @@ func (cs3 *CS3) Upload(ctx context.Context, req UploadRequest) (*UploadResponse,
md, _ := metadata.FromOutgoingContext(ctx)
httpReq.Header.Add(ctxpkg.TokenHeader, md.Get(ctxpkg.TokenHeader)[0])
fmt.Println("cs3.dataGatewayClient.Do")
log.Info().Str("path", req.Path).Msg("cs3.Upload dataGatewayClient.Do...")
resp, err := cs3.dataGatewayClient.Do(httpReq)
log.Info().Str("path", req.Path).Interface("err", err).Interface("resp.Status", resp.Status).Msg("cs3.Upload dataGatewayClient.Do done")
fmt.Printf("cs3.dataGatewayClient.Do err=%v\n", err)
if err != nil {
log.Info().Str("path", req.Path).Msg("cs3.Upload 0")
return nil, err
}
defer resp.Body.Close()
log.Info().Str("path", req.Path).Msg("cs3.Upload 1")
defer func() {
log.Info().Str("path", req.Path).Msg("cs3.Upload closing body")
resp.Body.Close()
log.Info().Str("path", req.Path).Msg("cs3.Upload closed body")
}()
log.Info().Str("path", req.Path).Msg("cs3.Upload 2")
if err := errtypes.NewErrtypeFromHTTPStatusCode(resp.StatusCode, httpReq.URL.Path); err != nil {
log.Info().Str("path", req.Path).Msg("cs3.Upload 2b")
return nil, err
}
log.Info().Str("path", req.Path).Msg("cs3.Upload 3")
etag := resp.Header.Get("Etag")
log.Info().Str("path", req.Path).Msg("cs3.Upload 4")
if ocEtag := resp.Header.Get("OC-ETag"); ocEtag != "" {
etag = ocEtag
}
log.Info().Str("path", req.Path).Err(err).Msg("cs3.Upload returning from cs3.Upload")
return &UploadResponse{
Etag: etag,
}, nil
Expand Down

0 comments on commit 896fd33

Please sign in to comment.