Skip to content

Commit e5b1215

Browse files
committed
debug: deploy overwhelming debug firepower (PRINTs everywhere)
Every single step will be logged
1 parent b1c1979 commit e5b1215

File tree

5 files changed

+106
-3
lines changed

5 files changed

+106
-3
lines changed

internal/grpc/services/gateway/storageprovider.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,13 @@ func (s *svc) Unlock(ctx context.Context, req *provider.UnlockRequest) (*provide
477477

478478
func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.StatResponse, error) {
479479
log := appctx.GetLogger(ctx)
480+
481+
log.Debug().
482+
Str("path", req.Ref.GetPath()).
483+
Str("storage_id", req.Ref.GetResourceId().GetStorageId()).
484+
Str("opaque_id", req.Ref.GetResourceId().GetOpaqueId()).
485+
Msg("gateway: Stat request")
486+
480487
providers, err := s.findProviders(ctx, req.Ref)
481488
if err != nil {
482489
return &provider.StatResponse{
@@ -485,8 +492,17 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St
485492
}
486493
providers = getUniqueProviders(providers)
487494

495+
log.Debug().
496+
Int("num_providers", len(providers)).
497+
Msg("gateway: found storage providers")
498+
488499
resPath := req.Ref.GetPath()
489500
if len(providers) == 1 && (utils.IsRelativeReference(req.Ref) || resPath == "" || strings.HasPrefix(resPath, providers[0].ProviderPath)) {
501+
log.Debug().
502+
Str("provider_address", providers[0].Address).
503+
Str("provider_path", providers[0].ProviderPath).
504+
Msg("gateway: routing Stat to storage provider")
505+
490506
c, err := s.getStorageProviderClient(ctx, providers[0])
491507
if err != nil {
492508
return &provider.StatResponse{
@@ -498,6 +514,14 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St
498514
log.Error().Err(err).Msg("Failed to stat " + resPath)
499515
return rsp, err
500516
}
517+
518+
log.Debug().
519+
Str("storage_id", rsp.Info.Id.StorageId).
520+
Str("space_id", rsp.Info.Id.SpaceId).
521+
Str("opaque_id", rsp.Info.Id.OpaqueId).
522+
Str("path", rsp.Info.Path).
523+
Msg("gateway: Stat response from storage provider")
524+
501525
return rsp, nil
502526
}
503527

internal/http/services/owncloud/ocdav/meta.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package ocdav
2121
import (
2222
"net/http"
2323

24+
"github.com/cs3org/reva/v3/pkg/appctx"
2425
"github.com/cs3org/reva/v3/pkg/rhttp/router"
2526
"github.com/cs3org/reva/v3/pkg/spaces"
2627
)
@@ -38,13 +39,21 @@ func (h *MetaHandler) init(c *Config) error {
3839
// Handler handles requests.
3940
func (h *MetaHandler) Handler(s *svc) http.Handler {
4041
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
42+
ctx := r.Context()
43+
log := appctx.GetLogger(ctx)
44+
4145
var id string
4246
id, r.URL.Path = router.ShiftPath(r.URL.Path)
4347
if id == "" {
4448
http.Error(w, "400 Bad Request", http.StatusBadRequest)
4549
return
4650
}
4751

52+
log.Debug().
53+
Str("raw_id", id).
54+
Str("url_path", r.URL.Path).
55+
Msg("meta: received resource ID from Web UI")
56+
4857
rid, ok := spaces.ParseResourceID(id)
4958
if !ok {
5059
// If this fails, client might be non-spaces
@@ -56,10 +65,21 @@ func (h *MetaHandler) Handler(s *svc) http.Handler {
5665
}
5766
}
5867

68+
log.Debug().
69+
Str("storage_id", rid.StorageId).
70+
Str("space_id", rid.SpaceId).
71+
Str("opaque_id", rid.OpaqueId).
72+
Msg("meta: parsed resource ID")
73+
5974
var head string
6075
head, r.URL.Path = router.ShiftPath(r.URL.Path)
6176
switch head {
6277
case "v":
78+
log.Debug().
79+
Str("storage_id", rid.StorageId).
80+
Str("space_id", rid.SpaceId).
81+
Str("opaque_id", rid.OpaqueId).
82+
Msg("meta: forwarding to versions handler")
6383
h.VersionsHandler.Handler(s, rid).ServeHTTP(w, r)
6484
default:
6585
w.WriteHeader(http.StatusNotFound)

internal/http/services/owncloud/ocdav/propfind.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,16 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
820820
if md.Id == nil {
821821
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("oc:fileid", ""))
822822
} else if spacesEnabled {
823+
sublog.Debug().
824+
Str("storage_id", md.Id.StorageId).
825+
Str("space_id", md.Id.SpaceId).
826+
Str("opaque_id", md.Id.OpaqueId).
827+
Str("path", md.Path).
828+
Msg("propfind: encoding fileid property")
823829
// If our client uses spaces, we try to use the spaces-encoded file id (storage$base32(spacePath)!inode)
824830
fileId, err := spaces.EncodeResourceInfo(md)
825831
if err != nil {
826-
log.Error().Err(err).Any("md", md).Msg("Failed to encode file id")
832+
sublog.Error().Err(err).Any("md", md).Msg("Failed to encode file id")
827833
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:fileid", spaces.EncodeResourceID(md.Id)))
828834
} else {
829835
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:fileid", fileId))
@@ -834,13 +840,24 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
834840

835841
case "id": // desktop client only
836842
if md.Id != nil {
843+
sublog.Debug().
844+
Str("storage_id", md.Id.StorageId).
845+
Str("space_id", md.Id.SpaceId).
846+
Str("opaque_id", md.Id.OpaqueId).
847+
Str("path", md.Path).
848+
Msg("propfind: encoding id property")
837849
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:id", spaces.EncodeResourceID(md.Id)))
838850
} else {
839851
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("oc:id", ""))
840852
}
841853
case "file-parent":
842854
if md.ParentId != nil {
843855
if spacesEnabled {
856+
sublog.Debug().
857+
Str("parent_storage_id", md.ParentId.StorageId).
858+
Str("parent_space_id", md.ParentId.SpaceId).
859+
Str("parent_opaque_id", md.ParentId.OpaqueId).
860+
Msg("propfind: encoding file-parent property")
844861
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:file-parent", spaces.EncodeResourceID(md.ParentId)))
845862
} else {
846863
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:file-parent", spaces.ResourceIdToString(md.ParentId)))

internal/http/services/owncloud/ocdav/versions.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ func (h *VersionsHandler) Handler(s *svc, rid *provider.ResourceId) http.Handler
5757
return
5858
}
5959

60+
log.Debug().
61+
Str("storage_id", rid.StorageId).
62+
Str("space_id", rid.SpaceId).
63+
Str("opaque_id", rid.OpaqueId).
64+
Msg("versions: handler entry - received rid")
65+
6066
// baseURI is encoded as part of the response payload in href field
6167
baseURI := path.Join(ctx.Value(ctxKeyBaseURI).(string), spaces.EncodeResourceID(rid))
6268
ctx = context.WithValue(ctx, ctxKeyBaseURI, baseURI)
@@ -180,6 +186,13 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,
180186
}
181187

182188
for i := range versions {
189+
sublog.Debug().
190+
Int("version_index", i).
191+
Str("version_key", versions[i].GetKey()).
192+
Str("rid_space_id", rid.SpaceId).
193+
Str("info_id_space_id", info.Id.SpaceId).
194+
Msg("versions: creating version ResourceInfo")
195+
183196
vi := &provider.ResourceInfo{
184197
// TODO(jfd) we cannot access version content, this will be a problem when trying to fetch version thumbnails
185198
// Opaque
@@ -201,6 +214,14 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,
201214
Size: versions[i].Size,
202215
Owner: info.Owner,
203216
}
217+
218+
sublog.Debug().
219+
Str("version_storage_id", vi.Id.StorageId).
220+
Str("version_space_id", vi.Id.SpaceId).
221+
Str("version_opaque_id", vi.Id.OpaqueId).
222+
Str("version_path", vi.Path).
223+
Msg("versions: created version ResourceInfo")
224+
204225
infos = append(infos, vi)
205226
}
206227

pkg/spaces/utils.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,37 @@ func EncodeResourceID(r *provider.ResourceId) string {
110110
// The resource ID is expected to be in the form of <storage_id>$base32(<path>)!<item_id>.
111111
func DecodeResourceID(raw string) (storageID, spacePath, itemID string, ok bool) {
112112
// The input is expected to be in the form of <storage_id>$base32(<path>)!<item_id>
113+
fmt.Fprintf(os.Stderr, "[DEBUG] DecodeResourceID: raw=%q\n", raw)
114+
113115
s := strings.SplitN(raw, "!", 2)
114116
if len(s) != 2 {
117+
fmt.Fprintf(os.Stderr, "[DEBUG] DecodeResourceID: FAILED split (expected '!') raw=%q\n", raw)
115118
return "", "", "", false
116119
}
117120
itemID = s[1]
118121
storageID, spacePath, ok = DecodeStorageSpaceID(s[0])
122+
123+
fmt.Fprintf(os.Stderr, "[DEBUG] DecodeResourceID: storageID=%q, spacePath=%q, itemID=%q, ok=%t\n",
124+
storageID, spacePath, itemID, ok)
125+
119126
return storageID, spacePath, itemID, ok
120127
}
121128

122129
// ParseResourceID converts the encoded resource id in a CS3API ResourceId.
123130
func ParseResourceID(raw string) (*provider.ResourceId, bool) {
131+
fmt.Fprintf(os.Stderr, "[DEBUG] ParseResourceID: raw=%q\n", raw)
132+
124133
storageID, path, itemID, ok := DecodeResourceID(raw)
125134
if !ok {
135+
fmt.Fprintf(os.Stderr, "[DEBUG] ParseResourceID: FAILED decode raw=%q\n", raw)
126136
return nil, false
127137
}
128138

129139
spaceID := PathToSpaceID(path)
130140

141+
fmt.Fprintf(os.Stderr, "[DEBUG] ParseResourceID: storageID=%q, spaceID=%q (from path=%q), itemID=%q\n",
142+
storageID, spaceID, path, itemID)
143+
131144
return &provider.ResourceId{
132145
StorageId: storageID,
133146
SpaceId: spaceID,
@@ -141,11 +154,19 @@ func ParseResourceID(raw string) (*provider.ResourceId, bool) {
141154
// If no path or space_id is set, an error will be returned
142155
func EncodeResourceInfo(info *provider.ResourceInfo) (spaceId string, err error) {
143156
if info.Id.SpaceId != "" {
144-
return fmt.Sprintf("%s$%s!%s", info.Id.StorageId, info.Id.SpaceId, info.Id.OpaqueId), nil
157+
result := fmt.Sprintf("%s$%s!%s", info.Id.StorageId, info.Id.SpaceId, info.Id.OpaqueId)
158+
fmt.Fprintf(os.Stderr, "[DEBUG] EncodeResourceInfo: using existing spaceID=%q -> %q\n",
159+
info.Id.SpaceId, result)
160+
return result, nil
145161
} else if info.Path != "" {
146162
encodedPath := PathToSpaceID(info.Path)
147-
return fmt.Sprintf("%s$%s!%s", info.Id.StorageId, encodedPath, info.Id.OpaqueId), nil
163+
result := fmt.Sprintf("%s$%s!%s", info.Id.StorageId, encodedPath, info.Id.OpaqueId)
164+
fmt.Fprintf(os.Stderr, "[DEBUG] EncodeResourceInfo: FALLBACK deriving spaceID from path=%q -> spaceID=%q -> %q\n",
165+
info.Path, encodedPath, result)
166+
return result, nil
148167
} else {
168+
fmt.Fprintf(os.Stderr, "[DEBUG] EncodeResourceInfo: FAILED no spaceID or path storageID=%q opaqueID=%q\n",
169+
info.Id.StorageId, info.Id.OpaqueId)
149170
return "", errors.New("resourceInfo must contain a spaceID or a path")
150171
}
151172
}

0 commit comments

Comments
 (0)