lib/ratelimit, lib/concurrentlimit: add protocol-neutral rate and concurrency limiters - #288
lib/ratelimit, lib/concurrentlimit: add protocol-neutral rate and concurrency limiters#288Vikramarjuna wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
What is this package needed? Why can't callers use the existing lib/srpc/serverutil package?
There was a problem hiding this comment.
Dropped — serverutil is unmodified. I'd lifted it out so a future gRPC/REST handler wouldn't have to import lib/srpc. Will add it later if needed.
| // Protocol identifies the wire protocol that admitted a request. It is used as | ||
| // a dimension on rate-limit denial metrics so that quota violations can be | ||
| // attributed to SRPC, gRPC or REST. | ||
| type Protocol string |
There was a problem hiding this comment.
Please change to uint type and implement a String() method for readable output. See the various examples in the proto directory for the pattern used.
| const ( | ||
| LimitTypeGlobal = "global" | ||
| LimitTypePerMethod = "per_method" | ||
| LimitTypePerUserPerMethod = "per_user_per_method" |
There was a problem hiding this comment.
Please add and use LimitType as a uint type and implement a String() method for readable output. See the various examples in the proto directory for the pattern used.
| return errors.NewResourceExhaustedError(method, LimitTypePerMethod) | ||
| } | ||
| // Empty username means an unauthenticated caller reached a public or | ||
| // unauthenticated method; the per-user-per-method tier has no identity |
There was a problem hiding this comment.
Unauthenticated callers should not reach a method which is merely marked as public. A method must be marked as allowing unauthenticated access in order for an unauthenticated caller to reach it.
98e41d4 to
6553e6a
Compare
6553e6a to
8ac6ff8
Compare
Adds lib/ratelimit, a three-tier token-bucket rate limiter (global, per-method, per-user-per-method) intended to be shared across SRPC, gRPC and REST handlers so quotas cannot be bypassed by switching protocols. Denials return *errors.ResourceExhaustedError.