Skip to content

合并 - #2287

Closed
Futureppo wants to merge 5 commits into
QuantumNous:mainfrom
Futureppo:addbanlist
Closed

合并#2287
Futureppo wants to merge 5 commits into
QuantumNous:mainfrom
Futureppo:addbanlist

Conversation

@Futureppo

@Futureppo Futureppo commented Nov 24, 2025

Copy link
Copy Markdown

合并

Summary by CodeRabbit

Release Notes

  • New Features

    • Added channel-based rate limiting with per-model configuration for requests per minute (RPM), tokens per minute (TPM), and requests per day (RPD).
    • New monitoring interface to view current usage against configured rate limits for each model.
    • Rate limit management page added to the admin console.
    • Rate limits are now enforced across API requests.
  • Documentation

    • Updated project README.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This PR introduces channel-level rate limiting with per-model configuration. It adds Redis-backed rate limit enforcement (RPM/TPM/RPD), a monitoring endpoint for viewing real-time usage, backend rate limit checks in the relay loop, and a complete admin UI for managing and displaying rate limit metrics.

Changes

Cohort / File(s) Summary
Documentation
.gitignore, README.md, README.old.md
Adds start.txt to ignore list; replaces README with attribution statement; archives prior comprehensive README with deployment, feature, and documentation details.
Backend Rate Limiting Service
service/channel_rate_limit.go
Implements Redis-backed rate limiting with CheckChannelRateLimit (validates RPM sliding window, TPM and RPD fixed windows) and RecordChannelRateLimit (logs usage with 1-min/24-hr expirations). Exports constants for Redis key prefixes.
Backend Error Types
types/error.go
Adds ErrorCodeChannelRateLimited constant for channel rate limit exceeded error responses.
Backend Controller & Monitoring
controller/channel_monitor.go
New HTTP handler GetChannelMonitorData serves per-channel monitoring data; fetches current RPM/TPM/RPD usage from Redis and compares against channel and per-model rate limits.
Backend Relay Integration
controller/relay.go
Integrates per-model rate limiting into relay loop: checks limits before request, records usage after success, with model-specific overrides.
Backend Data Models
model/channel.go, relay/common/relay_info.go
Channel adds rate limit fields (RateLimitRPM, RateLimitTPM, RateLimitRPD, RateLimitSettings) with getter methods and RateLimitConfig type. RelayInfo adds CompletionTokens field.
Backend Routing
router/api-router.go
Adds GET /api/channel/:id/monitor route to controller.GetChannelMonitorData.
Frontend Pages
web/src/pages/RateLimit/index.jsx
New rate limit management page displaying per-channel and per-model rate usage with progress indicators, channel selector, and refresh controls.
Frontend Channel Components
web/src/components/table/channels/ChannelsColumnDefs.jsx, ChannelsTable.jsx, index.jsx
Adds "速率限制" menu item to channel operations; threads monitor modal state through columns; imports and renders ChannelMonitorModal.
Frontend Channel Modals
web/src/components/table/channels/modals/ChannelMonitorModal.jsx, EditChannelModal.jsx
ChannelMonitorModal displays real-time rate metrics; EditChannelModal adds rate limit input fields (RPM, TPM, RPD) and JSON settings textarea.
Frontend Hooks & Utilities
web/src/hooks/channels/useChannelsData.jsx, web/src/hooks/common/useSidebar.js, web/src/helpers/render.jsx
useChannelsData exposes monitor modal state; useSidebar adds rate_limit admin module flag; render helpers add rate_limit icon mapping.
Frontend App Setup
web/src/App.jsx, web/src/components/layout/SiderBar.jsx
App adds admin-protected /console/rate_limit route; SiderBar adds "速率限制管理" menu item under Admin section.

Sequence Diagram

