-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Performance tuning #3932
Draft
butonic
wants to merge
18
commits into
cs3org:edge
Choose a base branch
from
fschade:micro-service-registry
base: edge
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[WIP] Performance tuning #3932
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
da195f5
enhancement: go micro service registry
fschade 2696626
enhancement: get rid of active service registration
fschade fa216b4
enhancement: add selector pattern to the client pool
fschade c600c92
enhancement: support for pool selector options
fschade 087da6c
use selector
butonic b81813d
add registry option
butonic 0289703
defer selector initialization in jsoncs3
butonic f3b3766
add error details
butonic f3e1936
update ge.mod
fschade e0dedc5
reenable ip addresses in selector again
butonic edbdd20
tidy
butonic a8346c8
enhancement: fascade use of selectors in clients
fschade 95ff17e
use selector in more places
butonic bc0b4ad
add statcache to sharesstorageprovider, use selectors
butonic 7872fbe
update otel semconv
butonic c3dd573
skip discovering services by address, just use address
butonic 9ecbfcb
trace jsoncs3 caches
butonic 9fa3d4f
trace jsoncs3 share manager, drop locks, add concurrent workers
butonic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
module _ // Fake go.mod auto-created by 'bingo' for go -moddir compatibility with non-Go projects. Commit this file, together with other .mod files. | ||
module _ // Fake go.mod auto-created by 'bingo' for go -moddir compatibility with non-Go projects. Commit this file, together with other .mod files. | ||
|
||
go 1.20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ const ( | |
|
||
func expandAndVerifyScope(ctx context.Context, req interface{}, tokenScope map[string]*authpb.Scope, user *userpb.User, gatewayAddr string, mgr token.Manager) error { | ||
log := appctx.GetLogger(ctx) | ||
client, err := pool.GetGatewayServiceClient(gatewayAddr) | ||
selector, err := pool.GatewaySelector(gatewayAddr) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -70,24 +70,28 @@ func expandAndVerifyScope(ctx context.Context, req interface{}, tokenScope map[s | |
for k := range tokenScope { | ||
switch { | ||
case strings.HasPrefix(k, "publicshare"): | ||
if err = resolvePublicShare(ctx, ref, tokenScope[k], client, mgr); err == nil { | ||
if err = resolvePublicShare(ctx, ref, tokenScope[k], selector, mgr); err == nil { | ||
return nil | ||
} | ||
|
||
case strings.HasPrefix(k, "share"): | ||
if err = resolveUserShare(ctx, ref, tokenScope[k], client, mgr); err == nil { | ||
if err = resolveUserShare(ctx, ref, tokenScope[k], selector, mgr); err == nil { | ||
return nil | ||
} | ||
|
||
case strings.HasPrefix(k, "lightweight"): | ||
if err = resolveLightweightScope(ctx, ref, tokenScope[k], user, client, mgr); err == nil { | ||
if err = resolveLightweightScope(ctx, ref, tokenScope[k], user, selector, mgr); err == nil { | ||
return nil | ||
} | ||
} | ||
log.Err(err).Msgf("error resolving reference %s under scope %+v", ref.String(), k) | ||
} | ||
|
||
} else if ref, ok := extractShareRef(req); ok { | ||
client, err := selector.Next() | ||
if err != nil { | ||
return err | ||
} | ||
// It's a share ref | ||
// The request might be coming from a share created for a lightweight account | ||
// after the token was minted. | ||
|
@@ -124,13 +128,18 @@ func expandAndVerifyScope(ctx context.Context, req interface{}, tokenScope map[s | |
return errtypes.PermissionDenied(fmt.Sprintf("access to resource %+v not allowed within the assigned scope", req)) | ||
} | ||
|
||
func resolveLightweightScope(ctx context.Context, ref *provider.Reference, scope *authpb.Scope, user *userpb.User, client gateway.GatewayAPIClient, mgr token.Manager) error { | ||
func resolveLightweightScope(ctx context.Context, ref *provider.Reference, scope *authpb.Scope, user *userpb.User, selector pool.Selectable[gateway.GatewayAPIClient], mgr token.Manager) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing ',' in parameter list (and 10 more errors) |
||
// Check if this ref is cached | ||
key := "lw:" + user.Id.OpaqueId + scopeDelimiter + getRefKey(ref) | ||
if _, err := scopeExpansionCache.Get(key); err == nil { | ||
return nil | ||
} | ||
|
||
client, err := selector.Next() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
shares, err := client.ListReceivedShares(ctx, &collaboration.ListReceivedSharesRequest{}) | ||
if err != nil || shares.Status.Code != rpc.Code_CODE_OK { | ||
return errtypes.InternalError("error listing received shares") | ||
|
@@ -143,7 +152,7 @@ func resolveLightweightScope(ctx context.Context, ref *provider.Reference, scope | |
if ref.ResourceId != nil && utils.ResourceIDEqual(share.Share.ResourceId, ref.ResourceId) { | ||
return nil | ||
} | ||
if ok, err := checkIfNestedResource(ctx, ref, share.Share.ResourceId, client, mgr); err == nil && ok { | ||
if ok, err := checkIfNestedResource(ctx, ref, share.Share.ResourceId, selector, mgr); err == nil && ok { | ||
_ = scopeExpansionCache.SetWithExpire(key, nil, scopeCacheExpiration*time.Second) | ||
return nil | ||
} | ||
|
@@ -152,20 +161,20 @@ func resolveLightweightScope(ctx context.Context, ref *provider.Reference, scope | |
return errtypes.PermissionDenied("request is not for a nested resource") | ||
} | ||
|
||
func resolvePublicShare(ctx context.Context, ref *provider.Reference, scope *authpb.Scope, client gateway.GatewayAPIClient, mgr token.Manager) error { | ||
func resolvePublicShare(ctx context.Context, ref *provider.Reference, scope *authpb.Scope, selector pool.Selectable[gateway.GatewayAPIClient], mgr token.Manager) error { | ||
var share link.PublicShare | ||
err := utils.UnmarshalJSONToProtoV1(scope.Resource.Value, &share) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := checkCacheForNestedResource(ctx, ref, share.ResourceId, client, mgr); err == nil { | ||
if err := checkCacheForNestedResource(ctx, ref, share.ResourceId, selector, mgr); err == nil { | ||
return nil | ||
} | ||
|
||
// Some services like wopi don't access the shared resource relative to the | ||
// share root but instead relative to the shared resources parent. | ||
return checkRelativeReference(ctx, ref, share.ResourceId, client) | ||
return checkRelativeReference(ctx, ref, share.ResourceId, selector) | ||
} | ||
|
||
// checkRelativeReference checks if the shared resource is being accessed via a relative reference | ||
|
@@ -178,7 +187,12 @@ func resolvePublicShare(ctx context.Context, ref *provider.Reference, scope *aut | |
// Reference{ResourceId: {StorageId: "abcd", SpaceId: "efgh"}, Path: "./New file.txt"} | ||
// then the request is considered relative and this function would return true. | ||
// Only references which are relative to the immediate parent of a resource are considered valid. | ||
func checkRelativeReference(ctx context.Context, requested *provider.Reference, sharedResourceID *provider.ResourceId, client gateway.GatewayAPIClient) error { | ||
func checkRelativeReference(ctx context.Context, requested *provider.Reference, sharedResourceID *provider.ResourceId, selector pool.Selectable[gateway.GatewayAPIClient]) error { | ||
client, err := selector.Next() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sRes, err := client.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{ResourceId: sharedResourceID}}) | ||
if err != nil { | ||
return err | ||
|
@@ -209,32 +223,36 @@ func checkRelativeReference(ctx context.Context, requested *provider.Reference, | |
return nil | ||
} | ||
|
||
func resolveUserShare(ctx context.Context, ref *provider.Reference, scope *authpb.Scope, client gateway.GatewayAPIClient, mgr token.Manager) error { | ||
func resolveUserShare(ctx context.Context, ref *provider.Reference, scope *authpb.Scope, selector pool.Selectable[gateway.GatewayAPIClient], mgr token.Manager) error { | ||
var share collaboration.Share | ||
err := utils.UnmarshalJSONToProtoV1(scope.Resource.Value, &share) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return checkCacheForNestedResource(ctx, ref, share.ResourceId, client, mgr) | ||
return checkCacheForNestedResource(ctx, ref, share.ResourceId, selector, mgr) | ||
} | ||
|
||
func checkCacheForNestedResource(ctx context.Context, ref *provider.Reference, resource *provider.ResourceId, client gateway.GatewayAPIClient, mgr token.Manager) error { | ||
func checkCacheForNestedResource(ctx context.Context, ref *provider.Reference, resource *provider.ResourceId, selector pool.Selectable[gateway.GatewayAPIClient], mgr token.Manager) error { | ||
// Check if this ref is cached | ||
key := storagespace.FormatResourceID(*resource) + scopeDelimiter + getRefKey(ref) | ||
if _, err := scopeExpansionCache.Get(key); err == nil { | ||
return nil | ||
} | ||
|
||
if ok, err := checkIfNestedResource(ctx, ref, resource, client, mgr); err == nil && ok { | ||
if ok, err := checkIfNestedResource(ctx, ref, resource, selector, mgr); err == nil && ok { | ||
_ = scopeExpansionCache.SetWithExpire(key, nil, scopeCacheExpiration*time.Second) | ||
return nil | ||
} | ||
|
||
return errtypes.PermissionDenied("request is not for a nested resource") | ||
} | ||
|
||
func checkIfNestedResource(ctx context.Context, ref *provider.Reference, parent *provider.ResourceId, client gateway.GatewayAPIClient, mgr token.Manager) (bool, error) { | ||
func checkIfNestedResource(ctx context.Context, ref *provider.Reference, parent *provider.ResourceId, selector pool.Selectable[gateway.GatewayAPIClient], mgr token.Manager) (bool, error) { | ||
client, err := selector.Next() | ||
if err != nil { | ||
return false, err | ||
} | ||
// Since the resource ID is obtained from the scope, the current token | ||
// has access to it. | ||
statResponse, err := client.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{ResourceId: parent}}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing ',' in parameter list