feat: ai-token-ratelimit support setting global rate limit thresholds for routes​ (#2667)

This commit is contained in:
韩贤涛
2025-07-28 08:14:35 +08:00
committed by GitHub
parent e6e4193679
commit 6a1557f6ac
14 changed files with 981 additions and 564 deletions

View File

@@ -20,6 +20,16 @@ func TestParseClusterKeyRateLimitConfig(t *testing.T) {
json: `{}`,
expectedErr: errors.New("missing rule_name in config"),
},
{
name: "GlobalThreshold_InvalidThreshold",
json: `{
"rule_name": "invalid-threshold",
"global_threshold": {
"query_per_minute": -100
}
}`,
expectedErr: errors.New("failed to parse global_threshold: 'query_per_minute' must be a positive integer, got -100"),
},
{
name: "GlobalThreshold_QueryPerSecond",
json: `{
@@ -56,6 +66,21 @@ func TestParseClusterKeyRateLimitConfig(t *testing.T) {
RejectedMsg: DefaultRejectedMsg,
},
},
{
name: "RuleItems_InvalidThreshold",
json: `{
"rule_name": "invalid-threshold",
"rule_items": [
{
"limit_by_header": "x-test",
"limit_keys": [
{"key": "key1", "query_per_minute": -100}
]
}
]
}`,
expectedErr: errors.New("failed to parse rule_item in rule_items: 'query_per_minute' must be a positive integer for key 'key1', got -100"),
},
{
name: "RuleItems_SingleRule",
json: `{