feat: support ClickHouse log database - #5663
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughReplaces exported boolean database-flag variables ( ChangesDatabaseType Abstraction, ClickHouse Log DB, and Request-ID Centralization
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@model/log.go`:
- Around line 670-685: The ClickHouse deletion path in the if block checking
common.UsingLogDatabase(common.DatabaseTypeClickHouse) does not respect a limit
parameter when deleting old logs, unlike the non-ClickHouse branch. Modify the
LOG_DB.Exec call that executes the ALTER TABLE logs DELETE query to include a
LIMIT clause using the limit parameter that should be available as a function
parameter, preventing unbounded deletion operations and avoiding the enqueuing
of oversized mutations in ClickHouse.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7dd470bb-8dff-420f-817b-790119e6b4b7
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (24)
AGENTS.mdCLAUDE.mdcommon/database.gocommon/utils.gocontroller/model_list_test.gocontroller/setup.gocontroller/token_test.godocker-compose.ymlgo.modmiddleware/request-id.gomodel/ability.gomodel/channel.gomodel/checkin.gomodel/db_time.gomodel/log.gomodel/main.gomodel/redemption.gomodel/subscription.gomodel/task_cas_test.gomodel/topup.gomodel/usedata_rankings.gorelay/common/relay_info.goservice/task_billing_test.goservice/waffo_pancake_test.go
💤 Files with no reviewable changes (1)
- service/waffo_pancake_test.go
Merge upstream changes including: - ClickHouse log database support (QuantumNous#5663) - System task for persistent log cleanup progress - Passive channel monitoring mode (QuantumNous#5592) - Channel test environment toggle - Node name defaults to hostname when NODE_NAME unset (QuantumNous#5659) - tsgo for web type checking - Refactored database type detection API (UsingMainDatabase/UsingLogDatabase) Conflict resolution: - AGENTS.md, CLAUDE.md: kept local Chinese version, added UsingMainDatabase/UsingLogDatabase docs - controller/channel-test.go: kept AIHubError naming, adopted allowDisable + localErr checks - docker-compose.yml: kept ai-hub naming, added ClickHouse config - model/redemption.go: kept local deletion (feature removed) - web/default/package.json: adopted upstream tsgo/oxlint/oxfmt toolchain - use-sidebar-data.ts: kept local (no redemption codes) - i18n locale files: kept local translations, added 8 new upstream keys
* feat: support ClickHouse log database * feat(log): optimize log deletion process for ClickHouse
* feat: support ClickHouse log database * feat(log): optimize log deletion process for ClickHouse
* feat: support ClickHouse log database * feat(log): optimize log deletion process for ClickHouse
Important
📝 变更描述 / Description
本次变更为
LOG_SQL_DSN增加 ClickHouse 日志库支持,主业务库SQL_DSN仍限制为 SQLite、MySQL 或 PostgreSQL,避免将 ClickHouse 用作事务型主库。日志表在 ClickHouse 下改为手写
MergeTree建表,按created_at, request_id排序,避免依赖 ClickHouse 不支持的自增id。日志写入统一补齐request_id,查询侧在 ClickHouse 分支使用created_at DESC, request_id DESC保持分页排序稳定,同时继续回填数字id,保证前端接口兼容。同时新增可选的
LOG_SQL_CLICKHOUSE_TTL_DAYS配置:默认或设置为0时不自动删除日志;设置为正整数时通过 ClickHouse 表级 TTL 自动清理过期日志。docker-compose.yml中补充了 ClickHouse 本地部署示例。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
本地测试通过:
go test ./common ./model ./controller ./service ok github.com/QuantumNous/new-api/common ok github.com/QuantumNous/new-api/model ok github.com/QuantumNous/new-api/controller ok github.com/QuantumNous/new-api/serviceSummary by CodeRabbit