feat(log): add RequestAt field to record request arrival time (#5071) - #5074
feat(log): add RequestAt field to record request arrival time (#5071)#5074Pahkho wants to merge 3 commits into
Conversation
…mNous#5071) Add a nullable `request_at` column to the logs table that captures when an HTTP request first arrives at the gateway (via ContextKeyRequestStartTime). This enables full-chain latency analysis between request arrival and log creation, useful for diagnosing slow uploads and cross-region delays. - Add `RequestAt *int64` field with composite indexes matching `CreatedAt` - Add `getRequestAt()` helper reading from gin context - Set RequestAt in RecordErrorLog and RecordConsumeLog - Add unit tests for getRequestAt (value set / nil)
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 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.
🧹 Nitpick comments (1)
model/log.go (1)
24-25: ⚡ Quick winMake
idx_request_at_typecomposite index column order consistent withidx_created_at_typeGORM orders composite index columns by per-field
priority(lower first). WithTypetaggedpriority:1andRequestAttaggedpriority:2,idx_request_at_typeis generated as(type, request_at), whileidx_created_at_type(where both fields omit per-fieldpriority) follows struct field order (i.e.,created_atthentype), so the new index doesn’t mirror the existing one.Suggested tag fix
- RequestAt *int64 `json:"request_at" gorm:"bigint;index:idx_request_at_id,priority:2;index:idx_request_at_type"` - Type int `json:"type" gorm:"index:idx_created_at_type;index:idx_request_at_type,priority:1"` + RequestAt *int64 `json:"request_at" gorm:"bigint;index:idx_request_at_id,priority:2;index:idx_request_at_type,priority:1"` + Type int `json:"type" gorm:"index:idx_created_at_type;index:idx_request_at_type,priority:2"`🤖 Prompt for 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. In `@model/log.go` around lines 24 - 25, The composite index idx_request_at_type is generated in the wrong column order because RequestAt has priority:2 and Type has priority:1, producing (type, request_at) whereas idx_created_at_type follows struct order (created_at, type); make the column order consistent by adjusting the per-field priority tags so both indexes use the same ordering (e.g., set RequestAt and CreatedAt priorities to the same or set Type priority to match struct order) — update the struct tags on RequestAt and/or Type (fields named RequestAt, Type, and CreatedAt) so idx_request_at_type is created in the same (created_at, type) order as idx_created_at_type.
🤖 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.
Nitpick comments:
In `@model/log.go`:
- Around line 24-25: The composite index idx_request_at_type is generated in the
wrong column order because RequestAt has priority:2 and Type has priority:1,
producing (type, request_at) whereas idx_created_at_type follows struct order
(created_at, type); make the column order consistent by adjusting the per-field
priority tags so both indexes use the same ordering (e.g., set RequestAt and
CreatedAt priorities to the same or set Type priority to match struct order) —
update the struct tags on RequestAt and/or Type (fields named RequestAt, Type,
and CreatedAt) so idx_request_at_type is created in the same (created_at, type)
order as idx_created_at_type.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f9c2be61-0647-4cb8-ba87-c972e9d54788
📒 Files selected for processing (2)
model/log.gomodel/log_time_test.go
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 55-57: The Log struct contains duplicated field declarations
(RequestId, UpstreamRequestId, Other) causing compile errors; remove the
duplicate block so each field is declared only once in type Log. Locate the type
Log definition and delete the second copy of RequestId, UpstreamRequestId, and
Other, leaving the single intended declaration (keep any tags like json/gorm on
the remaining fields). Ensure no other duplicate field names remain in struct
Log after the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
51fdfc5 to
2b6f1df
Compare
Add a nullable
request_atcolumn to the logs table that captures when an HTTP request first arrives at the gateway (via ContextKeyRequestStartTime). This enables full-chain latency analysis between request arrival and log creation, useful for diagnosing slow uploads and cross-region delays.RequestAt *int64field with composite indexes matchingCreatedAtgetRequestAt()helper reading from gin contextImportant
📝 变更描述 / Description
在Log表新增RequestAt *int64 字段,记录 HTTP 请求到达网关的 Unix 时间戳。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
Summary by CodeRabbit
New Features
Tests