Skip to content

Commit

Permalink
more trace spans
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Dec 2, 2024
1 parent 6529d03 commit 6d1fb3d
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 13 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/more-traces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: we added more trace spans in decomposedfs

https://github.com/cs3org/reva/pull/4978
2 changes: 2 additions & 0 deletions pkg/storage/fs/posix/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ func (t *Tree) ResolveSpaceIDIndexEntry(spaceid, entry string) (string, string,

// InitNewNode initializes a new node
func (t *Tree) InitNewNode(ctx context.Context, n *node.Node, fsize uint64) (metadata.UnlockFunc, error) {
_, span := tracer.Start(ctx, "InitNewNode")
defer span.End()
// create folder structure (if needed)
if err := os.MkdirAll(filepath.Dir(n.InternalPath()), 0700); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (fs *Decomposedfs) Postprocessing(ch <-chan events.Event) {
keepUpload = true
metrics.UploadSessionsAborted.Inc()
case events.PPOutcomeContinue:
if err := session.Finalize(); err != nil {
if err := session.Finalize(ctx); err != nil {
sublog.Error().Err(err).Msg("could not finalize upload")
failed = true
revertNodeMetadata = false
Expand Down
14 changes: 14 additions & 0 deletions pkg/storage/utils/decomposedfs/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (

// DenyGrant denies access to a resource.
func (fs *Decomposedfs) DenyGrant(ctx context.Context, ref *provider.Reference, grantee *provider.Grantee) error {
_, span := tracer.Start(ctx, "DenyGrant")
defer span.End()
log := appctx.GetLogger(ctx)

log.Debug().Interface("ref", ref).Interface("grantee", grantee).Msg("DenyGrant()")
Expand Down Expand Up @@ -74,6 +76,8 @@ func (fs *Decomposedfs) DenyGrant(ctx context.Context, ref *provider.Reference,

// AddGrant adds a grant to a resource
func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) (err error) {
_, span := tracer.Start(ctx, "AddGrant")
defer span.End()
log := appctx.GetLogger(ctx)
log.Debug().Interface("ref", ref).Interface("grant", g).Msg("AddGrant()")
grantNode, unlockFunc, grant, err := fs.loadGrant(ctx, ref, g)
Expand Down Expand Up @@ -119,6 +123,8 @@ func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g

// ListGrants lists the grants on the specified resource
func (fs *Decomposedfs) ListGrants(ctx context.Context, ref *provider.Reference) (grants []*provider.Grant, err error) {
_, span := tracer.Start(ctx, "ListGrants")
defer span.End()
var grantNode *node.Node
if grantNode, err = fs.lu.NodeFromResource(ctx, ref); err != nil {
return
Expand Down Expand Up @@ -174,6 +180,8 @@ func (fs *Decomposedfs) ListGrants(ctx context.Context, ref *provider.Reference)

// RemoveGrant removes a grant from resource
func (fs *Decomposedfs) RemoveGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) (err error) {
_, span := tracer.Start(ctx, "RemoveGrant")
defer span.End()
grantNode, unlockFunc, grant, err := fs.loadGrant(ctx, ref, g)
if err != nil {
return err
Expand Down Expand Up @@ -235,6 +243,8 @@ func isShareGrant(ctx context.Context) bool {
// UpdateGrant updates a grant on a resource
// TODO remove AddGrant or UpdateGrant grant from CS3 api, redundant? tracked in https://github.com/cs3org/cs3apis/issues/92
func (fs *Decomposedfs) UpdateGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error {
_, span := tracer.Start(ctx, "UpdateGrant")
defer span.End()
log := appctx.GetLogger(ctx)
log.Debug().Interface("ref", ref).Interface("grant", g).Msg("UpdateGrant()")

Expand Down Expand Up @@ -272,6 +282,8 @@ func (fs *Decomposedfs) UpdateGrant(ctx context.Context, ref *provider.Reference

// checks if the given grant exists and returns it. Nil grant means it doesn't exist
func (fs *Decomposedfs) loadGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) (*node.Node, metadata.UnlockFunc, *provider.Grant, error) {
_, span := tracer.Start(ctx, "loadGrant")
defer span.End()
n, err := fs.lu.NodeFromResource(ctx, ref)
if err != nil {
return nil, nil, nil, err
Expand Down Expand Up @@ -308,6 +320,8 @@ func (fs *Decomposedfs) loadGrant(ctx context.Context, ref *provider.Reference,
}

func (fs *Decomposedfs) storeGrant(ctx context.Context, n *node.Node, g *provider.Grant) error {
_, span := tracer.Start(ctx, "storeGrant")
defer span.End()
// if is a grant to a space root, the receiver needs the space type to update the indexes
spaceType, ok := storageprovider.SpaceTypeFromContext(ctx)
if !ok {
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/utils/decomposedfs/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (

// SetArbitraryMetadata sets the metadata on a resource
func (fs *Decomposedfs) SetArbitraryMetadata(ctx context.Context, ref *provider.Reference, md *provider.ArbitraryMetadata) (err error) {
_, span := tracer.Start(ctx, "SetArbitraryMetadata")
defer span.End()
n, err := fs.lu.NodeFromResource(ctx, ref)
if err != nil {
return errors.Wrap(err, "Decomposedfs: error resolving ref")
Expand Down Expand Up @@ -131,6 +133,8 @@ func (fs *Decomposedfs) SetArbitraryMetadata(ctx context.Context, ref *provider.

// UnsetArbitraryMetadata unsets the metadata on the given resource
func (fs *Decomposedfs) UnsetArbitraryMetadata(ctx context.Context, ref *provider.Reference, keys []string) (err error) {
_, span := tracer.Start(ctx, "UnsetArbitraryMetadata")
defer span.End()
n, err := fs.lu.NodeFromResource(ctx, ref)
if err != nil {
return errors.Wrap(err, "Decomposedfs: error resolving ref")
Expand Down
26 changes: 24 additions & 2 deletions pkg/storage/utils/decomposedfs/node/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (

// SetLock sets a lock on the node
func (n *Node) SetLock(ctx context.Context, lock *provider.Lock) error {
ctx, span := tracer.Start(ctx, "SetLock")
defer span.End()
lockFilePath := n.LockFilePath()

// ensure parent path exists
Expand Down Expand Up @@ -89,22 +91,31 @@ func (n *Node) SetLock(ctx context.Context, lock *provider.Lock) error {

// ReadLock reads the lock id for a node
func (n Node) ReadLock(ctx context.Context, skipFileLock bool) (*provider.Lock, error) {
ctx, span := tracer.Start(ctx, "ReadLock")
defer span.End()

// ensure parent path exists
if err := os.MkdirAll(filepath.Dir(n.InternalPath()), 0700); err != nil {
_, subspan := tracer.Start(ctx, "os.MkdirAll")
err := os.MkdirAll(filepath.Dir(n.InternalPath()), 0700)
subspan.End()
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: error creating parent folder for lock")
}

// the caller of ReadLock already may hold a file lock
if !skipFileLock {
_, subspan := tracer.Start(ctx, "filelocks.AcquireReadLock")
fileLock, err := filelocks.AcquireReadLock(n.InternalPath())
subspan.End()

if err != nil {
return nil, err
}

defer func() {
_, subspan := tracer.Start(ctx, "filelocks.ReleaseLock")
rerr := filelocks.ReleaseLock(fileLock)
subspan.End()

// if err is non nil we do not overwrite that
if err == nil {
Expand All @@ -113,7 +124,10 @@ func (n Node) ReadLock(ctx context.Context, skipFileLock bool) (*provider.Lock,
}()
}

_, subspan = tracer.Start(ctx, "os.Open")
f, err := os.Open(n.LockFilePath())
subspan.End()

if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return nil, errtypes.NotFound("no lock found")
Expand All @@ -130,7 +144,11 @@ func (n Node) ReadLock(ctx context.Context, skipFileLock bool) (*provider.Lock,

// lock already expired
if lock.Expiration != nil && time.Now().After(time.Unix(int64(lock.Expiration.Seconds), int64(lock.Expiration.Nanos))) {
if err = os.Remove(f.Name()); err != nil {

_, subspan = tracer.Start(ctx, "os.Remove")
err = os.Remove(f.Name())
subspan.End()
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: could not remove expired lock file")
}
// we successfully deleted the expired lock
Expand All @@ -142,6 +160,8 @@ func (n Node) ReadLock(ctx context.Context, skipFileLock bool) (*provider.Lock,

// RefreshLock refreshes the node's lock
func (n *Node) RefreshLock(ctx context.Context, lock *provider.Lock, existingLockID string) error {
ctx, span := tracer.Start(ctx, "RefreshLock")
defer span.End()

// ensure parent path exists
if err := os.MkdirAll(filepath.Dir(n.InternalPath()), 0700); err != nil {
Expand Down Expand Up @@ -204,6 +224,8 @@ func (n *Node) RefreshLock(ctx context.Context, lock *provider.Lock, existingLoc

// Unlock unlocks the node
func (n *Node) Unlock(ctx context.Context, lock *provider.Lock) error {
ctx, span := tracer.Start(ctx, "Unlock")
defer span.End()

// ensure parent path exists
if err := os.MkdirAll(filepath.Dir(n.InternalPath()), 0700); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ func (n *Node) MarshalJSON() ([]byte, error) {

// Type returns the node's resource type
func (n *Node) Type(ctx context.Context) provider.ResourceType {
_, span := tracer.Start(ctx, "Type")
defer span.End()
if n.nodeType != nil {
return *n.nodeType
}
Expand Down Expand Up @@ -446,6 +448,8 @@ func (n *Node) Child(ctx context.Context, name string) (*Node, error) {

// ParentWithReader returns the parent node
func (n *Node) ParentWithReader(ctx context.Context, r io.Reader) (*Node, error) {
_, span := tracer.Start(ctx, "ParentWithReader")
defer span.End()
if n.ParentID == "" {
return nil, fmt.Errorf("decomposedfs: root has no parent")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/storage/utils/decomposedfs/node/xattrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func (md Attributes) Time(key string) (time.Time, error) {

// SetXattrs sets multiple extended attributes on the write-through cache/node
func (n *Node) SetXattrsWithContext(ctx context.Context, attribs map[string][]byte, acquireLock bool) (err error) {
_, span := tracer.Start(ctx, "SetXattrsWithContext")
defer span.End()
if n.xattrsCache != nil {
for k, v := range attribs {
n.xattrsCache[k] = v
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func (p Permissions) AssemblePermissions(ctx context.Context, n *node.Node) (*pr

// AssembleTrashPermissions is used to assemble file permissions
func (p Permissions) AssembleTrashPermissions(ctx context.Context, n *node.Node) (*provider.ResourcePermissions, error) {
_, span := tracer.Start(ctx, "AssembleTrashPermissions")
defer span.End()
return p.item.AssembleTrashPermissions(ctx, n)
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/storage/utils/decomposedfs/recycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func (tb *DecomposedfsTrashbin) Setup(fs storage.FS) error {
// ListRecycle returns the list of available recycle items
// ref -> the space (= resourceid), key -> deleted node id, relativePath = relative to key
func (tb *DecomposedfsTrashbin) ListRecycle(ctx context.Context, ref *provider.Reference, key, relativePath string) ([]*provider.RecycleItem, error) {

_, span := tracer.Start(ctx, "ListRecycle")
defer span.End()
if ref == nil || ref.ResourceId == nil || ref.ResourceId.OpaqueId == "" {
return nil, errtypes.BadRequest("spaceid required")
}
Expand Down Expand Up @@ -346,6 +347,8 @@ func (tb *DecomposedfsTrashbin) listTrashRoot(ctx context.Context, spaceID strin

// RestoreRecycleItem restores the specified item
func (tb *DecomposedfsTrashbin) RestoreRecycleItem(ctx context.Context, ref *provider.Reference, key, relativePath string, restoreRef *provider.Reference) error {
_, span := tracer.Start(ctx, "RestoreRecycleItem")
defer span.End()
if ref == nil {
return errtypes.BadRequest("missing reference, needs a space id")
}
Expand Down Expand Up @@ -399,6 +402,8 @@ func (tb *DecomposedfsTrashbin) RestoreRecycleItem(ctx context.Context, ref *pro

// PurgeRecycleItem purges the specified item, all its children and all their revisions
func (tb *DecomposedfsTrashbin) PurgeRecycleItem(ctx context.Context, ref *provider.Reference, key, relativePath string) error {
_, span := tracer.Start(ctx, "PurgeRecycleItem")
defer span.End()
if ref == nil {
return errtypes.BadRequest("missing reference, needs a space id")
}
Expand Down Expand Up @@ -429,6 +434,8 @@ func (tb *DecomposedfsTrashbin) PurgeRecycleItem(ctx context.Context, ref *provi

// EmptyRecycle empties the trash
func (tb *DecomposedfsTrashbin) EmptyRecycle(ctx context.Context, ref *provider.Reference) error {
_, span := tracer.Start(ctx, "EmptyRecycle")
defer span.End()
if ref == nil || ref.ResourceId == nil || ref.ResourceId.OpaqueId == "" {
return errtypes.BadRequest("spaceid must be set")
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/storage/utils/decomposedfs/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import (

// ListRevisions lists the revisions of the given resource
func (fs *Decomposedfs) ListRevisions(ctx context.Context, ref *provider.Reference) (revisions []*provider.FileVersion, err error) {
_, span := tracer.Start(ctx, "ListRevisions")
defer span.End()
var n *node.Node
if n, err = fs.lu.NodeFromResource(ctx, ref); err != nil {
return
Expand Down Expand Up @@ -115,6 +117,8 @@ func (fs *Decomposedfs) ListRevisions(ctx context.Context, ref *provider.Referen
// DownloadRevision returns a reader for the specified revision
// FIXME the CS3 api should explicitly allow initiating revision and trash download, a related issue is https://github.com/cs3org/reva/issues/1813
func (fs *Decomposedfs) DownloadRevision(ctx context.Context, ref *provider.Reference, revisionKey string, openReaderFunc func(md *provider.ResourceInfo) bool) (*provider.ResourceInfo, io.ReadCloser, error) {
_, span := tracer.Start(ctx, "DownloadRevision")
defer span.End()
log := appctx.GetLogger(ctx)

// verify revision key format
Expand Down Expand Up @@ -186,6 +190,8 @@ func (fs *Decomposedfs) DownloadRevision(ctx context.Context, ref *provider.Refe

// RestoreRevision restores the specified revision of the resource
func (fs *Decomposedfs) RestoreRevision(ctx context.Context, ref *provider.Reference, revisionKey string) (returnErr error) {
_, span := tracer.Start(ctx, "RestoreRevision")
defer span.End()
log := appctx.GetLogger(ctx)

// verify revision key format
Expand Down Expand Up @@ -330,6 +336,8 @@ func (fs *Decomposedfs) RestoreRevision(ctx context.Context, ref *provider.Refer

// DeleteRevision deletes the specified revision of the resource
func (fs *Decomposedfs) DeleteRevision(ctx context.Context, ref *provider.Reference, revisionKey string) error {
_, span := tracer.Start(ctx, "DeleteRevision")
defer span.End()
n, err := fs.getRevisionNode(ctx, ref, revisionKey, func(rp *provider.ResourcePermissions) bool {
return rp.RestoreFileVersion
})
Expand All @@ -345,6 +353,8 @@ func (fs *Decomposedfs) DeleteRevision(ctx context.Context, ref *provider.Refere
}

func (fs *Decomposedfs) getRevisionNode(ctx context.Context, ref *provider.Reference, revisionKey string, hasPermission func(*provider.ResourcePermissions) bool) (*node.Node, error) {
_, span := tracer.Start(ctx, "getRevisionNode")
defer span.End()
log := appctx.GetLogger(ctx)

// verify revision key format
Expand Down
Loading

0 comments on commit 6d1fb3d

Please sign in to comment.