Skip to content

Feat/optimize logging - #1467

Closed
whatattitude wants to merge 216 commits into
QuantumNous:mainfrom
Furion-cn:feat/optimize-logging
Closed

Feat/optimize logging#1467
whatattitude wants to merge 216 commits into
QuantumNous:mainfrom
Furion-cn:feat/optimize-logging

Conversation

@whatattitude

@whatattitude whatattitude commented Jul 28, 2025

Copy link
Copy Markdown

Summary by CodeRabbit

New Features

  • Introduced batch job management APIs, including job registration, starting, and pre-signed URL generation.
  • Added user rate limit configuration query endpoint.
  • Implemented health check endpoint (/ping).
  • Enabled request logging toggle and pprof profiling control via API.
  • Added support for new channel types (e.g., XAI, Doubao offline, Doubao offline JOB).
  • Enhanced billing data export and quota data filtering by token.
  • Implemented request/response persistence and daily log partitioning.
  • Integrated Prometheus metrics for monitoring.
  • Added middleware for mock responses and request logging.

Improvements

  • Enhanced logging with rotation, sampling, and enriched context.
  • Refined role-based access control for channels, groups, tokens, and users.
  • Improved error messages and request/response handling.
  • Refactored relay and helper functions for modularity and better metrics.
  • Added support for new Claude, Gemini, and XAI model features.
  • Upgraded and expanded third-party dependencies.

Bug Fixes

  • Corrected log and error formatting, improved empty data handling in tables.
  • Fixed token group selection validation and error messaging in UI.

Chores

  • Updated .gitignore and Dockerfile for broader environment and build support.
  • Added and updated SQL migrations for new tables and fields.

Documentation

  • Extended localization files with new billing and quota-related entries.

Style

  • Improved UI for channel and token management to support new features and role-based filtering.

Tests

  • Added new data structures and testable components for billing, quota, and job management.

whatattitude and others added 27 commits June 28, 2025 13:31
feat: support o3-deep-research-2025-06-26 model
1. 调整main.go中中间件执行顺序,将RequestId()放在RequestLogger()之前
2. 修改RequestLogger中间件,使用全链路上下文进行日志打印
3. 包含request ID和gin上下文信息,支持日志采样和错误统计
4. 修复Gemini相关功能和其他依赖更新
feat: 调整中间件执行顺序,实现全链路日志追踪
@coderabbitai

coderabbitai Bot commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This update delivers a comprehensive refactor and feature expansion across backend, middleware, database, and frontend components. Major enhancements include: role-based access controls, batch job and billing features, daily log partitioning, advanced request/response logging, new relay channel types (including XAI and Doubao), metrics instrumentation, batch processing support for Volcengine, and numerous new API endpoints. The frontend is updated to support new filters, role-based data visibility, and billing export.

Changes