sequenceDiagram
    actor Admin as Admin
    participant UI as Frontend UI
    participant API as Backend API
    participant Redis as Redis
    participant DB as Database

    rect rgb(220, 240, 255)
    note over Admin,DB: Rate Limit Check During Relay
    end
    API->>API: Relay receives request
    API->>DB: Fetch channel & model rate limits
    API->>API: Determine RPM, TPM, RPD limits
    API->>Redis: CheckChannelRateLimit(channel, model)
    alt Limit Exceeded
        Redis-->>API: Error (RPM/TPM/RPD exceeded)
        API->>API: Return ChannelRateLimited error
    else Limit OK
        Redis-->>API: OK
        API->>API: Forward request downstream
        API->>Redis: RecordChannelRateLimit(usage)
        Redis->>Redis: Log timestamp/counter
        API-->>API: Return response
    end

    rect rgb(240, 255, 240)
    note over Admin,DB: Rate Limit Monitoring Flow
    end
    Admin->>UI: Open rate limit monitor
    UI->>API: GET /api/channel/:id/monitor
    API->>DB: Fetch channel & models
    API->>Redis: Read current RPM/TPM/RPD
    Redis-->>API: Usage counters
    API->>API: Calculate aggregates per model
    API-->>UI: ChannelMonitorData (current/limits)
    UI->>UI: Render progress bars & metrics
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Areas requiring extra attention:

  • service/channel_rate_limit.go: Verify Redis key expiry logic (1-min for TPM, 24-hr for RPD) and sliding-window correctness for RPM; ensure list trimming prevents unbounded growth.
  • controller/relay.go: Confirm rate limit checks integrate correctly with existing retry and error-handling paths; validate model-specific override logic.
  • web/src/components/table/channels/modals/ChannelMonitorModal.jsx: Review data fetching pattern on mount and dependency arrays; ensure loading state prevents race conditions.
  • web/src/pages/RateLimit/index.jsx: Validate channel selection state transitions and auto-refresh logic for monitor data.
  • Cross-layer consistency: Verify rate limit field naming (RateLimitRPM, rate_limit_rpm) is consistent across backend model, frontend form, and API responses.

Possibly related PRs

Suggested reviewers

  • Calcium-Ion
  • creamlike1024

Poem

🐰 Whiskers twitch with rate-limiting delight,
Redis counts the tokens spinning through the night,
Per-model limits, sliding windows clean,
The fastest relay ever, yet so serene!
Monitor dashboards glow with metrics bright—
One bunny's code brings order to the fight.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f80e3f and 3ab084f.

📒 Files selected for processing (21)
  • .gitignore (1 hunks)
  • README.md (1 hunks)
  • README.old.md (1 hunks)
  • controller/channel_monitor.go (1 hunks)
  • controller/relay.go (2 hunks)
  • model/channel.go (2 hunks)
  • relay/common/relay_info.go (1 hunks)
  • router/api-router.go (1 hunks)
  • service/channel_rate_limit.go (1 hunks)
  • types/error.go (1 hunks)
  • web/src/App.jsx (2 hunks)
  • web/src/components/layout/SiderBar.jsx (2 hunks)
  • web/src/components/table/channels/ChannelsColumnDefs.jsx (2 hunks)
  • web/src/components/table/channels/ChannelsTable.jsx (3 hunks)
  • web/src/components/table/channels/index.jsx (2 hunks)
  • web/src/components/table/channels/modals/ChannelMonitorModal.jsx (1 hunks)
  • web/src/components/table/channels/modals/EditChannelModal.jsx (3 hunks)
  • web/src/helpers/render.jsx (2 hunks)
  • web/src/hooks/channels/useChannelsData.jsx (2 hunks)
  • web/src/hooks/common/useSidebar.js (1 hunks)
  • web/src/pages/RateLimit/index.jsx (1 hunks)

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@Futureppo Futureppo closed this Nov 24, 2025
@Futureppo Futureppo reopened this Nov 24, 2025
@Futureppo Futureppo closed this Nov 24, 2025
@Futureppo
Futureppo deleted the addbanlist branch November 24, 2025 08:09
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