Skip to content

Commit

Permalink
Pass an initialized logger to the upload store/session
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Dec 4, 2024
1 parent 0662c5e commit 3c6c7a0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func New(o *options.Options, aspects aspects.Aspects, log *zerolog.Logger) (stor
spaceTypeIndex: spaceTypeIndex,
log: log,
}
fs.sessionStore = upload.NewSessionStore(fs, aspects, o.Root, o.AsyncFileUploads, o.Tokens)
fs.sessionStore = upload.NewSessionStore(fs, aspects, o.Root, o.AsyncFileUploads, o.Tokens, log)
if err = fs.trashbin.Setup(fs); err != nil {
return nil, err
}
Expand Down
8 changes: 1 addition & 7 deletions pkg/storage/utils/decomposedfs/upload/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/v2/pkg/appctx"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/logger"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/v2/pkg/utils"
)
Expand All @@ -49,12 +48,7 @@ type OcisSession struct {

// Context returns a context with the user, logger and lockid used when initiating the upload session
func (s *OcisSession) Context(ctx context.Context) context.Context { // restore logger from file info
log, _ := logger.FromConfig(&logger.LogConf{
Output: "stderr", // TODO use config from decomposedfs
Mode: "json", // TODO use config from decomposedfs
Level: s.info.Storage["LogLevel"],
})
sub := log.With().Int("pid", os.Getpid()).Logger()
sub := s.store.log.With().Int("pid", os.Getpid()).Logger()
ctx = appctx.WithLogger(ctx, &sub)
ctx = ctxpkg.ContextSetLockID(ctx, s.lockID())
ctx = ctxpkg.ContextSetUser(ctx, s.executantUser())
Expand Down
5 changes: 4 additions & 1 deletion pkg/storage/utils/decomposedfs/upload/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/rogpeppe/go-internal/lockedfile"
"github.com/rs/zerolog"
tusd "github.com/tus/tusd/v2/pkg/handler"
)

Expand All @@ -65,10 +66,11 @@ type OcisStore struct {
async bool
tknopts options.TokenOptions
disableVersioning bool
log *zerolog.Logger
}

// NewSessionStore returns a new OcisStore
func NewSessionStore(fs storage.FS, aspects aspects.Aspects, root string, async bool, tknopts options.TokenOptions) *OcisStore {
func NewSessionStore(fs storage.FS, aspects aspects.Aspects, root string, async bool, tknopts options.TokenOptions, log *zerolog.Logger) *OcisStore {
return &OcisStore{
fs: fs,
lu: aspects.Lookup,
Expand All @@ -79,6 +81,7 @@ func NewSessionStore(fs storage.FS, aspects aspects.Aspects, root string, async
tknopts: tknopts,
disableVersioning: aspects.DisableVersioning,
um: aspects.UserMapper,
log: log,
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/utils/decomposedfs/upload/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import (

// TestInitNewNode calls greetings.initNewNode
func TestInitNewNode(t *testing.T) {

log := &zerolog.Logger{}
root := t.TempDir()

lookup := lookup.New(metadata.NewMessagePackBackend(root, cache.Config{}), &options.Options{Root: root}, &timemanager.Manager{})
tp := tree.New(lookup, nil, &options.Options{}, nil, &zerolog.Logger{})
tp := tree.New(lookup, nil, &options.Options{}, nil, log)

aspects := aspects.Aspects{
Lookup: lookup,
Tree: tp,
}
store := NewSessionStore(nil, aspects, root, false, options.TokenOptions{})
store := NewSessionStore(nil, aspects, root, false, options.TokenOptions{}, log)

rootNode := node.New("e48c4e7a-beac-4b82-b991-a5cff7b8c39c", "e48c4e7a-beac-4b82-b991-a5cff7b8c39c", "", "", 0, "", providerv1beta1.ResourceType_RESOURCE_TYPE_CONTAINER, &userv1beta1.UserId{}, lookup)
rootNode.Exists = true
Expand Down

0 comments on commit 3c6c7a0

Please sign in to comment.