diff options
author | John Cai <jcai@gitlab.com> | 2022-03-21 23:53:01 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2022-04-05 20:57:43 +0300 |
commit | aad545f661c295bcff422424e76abe7c2fd85a10 (patch) | |
tree | 7661eb9aa70b7e697bce08692624b6bf390bf184 | |
parent | 251ee0c20a8898d8165bf5b0028b85eb11e6c61c (diff) |
config: Add RateLimiting configuration
To prepare for a rate limiting middleware, add a struct to support
configuring a rate limiter. Behind the scenes, we are using
golang.org/x/time/rate package, which implements rate limiting with a
concept of a token bucket. There are two relevant values. Burst refers
to the maximum size of the token bucket. For a request to be handled, a
token is retrieved from the token bucket. Once the bucket is empty, no
more requests can be handled.
The token bucket will be refilled to capacity as defined by "Burst"
according to what is set by "Interval".
Changelog: added
-rw-r--r-- | internal/gitaly/config/config.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/gitaly/config/config.go b/internal/gitaly/config/config.go index 3f6757db3..49b6cc509 100644 --- a/internal/gitaly/config/config.go +++ b/internal/gitaly/config/config.go @@ -60,6 +60,7 @@ type Cfg struct { GitlabShell GitlabShell `toml:"gitlab-shell"` Hooks Hooks `toml:"hooks"` Concurrency []Concurrency `toml:"concurrency"` + RateLimiting []RateLimiting `toml:"rate_limiting"` GracefulRestartTimeout Duration `toml:"graceful_restart_timeout"` InternalSocketDir string `toml:"internal_socket_dir"` DailyMaintenance DailyJob `toml:"daily_maintenance"` @@ -149,6 +150,22 @@ type Concurrency struct { MaxQueueWait Duration `toml:"max_queue_wait"` } +// RateLimiting allows endpoints to be limited to a maximum request rate per +// second. The rate limiter uses a concept of a "token bucket". In order to serve a +// request, a token is retrieved from the token bucket. The size of the token +// bucket is configured through the Burst value, while the rate at which the +// token bucket is refilled per second is configured through the RequestsPerSecond +// value. +type RateLimiting struct { + // RPC is the full name of the RPC including the service name + RPC string `toml:"rpc"` + // Interval sets the interval with which the token bucket will + // be refilled to what is configured in Burst. + Interval time.Duration `toml:"interval"` + // Burst sets the capacity of the token bucket (see above). + Burst int `toml:"burst"` +} + // StreamCacheConfig contains settings for a streamcache instance. type StreamCacheConfig struct { Enabled bool `toml:"enabled"` // Default: false |