From eac986b2a794456d97853b74f5f12d550d40782d Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Mon, 25 Oct 2021 14:06:36 +0200 Subject: [PATCH] More debugging --- .../grpc/services/gateway/storageprovider.go | 5 ++++- internal/http/services/owncloud/ocs/cache.go | 19 ++++++++++++++++--- .../handlers/apps/sharing/shares/shares.go | 7 ++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index 3ea0d881f4a..da46ffbd8e8 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -1945,7 +1945,10 @@ func (s *svc) getPath(ctx context.Context, ref *provider.Reference, keys ...stri if ref.ResourceId != nil { req := &provider.StatRequest{Ref: ref, ArbitraryMetadataKeys: keys} res, err := s.stat(ctx, req) - if (res != nil && res.Status.Code != rpc.Code_CODE_OK) || err != nil { + if err != nil { + return "", status.NewStatusFromErrType(ctx, "getPath ref="+ref.String(), err) + } + if res != nil && res.Status.Code != rpc.Code_CODE_OK { return "", res.Status } diff --git a/internal/http/services/owncloud/ocs/cache.go b/internal/http/services/owncloud/ocs/cache.go index 2db8e337020..ea587ae5fab 100644 --- a/internal/http/services/owncloud/ocs/cache.go +++ b/internal/http/services/owncloud/ocs/cache.go @@ -23,6 +23,7 @@ import ( "net/http" "net/http/httptest" + "github.com/cs3org/reva/pkg/appctx" ctxpkg "github.com/cs3org/reva/pkg/ctx" "google.golang.org/grpc/metadata" ) @@ -31,21 +32,33 @@ func (s *svc) cacheWarmup(w http.ResponseWriter, r *http.Request) { if s.warmupCacheTracker != nil { u := ctxpkg.ContextMustGetUser(r.Context()) tkn := ctxpkg.ContextMustGetToken(r.Context()) + log := appctx.GetLogger(r.Context()) ctx := context.Background() + ctx = appctx.WithLogger(ctx, log) ctx = ctxpkg.ContextSetUser(ctx, u) ctx = ctxpkg.ContextSetToken(ctx, tkn) ctx = metadata.AppendToOutgoingContext(ctx, ctxpkg.TokenHeader, tkn) - req := r.Clone(ctx) - req.Method = http.MethodGet + + req, _ := http.NewRequest("GET", "", nil) + req = req.WithContext(ctx) + req.URL = r.URL id := u.Id.OpaqueId if _, err := s.warmupCacheTracker.Get(id); err != nil { p := httptest.NewRecorder() _ = s.warmupCacheTracker.Set(id, true) + + log.Info().Msgf("cache warmup getting created shares for user %s", id) req.URL.Path = "/v1.php/apps/files_sharing/api/v1/shares" s.router.ServeHTTP(p, req) - req.URL.Path = "/v1.php/apps/files_sharing/api/v1/shares?shared_with_me=true" + + log.Info().Msgf("cache warmup getting received shares for user %s", id) + req.URL.Path = "/v1.php/apps/files_sharing/api/v1/shares" + q := req.URL.Query() + q.Set("shared_with_me", "true") + q.Set("state", "all") + req.URL.RawQuery = q.Encode() s.router.ServeHTTP(p, req) } } diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go index 47bc328efbe..84861cea783 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go @@ -100,7 +100,7 @@ func (h *Handler) Init(c *config.Config) { h.additionalInfoTemplate, _ = template.New("additionalInfo").Parse(c.AdditionalInfoAttribute) h.userIdentifierCache = ttlcache.NewCache() - _ = h.userIdentifierCache.SetTTL(time.Second * 60) + _ = h.userIdentifierCache.SetTTL(time.Second * 86400) if h.resourceInfoCacheTTL > 0 { cwm, err := getCacheWarmupManager(c) @@ -512,6 +512,7 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { // which pending state to list stateFilter := getStateFilter(r.FormValue("state")) + log := appctx.GetLogger(r.Context()) client, err := pool.GetGatewayServiceClient(h.gatewayAddr) if err != nil { response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error getting grpc gateway client", err) @@ -693,6 +694,7 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { log.Debug().Msgf("share: %+v", *data) } + log.Info().Msgf("listSharesWithMe cache %s %+v", p, h.resourceInfoCache) response.WriteOCSSuccess(w, r, shares) } @@ -707,6 +709,7 @@ func findMatch(shareJailInfos []*provider.ResourceInfo, id *provider.ResourceId) func (h *Handler) listSharesWithOthers(w http.ResponseWriter, r *http.Request) { shares := make([]*conversions.ShareData, 0) + log := appctx.GetLogger(r.Context()) filters := []*collaboration.Filter{} linkFilters := []*link.ListPublicSharesRequest_Filter{} @@ -764,6 +767,7 @@ func (h *Handler) listSharesWithOthers(w http.ResponseWriter, r *http.Request) { shares = append(shares, userShares...) } + log.Info().Msgf("listSharesWithOthers cache %+v", h.resourceInfoCache) response.WriteOCSSuccess(w, r, shares) } @@ -1022,6 +1026,7 @@ func (h *Handler) getResourceInfo(ctx context.Context, client gateway.GatewayAPI pinfo = infoIf.(*provider.ResourceInfo) status = &rpc.Status{Code: rpc.Code_CODE_OK} } else { + logger.Debug().Msgf("cache miss for resource %+v, statting", key) statReq := &provider.StatRequest{ Ref: ref, }