-
Notifications
You must be signed in to change notification settings - Fork 231
feat: limit concurrent processing of thumbnail requests #9199
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Enhancement: Limit concurrent thumbnail requests | ||
|
|
||
| The number of concurrent requests to the thumbnail service can be limited now | ||
| to have more control over the consumed system resources. | ||
|
|
||
| https://github.com/owncloud/ocis/pull/9199 |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package middleware | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/go-chi/chi/v5/middleware" | ||
| ) | ||
|
|
||
| // Throttle limits the number of concurrent requests. | ||
| func Throttle(limit int) func(http.Handler) http.Handler { | ||
| if limit > 0 { | ||
| return middleware.Throttle(limit) | ||
| } | ||
| return func(next http.Handler) http.Handler { | ||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| next.ServeHTTP(w, r) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import ( | |
| gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" | ||
| userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" | ||
| rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" | ||
| revactx "github.com/cs3org/reva/v2/pkg/ctx" | ||
| "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" | ||
| "github.com/cs3org/reva/v2/pkg/storage/utils/templates" | ||
| "github.com/go-chi/chi/v5" | ||
|
|
@@ -37,10 +38,6 @@ func init() { | |
| chi.RegisterMethod("REPORT") | ||
| } | ||
|
|
||
| const ( | ||
| TokenHeader = "X-Access-Token" | ||
| ) | ||
|
|
||
| var ( | ||
| codesEnum = map[int]string{ | ||
| http.StatusBadRequest: "Sabre\\DAV\\Exception\\BadRequest", | ||
|
|
@@ -52,8 +49,8 @@ var ( | |
|
|
||
| // Service defines the extension handlers. | ||
| type Service interface { | ||
| ServeHTTP(http.ResponseWriter, *http.Request) | ||
| Thumbnail(http.ResponseWriter, *http.Request) | ||
| ServeHTTP(w http.ResponseWriter, r *http.Request) | ||
| Thumbnail(w http.ResponseWriter, r *http.Request) | ||
| } | ||
|
|
||
| // NewService returns a service implementation for Service. | ||
|
|
@@ -235,7 +232,7 @@ func (g Webdav) SpacesThumbnail(w http.ResponseWriter, r *http.Request) { | |
| renderError(w, r, errBadRequest(err.Error())) | ||
| return | ||
| } | ||
| t := r.Header.Get(TokenHeader) | ||
| t := r.Header.Get(revactx.TokenHeader) | ||
|
|
||
| fullPath := filepath.Join(tr.Identifier, tr.Filepath) | ||
| rsp, err := g.thumbnailsClient.GetThumbnail(r.Context(), &thumbnailssvc.GetThumbnailRequest{ | ||
|
|
@@ -284,7 +281,7 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) { | |
| return | ||
| } | ||
|
|
||
| t := r.Header.Get(TokenHeader) | ||
| t := r.Header.Get(revactx.TokenHeader) | ||
|
|
||
| gatewayClient, err := g.gatewaySelector.Next() | ||
| if err != nil { | ||
|
|
@@ -312,7 +309,7 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) { | |
| user = userRes.GetUser() | ||
| } else { | ||
| // look up user from URL via GetUserByClaim | ||
| ctx := grpcmetadata.AppendToOutgoingContext(r.Context(), TokenHeader, t) | ||
| ctx := grpcmetadata.AppendToOutgoingContext(r.Context(), revactx.TokenHeader, t) | ||
| userRes, err := gatewayClient.GetUserByClaim(ctx, &userv1beta1.GetUserByClaimRequest{ | ||
| Claim: "username", | ||
| Value: tr.Identifier, | ||
|
|
@@ -475,11 +472,11 @@ func (g Webdav) sendThumbnailResponse(rsp *thumbnailssvc.GetThumbnailResponse, w | |
|
|
||
| if dlRsp.StatusCode != http.StatusOK { | ||
| logger.Debug(). | ||
| Str("transfer_token", rsp.TransferToken). | ||
| Str("data_endpoint", rsp.DataEndpoint). | ||
| Str("transfer_token", rsp.GetTransferToken()). | ||
| Str("data_endpoint", rsp.GetDataEndpoint()). | ||
| Str("response_status", dlRsp.Status). | ||
| Msg("could not download thumbnail") | ||
| renderError(w, r, errInternalError("could not download thumbnail")) | ||
| renderError(w, r, newErrResponse(dlRsp.StatusCode, "could not download thumbnail")) | ||
|
Member
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. sabredav does not have a dedicated TooManyRequests exception. So we don't need to try and invent something here or in the reva webdav error handling. We could omit a body ... and we should send a retry after header ... in a different PR. |
||
| return | ||
| } | ||
|
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.