Cohort / File(s) Change Summary
Batch Job & Billing Features
controller/batchjob.go, model/batchjob.go, model/job.go, database/migrations/create_jobs_table.sql, service/job_service.go, relay/channel/volcengine/batchjob/tos.go, relay/channel/volcengine/batchchat.go, relay/channel/volcengine/redis_client.go, relay/channel/volcengine/keepalive.go, web/src/pages/Detail/index.js
Introduces batch job registration, execution, and status tracking with Volcengine; adds job models, migrations, TOS presign logic, Redis-based result caching, keep-alive management, and billing data export with Excel support.
Role-Based Filtering & Group Management
controller/channel.go, controller/group.go, controller/token.go, model/group.go, model/token.go, model/option.go, setting/user_usable_group.go, web/src/components/UsersTable.js, web/src/pages/Token/EditToken.js
Adds user/group role-based filtering for channels, groups, and tokens; introduces group model and management; enforces group selection on token creation; updates frontend for group-based data visibility.
Logging, Metrics & Request Handling
common/logger.go, model/log.go, main.go, metrics/metrics.go, middleware/request-logger.go, middleware/request-id.go, middleware/mock.go, controller/option.go, controller/pprof.go, common/pprof.go, .gitignore
Implements log rotation, daily log partitioning, log sampling, request/response logging with context, pprof server management, mock response middleware, and Prometheus metrics instrumentation.
Relay Refactor & New Channel Types
relay/relay-text.go, relay/relay-image.go, relay/relay_embedding.go, relay/relay_rerank.go, relay/relay-audio.go, relay/relay-task.go, relay/relay-mj.go, relay/channel/xai/*, relay/relay_adaptor.go, relay/common/relay_info.go, relay/constant/api_type.go, relay/constant/relay_mode.go, relay/channel/adapter.go, relay/channel/openai/adaptor.go, relay/channel/claude/adaptor.go, relay/channel/vertex/adaptor.go, relay/channel/aws/adaptor.go, relay/channel/volcengine/adaptor.go, relay/channel/gemini/dto.go, relay/channel/gemini/relay-gemini.go, relay/channel/openai/helper.go, relay/channel/openai/relay-openai.go, relay/helper/stream_scanner.go, relay/helper/common.go, relay/relay_direct.go
Modularizes relay handlers (splitting info/execution), adds new channel types (XAI, Doubao), supports batch relay, enhances error handling, and improves request/response processing and metrics.
Database & Persistence Enhancements
model/main.go, model/central_control.go, model/text_request.go, common/constants.go, common/init.go, common/time.go, constant/context_key.go
Adds central DB support, user rate limit config, text request persistence, new constants, and Beijing time utilities.
Quota & Usage Data Improvements
controller/usedata.go, model/usedata.go, dto/openai_response.go, dto/realtime.go, web/src/pages/Detail/index.js
Extends quota data to include token names, adds daily aggregation, billing, Excel export, and new usage fields.
Frontend: Role, Token, Channel, and Billing UI
web/src/components/LogsTable.js, web/src/components/TokensTable.js, web/src/constants/channel.constants.js, web/src/pages/Channel/EditChannel.js, web/src/helpers/utils.js, web/src/helpers/render.js, web/src/i18n/locales/en.json, web/src/i18n/locales/zh.json
Updates logs and tokens tables for new fields and role-based visibility, adds new channel types, improves billing UI, and extends localization.
API & Middleware Additions
router/api-router.go, router/relay-router.go, controller/misc.go, controller/user_rate_limit.go, middleware/auth.go, middleware/distributor.go, middleware/utils.go, service/error.go, service/quota.go, service/token_counter.go
Adds new API endpoints (ping, pprof, all tokens, user rate limit, billing export), improves authentication and error handling, and extends request processing logic.
Claude & OpenAI DTOs and Parsing
dto/claude.go, dto/openai_request.go, dto/error.go
Adds comprehensive Claude DTOs, extends OpenAI request/response DTOs for new fields and error/status codes, and improves multimodal content parsing.
Docker, Build, and Dependency Updates
Dockerfile, .github/workflows/docker-image-amd64.yml, go.mod
Switches to private base images, updates build workflow for Tencent Cloud Registry, and upgrades/adds dependencies (Prometheus, Volcengine, Excelize, etc.).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant API
    participant Middleware
    participant Controller
    participant Model
    participant DB
    participant Volcengine
    participant Redis

    User->>Frontend: Interact (e.g., billing export, batch job)
    Frontend->>API: Send request (with auth, filters)
    API->>Middleware: Process request (logging, mock, auth)
    Middleware->>Controller: Route to appropriate handler
    Controller->>Model: Validate/request data (role/group aware)
    Model->>DB: Query/update (logs, jobs, tokens, groups)
    Controller->>Volcengine: (if batch job) Submit job/request presign
    Controller->>Redis: (if batch job) Cache results/status
    Controller->>Frontend: Return response (data, status, file)
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~90+ minutes

Possibly related PRs

Suggested reviewers

  • creamlike1024
  • Calcium-Ion

Poem

A rabbit hops through code so wide,
With logs that roll and groups that guide.
Batch jobs queue and tokens gleam,
Metrics sparkle in the stream.
From XAI to Doubao, features bloom—
This code refactor clears all gloom!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

jiutubaba pushed a commit to jiutubaba/fx-api that referenced this pull request May 17, 2026
…service-cleanup

refactor(channel): split long functions, extract shared validation, move billing validation to service
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.

5 participants