feat: 请求日志记录

This commit is contained in:
tbphp
2025-07-12 10:15:07 +08:00
parent 70554b8fe5
commit 13d7c4dbad
13 changed files with 411 additions and 115 deletions

View File

@@ -72,14 +72,18 @@ type APIKey struct {
// RequestLog 对应 request_logs 表
type RequestLog struct {
ID string `gorm:"type:varchar(36);primaryKey" json:"id"`
Timestamp time.Time `gorm:"type:datetime(3);not null" json:"timestamp"`
GroupID uint `gorm:"not null" json:"group_id"`
KeyID uint `gorm:"not null" json:"key_id"`
SourceIP string `gorm:"type:varchar(45)" json:"source_ip"`
StatusCode int `gorm:"not null" json:"status_code"`
RequestPath string `gorm:"type:varchar(1024)" json:"request_path"`
RequestBodySnippet string `gorm:"type:text" json:"request_body_snippet"`
ID string `gorm:"type:varchar(36);primaryKey" json:"id"`
Timestamp time.Time `gorm:"type:datetime(3);not null;index" json:"timestamp"`
GroupID uint `gorm:"not null;index" json:"group_id"`
KeyID uint `gorm:"not null;index" json:"key_id"`
IsSuccess bool `gorm:"not null" json:"is_success"`
SourceIP string `gorm:"type:varchar(45)" json:"source_ip"`
StatusCode int `gorm:"not null" json:"status_code"`
RequestPath string `gorm:"type:varchar(1024)" json:"request_path"`
Duration int64 `gorm:"not null" json:"duration_ms"`
ErrorMessage string `gorm:"type:text" json:"error_message"`
UserAgent string `gorm:"type:varchar(512)" json:"user_agent"`
Retries int `gorm:"not null" json:"retries"`
}
// GroupRequestStat 用于表示每个分组的请求统计