Skip to content

feat(limit-count): upgrade lua-resty-limit-traffic to v1.2.0#13212

Merged
nic-6443 merged 3 commits into
apache:masterfrom
nic-6443:feat/upgrade-limit-traffic-v120
Apr 14, 2026
Merged

feat(limit-count): upgrade lua-resty-limit-traffic to v1.2.0#13212
nic-6443 merged 3 commits into
apache:masterfrom
nic-6443:feat/upgrade-limit-traffic-v120

Conversation

@nic-6443

Copy link
Copy Markdown
Member

Description

Upgrade apisix-runtime from 1.3.3 to 1.3.4 which includes lua-resty-limit-traffic v1.2.0 (from api7/lua-resty-limit-traffic). The library changed its counter semantics from counting down (returning remaining) to counting up (returning consumed).

Changes

.requirements

  • APISIX_RUNTIME=1.3.3APISIX_RUNTIME=1.3.4

limit-count-local.lua — consumed→remaining conversion:

  • The v1.2.0 library returns consumed count instead of remaining. The wrapper converts it back to remaining via self.limit - consumed, preserving the existing API contract.
  • Error strings (e.g. "rejected") pass through unchanged via a type() check.

limit-count/init.lua — improved dry_run peek:

  • For local policy with dry_run=true: uses cost=0 with commit=false for a side-effect-free peek. dict:get reads the counter without creating or incrementing the key.
  • Adds manual rejection check: if remaining - cost < 0 after peek, converts to standard "rejected" flow.
  • Redis/redis-cluster path: unchanged (no dry_run support).

ai-rate-limiting-expression.t — fix remaining header values:

  • The dry_run peek in access phase no longer deducts cost=1 from remaining, fixing off-by-1 in X-AI-RateLimit-Remaining header (e.g., 499→500, 319→320).

limit-count5.t — new TEST 8:

  • Validates that cost=0 peek does not consume quota: multiple peeks return stable remaining, interleaved with real commits that correctly decrement.

Upgrade apisix-runtime from 1.3.3 to 1.3.4 which includes
lua-resty-limit-traffic v1.2.0. The library changed from counting
down (returning remaining) to counting up (returning consumed).

Changes:
- limit-count-local.lua: convert consumed to remaining via
  self.limit - consumed, pass through error strings unchanged
- limit-count/init.lua: use cost=0 with commit=false for dry_run
  peek (side-effect free), add manual rejection check
- ai-rate-limiting-expression.t: fix remaining header values now
  that dry_run peek no longer deducts cost from remaining
- limit-count5.t: add test for cost=0 peek behavior

Reference: api7-ee-3-gateway#1090 (54a7acb)
Copilot AI review requested due to automatic review settings April 13, 2026 07:54
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. dependencies Pull requests that update a dependency file enhancement New feature or request labels Apr 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Upgrades the bundled APISIX runtime (and its lua-resty-limit-traffic dependency) and adapts the limit-count plugin to preserve the existing “remaining quota” contract after the library changed its counter semantics to return “consumed”.

Changes:

  • Bump APISIX_RUNTIME to 1.3.4.
  • Convert consumed -> remaining in the local limit-count wrapper.
  • Adjust local-policy dry-run to perform a side-effect-free “peek” (commit=false, cost=0) and update tests/header expectations accordingly.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
.requirements Updates APISIX runtime version to pick up new limiter semantics.
apisix/plugins/limit-count/limit-count-local.lua Converts returned “consumed” to “remaining” and continues computing reset.
apisix/plugins/limit-count/init.lua Changes local dry-run behavior to peek without consuming quota and adds explicit rejection check.
t/plugin/ai-rate-limiting-expression.t Updates expected remaining headers to match new dry-run peek behavior.
t/plugin/limit-count5.t Adds a new test intended to verify that peeks don’t consume quota.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apisix/plugins/limit-count/limit-count-local.lua
Comment thread t/plugin/limit-count5.t Outdated
- ai-rate-limiting.t: update remaining header values (+1) because
  dry_run peek with cost=0 no longer deducts from remaining quota
- limit-count5.t TEST 8: use unique key to avoid shared dict
  collision with TEST 1 which stores data for key '/t'
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 13, 2026
@nic-6443
nic-6443 merged commit 6427788 into apache:master Apr 14, 2026
19 checks passed
@nic-6443
nic-6443 deleted the feat/upgrade-limit-traffic-v120 branch April 14, 2026 02:15
wistefan pushed a commit to wistefan/apisix that referenced this pull request Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants