diff options
author | John Cai <jcai@gitlab.com> | 2022-04-22 00:32:59 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2022-04-27 22:13:27 +0300 |
commit | 3d1eb883c6e8b95aa7cbed1ba06217b5a454a7f5 (patch) | |
tree | b743c90a1a7e144c077df712d2b49147ee3ec27a | |
parent | 64f59cae54e67f385b88496b7ccdb29565f90704 (diff) |
limithandler: Return structured error on queue timejc-return-structured-error-limits
-rw-r--r-- | internal/middleware/limithandler/concurrency_limiter.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/middleware/limithandler/concurrency_limiter.go b/internal/middleware/limithandler/concurrency_limiter.go index f6587554a..ff26ffb63 100644 --- a/internal/middleware/limithandler/concurrency_limiter.go +++ b/internal/middleware/limithandler/concurrency_limiter.go @@ -11,6 +11,8 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/v14/internal/helper" "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag" + "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" + "google.golang.org/protobuf/types/known/durationpb" ) // ErrMaxQueueTime indicates a request has reached the maximum time allowed to wait in the @@ -164,6 +166,18 @@ func (c *ConcurrencyLimiter) Limit(ctx context.Context, lockKey string, f Limite if err != nil { if errors.Is(err, ErrMaxQueueTime) { c.monitor.Dropped(ctx, "max_time") + + errWithDetails, e := helper.ErrWithDetails( + helper.ErrUnavailablef("too many requests"), + &gitalypb.LimitError{ + ErrorMessage: "concurrency queue wait time reached", + RetryAfter: durationpb.New(0), + }, + ) + if e != nil { + return nil, err + } + return nil, errWithDetails } return nil, err } |