Skip to content

router: clean up rate limiters when spec.rateLimit is cleared from ModelRoute - #1506

Open
bhuvan-somisetty wants to merge 1 commit into
volcano-sh:mainfrom
bhuvan-somisetty:fix/router-ratelimit-delete-on-spec-clear-1505
Open

router: clean up rate limiters when spec.rateLimit is cleared from ModelRoute#1506
bhuvan-somisetty wants to merge 1 commit into
volcano-sh:mainfrom
bhuvan-somisetty:fix/router-ratelimit-delete-on-spec-clear-1505

Conversation

@bhuvan-somisetty

@bhuvan-somisetty bhuvan-somisetty commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it:
When an existing ModelRoute custom resource is updated to remove its spec.rateLimit configuration (clearing spec.rateLimit so traffic for that model is no longer rate-limited), the router's event callback in pkg/kthena-router/router/router.go previously returned early without calling loadRateLimiter.DeleteLimiter. Consequently, the router retained active input and output token rate limiters in memory and continued enforcing stale rate limits (TPS/TPM) against all requests for that model indefinitely.

This PR addresses the issue by:

  1. Updating the ModelRoute event handler in pkg/kthena-router/router/router.go to invoke loadRateLimiter.DeleteLimiter(data.ModelName) when spec.rateLimit is nil during EventAdd or EventUpdate events.
  2. Updating AddOrUpdateLimiter in pkg/kthena-router/filters/ratelimit/ratelimit.go to delete specific directional limiters (inputLimiter or outputLimiter) when InputTokensPerUnit or OutputTokensPerUnit is set to nil on update.
  3. Adding unit test cases in ratelimit_test.go and router_test.go verifying that rate limiters are cleared when spec.rateLimit is removed.

Which issue(s) this PR fixes:
Fixes #1505

Bug evidence (required for bug-related PRs):

Special notes for your reviewer:

  • Unit tests added: TestTokenRateLimiter_DeleteLimiter, TestTokenRateLimiter_UpdateClearsNilDirectionalLimits, and TestRouter_ModelRouteRateLimitClearedOnUpdate.
  • All unit tests under ./pkg/kthena-router/... pass cleanly.

Does this PR introduce a user-facing change?:

NONE

@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

cc @YaoZengzeng @LiZhenCheng9527 @hzxuzhonghu @git-malu @FAUST-BENCHOU

Hi maintainers, when you get a chance please take a look at this PR. It ensures rate limiters are properly cleaned up when spec.rateLimit is removed from a ModelRoute custom resource. Unit tests have been added and all checks are passing.

@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix/router-ratelimit-delete-on-spec-clear-1505 branch 2 times, most recently from cf9d704 to 59659c6 Compare August 5, 2026 13:15
@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign yaozengzeng for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix/router-ratelimit-delete-on-spec-clear-1505 branch 2 times, most recently from a019c43 to d0248dd Compare August 5, 2026 15:05

@LiZhenCheng9527 LiZhenCheng9527 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it would be possible to write a function that takes *uint32 (the type of inputTokensPerUnit), if it to nil, delete a recode in map. and abstracts the deletion strategy into a function. This would help avoid multiple if-else branches within a single function.

…delRoute

When an existing ModelRoute resource is updated to remove its spec.rateLimit configuration, the router's event callback in pkg/kthena-router/router/router.go previously returned early without calling DeleteLimiter. Consequently, the router retained active input and output token rate limiters in memory and continued enforcing stale rate limits against requests for that model indefinitely.

This change updates the router's ModelRoute event handler to:
- Invoke loadRateLimiter.DeleteLimiter for the model name when spec.rateLimit is nil on EventAdd or EventUpdate events.
- Update AddOrUpdateLimiter in TokenRateLimiter to clear directional (input or output) limiters when either InputTokensPerUnit or OutputTokensPerUnit is nil on update.

Unit tests in ratelimit_test.go and router_test.go verify that rate limiters are deleted when spec.rateLimit is cleared or updated.

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix/router-ratelimit-delete-on-spec-clear-1505 branch from d0248dd to 4fdf333 Compare August 6, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: kthena-router does not remove rate limiters when spec.rateLimit is cleared from ModelRoute

3 participants