Skip to content

Commit 25d5268

Browse files
committed
Revert "fix: adapt limit-count-local for lua-resty-limit-traffic v1.2.0 semantics"
This reverts commit 98ce8f3.
1 parent 98ce8f3 commit 25d5268

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

apisix/plugins/limit-count/init.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,6 @@ local function run_rate_limit(conf, rule, ctx, name, cost, dry_run)
401401
local delay, remaining, reset
402402
if not conf.policy or conf.policy == "local" then
403403
delay, remaining, reset = lim:incoming(key, not dry_run, conf, cost)
404-
if dry_run and type(remaining) == "number" and remaining - cost < 0 then
405-
delay = nil
406-
remaining = "rejected"
407-
end
408404
else
409405
delay, remaining, reset = lim:incoming(key, cost)
410406
end

apisix/plugins/limit-count/limit-count-local.lua

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ local limit_count = require("resty.limit.count")
1818

1919
local ngx = ngx
2020
local ngx_time = ngx.time
21-
local type = type
2221
local assert = assert
2322
local setmetatable = setmetatable
2423
local core = require("apisix.core")
@@ -67,22 +66,16 @@ function _M.new(plugin_name, limit, window)
6766
end
6867

6968
function _M.incoming(self, key, commit, conf, cost)
70-
local actual_cost = commit and cost or 0
71-
local delay, consumed_or_err = self.limit_count:incoming(key, true, actual_cost)
69+
local delay, remaining = self.limit_count:incoming(key, commit, cost)
7270
local reset
7371

74-
local remaining_or_err = consumed_or_err
75-
if type(consumed_or_err) == "number" then
76-
remaining_or_err = self.limit - consumed_or_err
77-
end
78-
79-
if remaining_or_err == self.limit - actual_cost then
72+
if remaining == self.limit - cost then
8073
reset = set_endtime(self, key, self.window)
8174
else
8275
reset = read_reset(self, key)
8376
end
8477

85-
return delay, remaining_or_err, reset
78+
return delay, remaining, reset
8679
end
8780

8881
return _M

t/plugin/ai-rate-limiting-expression.t

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ passed
271271
]
272272
--- response_headers_like eval
273273
[
274-
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 500",
275-
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 320",
274+
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 499",
275+
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 319",
276276
]
277277
--- no_error_log
278278
[error]
@@ -340,8 +340,8 @@ passed
340340
]
341341
--- response_headers_like eval
342342
[
343-
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 500",
344-
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 320",
343+
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 499",
344+
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 319",
345345
]
346346
--- no_error_log
347347
[error]
@@ -475,8 +475,8 @@ passed
475475
]
476476
--- response_headers_like eval
477477
[
478-
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 1000",
479-
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 775",
478+
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 999",
479+
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 774",
480480
]
481481
--- no_error_log
482482
[error]
@@ -544,8 +544,8 @@ passed
544544
]
545545
--- response_headers_like eval
546546
[
547-
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 500",
548-
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 420",
547+
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 499",
548+
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 419",
549549
]
550550
--- no_error_log
551551
[error]
@@ -613,8 +613,8 @@ passed
613613
]
614614
--- response_headers_like eval
615615
[
616-
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 100",
617-
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 100",
616+
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 99",
617+
"X-AI-RateLimit-Remaining-ai-proxy-anthropic: 99",
618618
]
619619
--- no_error_log
620620
[error]

0 commit comments

Comments
 (0)