Skip to main content
Version: 1.0.x

Limits With Allocation Percentage

The allocation_percentage field allows users to allocate a specific percentage of a main quota to different internal quotas, ensuring more flexible and precise control over quota usage among different user groups or environments.

Example Use Case

In the example below, a primary quota (MyQuota) limits API usage to 100,000 requests per month. We then allocate 20% of this quota to the staging environment and 80% to production.

  • Primary Quota: Limits API usage to a maximum of 100,000 requests per month.
  • Staging Quota: Allocates 20% of the primary quota, up to 20,000 requests.
  • Production Quota: Allocates 80% of the primary quota, up to 80,000 requests.

Example YAML Configuration

/etc/lunar-proxy/quotas/{fileName}.yaml
quotas:
- id: MyQuota
filter:
url: httpbin.org/get
strategy:
fixed_window:
max: 100
interval: 1
interval_unit: month
monthly_renewal:
day: 1
hour: 11
minute: 0
second: 0
timezone: UTC

internal_limits:
- id: LimiterStaging
parent_id: MyQuota
filter:
header:
key: X-Group
value: staging
strategy:
allocation_percentage: 20

- id: LimiterProd
parent_id: MyQuota
filter:
header:
key: X-Group
value: production
strategy:
allocation_percentage: 80
note
  • Combination Restriction: We do not allow a combination of both fixed_window and allocation_percentage strategies within the same internal_limits list.
  • Zero Percent Restriction: An allocation of 0% is not allowed and will return an error.
  • Total Allocation Requirement: The total percentage allocations must add up to exactly 100% for the quota configuration to be valid.