Skip to content

feat(log): add RequestAt field to record request arrival time (#5071) - #5074

Open
Pahkho wants to merge 3 commits into
QuantumNous:mainfrom
Pahkho:main
Open

feat(log): add RequestAt field to record request arrival time (#5071)#5074
Pahkho wants to merge 3 commits into
QuantumNous:mainfrom
Pahkho:main

Conversation

@Pahkho

@Pahkho Pahkho commented May 23, 2026

Copy link
Copy Markdown

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)

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

在Log表新增RequestAt *int64 字段,记录 HTTP 请求到达网关的 Unix 时间戳。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

  • New Features

    • Enhanced logging now captures request initiation timestamps, providing improved visibility into request lifecycle and timing information.
  • Tests

    • Added test coverage for request timestamp tracking functionality.

Review Change Stack

…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)
@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
model/log.go (1)

24-25: ⚡ Quick win

Make idx_request_at_type composite index column order consistent with idx_created_at_type

GORM orders composite index columns by per-field priority (lower first). With Type tagged priority:1 and RequestAt tagged priority:2, idx_request_at_type is generated as (type, request_at), while idx_created_at_type (where both fields omit per-field priority) follows struct field order (i.e., created_at then type), 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

📥 Commits

Reviewing files that changed from the base of the PR and between ebbe315 and 66f5359.

📒 Files selected for processing (2)
  • model/log.go
  • model/log_time_test.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ad1065e1-8601-428e-89fd-16e3dd6a16a1

📥 Commits

Reviewing files that changed from the base of the PR and between 66f5359 and 5d61cb9.

📒 Files selected for processing (1)
  • model/log.go

Comment thread model/log.go
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