Interface QuotaEnforcer


public interface QuotaEnforcer
Allows plugins to enforce different types of quota.

Enforcing quotas can be helpful in many scenarios. For example:

  • Reducing the number of QPS a user can send to Gerrit on the REST API
  • Limiting the size of a repository (project)
  • Limiting the number of changes in a repository
  • Limiting the number of actions that have the potential for spam, abuse or flooding if not limited
This endpoint gives plugins the capability to enforce any of these limits. The server will ask all plugins that registered this endpoint and collect all results. In case requestTokens(String, QuotaRequestContext, long) was called and one or more plugins returned an erroneous result, the server will call refill(String, QuotaRequestContext, long) on all plugins with the same parameters. Plugins that deducted tokens in the requestTokens(String, QuotaRequestContext, long) call can refill them so that users don't get charged any quota for failed requests.

Not all implementations will need to deduct quota on requestTokens(String, QuotaRequestContext, long)}. Implementations that work on top of instance-attributes, such as the number of projects per instance can choose not to keep any state and always check how many existing projects there are and if adding the inquired number would exceed the limit. In this case, requestTokens(String, QuotaRequestContext, long) and dryRun(String, QuotaRequestContext, long) share the same implementation and refill(String, QuotaRequestContext, long) is a no-op.

  • Method Details