Skip to content

test(e2e): pin that a gateway rate-limit 429 reaches the usage feed - #1070

Merged
jarvis9443 merged 1 commit into
mainfrom
test/1389-gateway-429-usage-row
Aug 28, 2026
Merged

test(e2e): pin that a gateway rate-limit 429 reaches the usage feed#1070
jarvis9443 merged 1 commit into
mainfrom
test/1389-gateway-429-usage-row

Conversation

@jarvis9443

Copy link
Copy Markdown
Contributor

Follow-up coverage for api7/AISIX-Cloud#1389, extending the member-attribution spec #1066 added.

A 429 reaches a caller two ways: the upstream throttled us, or the gateway's own rate limit refused the request before any upstream was contacted. Only the first is an upstream attempt. The gateway's own refusal leaves the failure path with zero attempts, so it is emitted by a different branch — chat.rs's match charge zero-attempt arm rather than its per-attempt loop — and nothing covered that branch.

"Show me this member's 429s" needs both to work, and the gateway's own refusals are the more likely half of the question in practice.

Why a test rather than a comment

Reading the emit code makes it easy to conclude the zero-attempt case produces nothing at all: emit_failed_attempts is right there, it iterates routing.attempts, and that list is empty for a pre-dispatch rejection. The arm that actually emits sits ~30 lines further down, past the loop. I reached the wrong conclusion from exactly that read while working on #1389, and only a real request settled it.

What it drives

A real key-level rate_limit: {rpm: 1} on a member-owned key, through a real aisix binary: the first request succeeds, the second is refused by the gateway. The refused request's row must carry

  • status_code = 429,
  • the member's user_id, so the Logs member filter finds it,
  • error_class = rate_limit_exceeded — what lets an operator tell "we throttled them" from "the provider throttled us",
  • zero billed tokens, since nothing was sent upstream,

plus a {user_id, status="429"} increment on aisix_usage_events_emitted_total.

No production code changes.

Ref api7/AISIX-Cloud#1389

A 429 reaches a caller two ways: the upstream throttled us, or the
gateway's own rate limit refused the request before any upstream was
contacted. Only the first is an upstream *attempt*. The gateway's own
refusal leaves the failure path with zero attempts, so it is emitted by a
genuinely different branch — `chat.rs`'s `match charge` zero-attempt arm
rather than its per-attempt loop — and nothing covered that branch.

"Show me this member's 429s" (AISIX-Cloud#1389) is the question that
needs both. Reading the emit code makes it easy to conclude the
zero-attempt case produces nothing at all, because the per-attempt loop
is right there and iterates an empty list; the arm that actually emits it
sits below the loop. A test settles that far better than a careful read
does.

Drives a real key-level `rate_limit: {rpm: 1}` through a real binary and
asserts the refused request's row carries status 429, the member, an
error class that distinguishes a gateway refusal from an upstream one,
and zero billed tokens.

Ref api7/AISIX-Cloud#1389
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

On-demand reviews are free for the next 23 days. After that, they cost $0.25 per reviewed file.

Or wait 10 minutes for your next included review.

View limit details

Limit details: You’ve used the included review currently available. Your 62 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c45632fd-ef29-4127-b2a9-1a8e1ca5c028

📥 Commits

Reviewing files that changed from the base of the PR and between f93f25f and eeee6cb.

📒 Files selected for processing (1)
  • tests/e2e/src/cases/usage-member-attribution-e2e.test.ts

Comment @coderabbitai help to get the list of available commands.

@jarvis9443
jarvis9443 merged commit b3083de into main Aug 28, 2026
12 checks passed
@jarvis9443
jarvis9443 deleted the test/1389-gateway-429-usage-row branch August 28, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant