Skip to content

[CLOUD-303] Set rate limiter for every external service

Created by: unknwon

Previously we have been using the URL of the code host as the key of rate limiting units, it is no longer appropriate for Cloud as all user and organization code host connections are pointing to GitLab.com and GitHub.com. This imposes inefficiency in repository permissions syncing on Cloud (and literally all operations involved code host communication), because it ends up all user and organization code host connections share the same rate limit quota which in reality they are very likely from different accounts, with different tokens, with independent quotas on the code hosts.

This PR changes the the key of rate limiting units to be URN of external services, which looks like extsvc:<kind>:<id> (extsvc:github:1) and is unique to every external service. The reason that external service ID is picked because there are legitimate places where our API calls are not tied to any external services but as the instance as a whole. The string type still allows us to uniquely identify those resources.

Impact

For on-premise customers,

  • rate limiter behavior will not change if they only have single site-level code host connection configured for different code hosts.
  • if they have multiple site-level code host connections for a single code host and do intent to enforce rate limit on Sourcegraph side, they'll need to configure rate limit in each of them.

Review notes

  • There are lots of mechanical changes that touches number of files for adding urn string to the method signature. The core change is in the internal/ratelimit/rate_limit.go file.
  • Rate limit conflict checking for same URL is removed.
  • RateLimitSyncer.SyncRateLimiters has been refactored to be capable of sync rate limiters for all or selected external services.

Test plan

Unit tests.


Jira: CLOUD-303

Merge request reports

Loading