refactor(rate-limit): change rate limiting granularity from tenant to API Key

- Refactor rate limiting mechanism to limit per API Key instead of per tenant (workspace).
- Update error code logic and Redis key naming conventions.
- Adjust quota usage statistics to display the QPS of the API Key closest to its limit.
This commit is contained in:
wwq
2026-04-20 16:13:30 +08:00
parent 48f3d9b105
commit c448cf0660
3 changed files with 23 additions and 11 deletions

View File

@@ -284,8 +284,8 @@ class RateLimiterService:
async def check_tenant_rate_limit(self, window_id: uuid.UUID, limit: int) -> Tuple[bool, dict]:
"""
按 window_idworkspace_id做 1 秒滑动窗口限速。
限制值来自套餐配额 api_ops_rate_limit。
按 window_idapi_key_id做 1 秒滑动窗口限速。
限制值来自套餐配额 api_ops_rate_limit,每个 API Key 独立受此上限约束
只有请求被允许时才计入窗口,超限请求不污染计数。
"""
now = time.time()