Skip to content

Commit

Permalink
fix jsoncs3 logging
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 Apr 4, 2024
1 parent 251ba8d commit 49f4c29
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions pkg/share/manager/jsoncs3/jsoncs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/google/uuid"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"go.opentelemetry.io/otel/codes"
"golang.org/x/sync/errgroup"
"google.golang.org/genproto/protobuf/field_mask"
Expand Down Expand Up @@ -411,6 +410,7 @@ func (m *Manager) get(ctx context.Context, ref *collaboration.ShareReference) (s
func (m *Manager) GetShare(ctx context.Context, ref *collaboration.ShareReference) (*collaboration.Share, error) {
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "GetShare")
defer span.End()
sublog := appctx.GetLogger(ctx).With().Str("id", ref.GetId().GetOpaqueId()).Str("key", ref.GetKey().String()).Str("driver", "jsoncs3").Str("handler", "GetShare").Logger()
if err := m.initialize(ctx); err != nil {
return nil, err
}
Expand All @@ -421,7 +421,7 @@ func (m *Manager) GetShare(ctx context.Context, ref *collaboration.ShareReferenc
}
if share.IsExpired(s) {
if err := m.removeShare(ctx, s); err != nil {
log.Error().Err(err).
sublog.Error().Err(err).
Msg("failed to unshare expired share")
}
if err := events.Publish(ctx, m.eventStream, events.ShareExpired{
Expand All @@ -432,7 +432,7 @@ func (m *Manager) GetShare(ctx context.Context, ref *collaboration.ShareReferenc
GranteeUserID: s.GetGrantee().GetUserId(),
GranteeGroupID: s.GetGrantee().GetGroupId(),
}); err != nil {
log.Error().Err(err).
sublog.Error().Err(err).
Msg("failed to publish share expired event")
}
}
Expand Down Expand Up @@ -583,6 +583,7 @@ func (m *Manager) ListShares(ctx context.Context, filters []*collaboration.Filte
func (m *Manager) listSharesByIDs(ctx context.Context, user *userv1beta1.User, filters []*collaboration.Filter) ([]*collaboration.Share, error) {
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "listSharesByIDs")
defer span.End()
sublog := appctx.GetLogger(ctx).With().Str("userid", user.GetId().GetOpaqueId()).Str("useridp", user.GetId().GetIdp()).Str("driver", "jsoncs3").Str("handler", "listSharesByIDs").Logger()

providerSpaces := make(map[string]map[string]struct{})
for _, f := range share.FilterFiltersByType(filters, collaboration.Filter_TYPE_RESOURCE_ID) {
Expand All @@ -604,19 +605,21 @@ func (m *Manager) listSharesByIDs(ctx context.Context, user *userv1beta1.User, f
}

for _, s := range shares.Shares {
resourceID := s.GetResourceId()
sublog = sublog.With().Str("storageid", resourceID.GetStorageId()).Str("spaceid", resourceID.GetSpaceId()).Str("opaqueid", resourceID.GetOpaqueId()).Logger()
if share.IsExpired(s) {
if err := m.removeShare(ctx, s); err != nil {
log.Error().Err(err).
sublog.Error().Err(err).
Msg("failed to unshare expired share")
}
if err := events.Publish(ctx, m.eventStream, events.ShareExpired{
ShareOwner: s.GetOwner(),
ItemID: s.GetResourceId(),
ItemID: resourceID,
ExpiredAt: time.Unix(int64(s.GetExpiration().GetSeconds()), int64(s.GetExpiration().GetNanos())),
GranteeUserID: s.GetGrantee().GetUserId(),
GranteeGroupID: s.GetGrantee().GetGroupId(),
}); err != nil {
log.Error().Err(err).
sublog.Error().Err(err).
Msg("failed to publish share expired event")
}
continue
Expand All @@ -626,17 +629,25 @@ func (m *Manager) listSharesByIDs(ctx context.Context, user *userv1beta1.User, f
}

if !(share.IsCreatedByUser(s, user) || share.IsGrantedToUser(s, user)) {
key := storagespace.FormatResourceID(*s.ResourceId)
key := storagespace.FormatResourceID(*resourceID)
if _, hit := statCache[key]; !hit {
req := &provider.StatRequest{
Ref: &provider.Reference{ResourceId: s.ResourceId},
Ref: &provider.Reference{ResourceId: resourceID},
}
res, err := m.gateway.Stat(ctx, req)
if err != nil ||
res.Status.Code != rpcv1beta1.Code_CODE_OK ||
!res.Info.PermissionSet.ListGrants {
if err != nil {
sublog.Error().Err(err).Msg("failed to make stat call")
continue
}
if res.Status.Code != rpcv1beta1.Code_CODE_OK {
sublog.Debug().Str("code", res.GetStatus().GetCode().String()).Msg(res.GetStatus().GetMessage())
continue
}
if !res.Info.PermissionSet.ListGrants {
sublog.Debug().Msg("user has no list grants permission")
continue
}
sublog.Debug().Msg("listing share for non participating user")
statCache[key] = struct{}{}
}
}
Expand All @@ -652,6 +663,7 @@ func (m *Manager) listSharesByIDs(ctx context.Context, user *userv1beta1.User, f
func (m *Manager) listCreatedShares(ctx context.Context, user *userv1beta1.User, filters []*collaboration.Filter) ([]*collaboration.Share, error) {
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "listCreatedShares")
defer span.End()
sublog := appctx.GetLogger(ctx).With().Str("userid", user.GetId().GetOpaqueId()).Str("useridp", user.GetId().GetIdp()).Str("driver", "jsoncs3").Str("handler", "listCreatedShares").Logger()

list, err := m.CreatedCache.List(ctx, user.Id.OpaqueId)
if err != nil {
Expand Down Expand Up @@ -694,7 +706,7 @@ func (m *Manager) listCreatedShares(ctx context.Context, user *userv1beta1.User,
// fetch all shares from space with one request
_, err := m.Cache.ListSpace(ctx, storageID, spaceID)
if err != nil {
log.Error().Err(err).
sublog.Error().Err(err).
Str("storageid", storageID).
Str("spaceid", spaceID).
Msg("failed to list shares in space")
Expand All @@ -707,7 +719,7 @@ func (m *Manager) listCreatedShares(ctx context.Context, user *userv1beta1.User,
}
if share.IsExpired(s) {
if err := m.removeShare(ctx, s); err != nil {
log.Error().Err(err).
sublog.Error().Err(err).
Msg("failed to unshare expired share")
}
if err := events.Publish(ctx, m.eventStream, events.ShareExpired{
Expand All @@ -717,7 +729,7 @@ func (m *Manager) listCreatedShares(ctx context.Context, user *userv1beta1.User,
GranteeUserID: s.GetGrantee().GetUserId(),
GranteeGroupID: s.GetGrantee().GetGroupId(),
}); err != nil {
log.Error().Err(err).
sublog.Error().Err(err).
Msg("failed to publish share expired event")
}
continue
Expand Down Expand Up @@ -762,6 +774,7 @@ func (m *Manager) listCreatedShares(ctx context.Context, user *userv1beta1.User,
func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaboration.Filter, forUser *userv1beta1.UserId) ([]*collaboration.ReceivedShare, error) {
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "ListReceivedShares")
defer span.End()
sublog := appctx.GetLogger(ctx).With().Str("driver", "jsoncs3").Str("handler", "ListReceivedShares").Logger()

if err := m.initialize(ctx); err != nil {
return nil, err
Expand Down Expand Up @@ -852,12 +865,11 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati
g.Go(func() error {
for w := range work {
storageID, spaceID, _ := shareid.Decode(w.ssid)
sublog = sublog.With().Str("storageid", storageID).Str("spaceid", spaceID).Logger()
// fetch all shares from space with one request
_, err := m.Cache.ListSpace(ctx, storageID, spaceID)
if err != nil {
log.Error().Err(err).
Str("storageid", storageID).
Str("spaceid", spaceID).
sublog.Error().Err(err).
Msg("failed to list shares in space")
continue
}
Expand All @@ -866,9 +878,10 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati
if err != nil || s == nil {
continue
}
sublog = sublog.With().Str("shareID", shareID).Logger()
if share.IsExpired(s) {
if err := m.removeShare(ctx, s); err != nil {
log.Error().Err(err).
sublog.Error().Err(err).
Msg("failed to unshare expired share")
}
if err := events.Publish(ctx, m.eventStream, events.ShareExpired{
Expand All @@ -878,7 +891,7 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati
GranteeUserID: s.GetGrantee().GetUserId(),
GranteeGroupID: s.GetGrantee().GetGroupId(),
}); err != nil {
log.Error().Err(err).
sublog.Error().Err(err).
Msg("failed to publish share expired event")
}
continue
Expand Down Expand Up @@ -959,6 +972,7 @@ func (m *Manager) GetReceivedShare(ctx context.Context, ref *collaboration.Share
func (m *Manager) getReceived(ctx context.Context, ref *collaboration.ShareReference) (*collaboration.ReceivedShare, error) {
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "getReceived")
defer span.End()
sublog := appctx.GetLogger(ctx).With().Str("id", ref.GetId().GetOpaqueId()).Str("key", ref.GetKey().String()).Str("driver", "jsoncs3").Str("handler", "getReceived").Logger()

s, err := m.get(ctx, ref)
if err != nil {
Expand All @@ -970,7 +984,7 @@ func (m *Manager) getReceived(ctx context.Context, ref *collaboration.ShareRefer
}
if share.IsExpired(s) {
if err := m.removeShare(ctx, s); err != nil {
log.Error().Err(err).
sublog.Error().Err(err).
Msg("failed to unshare expired share")
}
if err := events.Publish(ctx, m.eventStream, events.ShareExpired{
Expand All @@ -980,7 +994,7 @@ func (m *Manager) getReceived(ctx context.Context, ref *collaboration.ShareRefer
GranteeUserID: s.GetGrantee().GetUserId(),
GranteeGroupID: s.GetGrantee().GetGroupId(),
}); err != nil {
log.Error().Err(err).
sublog.Error().Err(err).
Msg("failed to publish share expired event")
}
}
Expand Down

0 comments on commit 49f4c29

Please sign in to comment.