improve:优化超时时间,最多10分钟超时
This commit is contained in:
1 parent
6a50325da8
commit
cd47f55ded
32 files changed
+64
-83
No files matched your search
@@ -52,6 +52,7 @@ type AudRequestLogsColumns struct {
|
||||
TaskUpstreamHeaders string // 异步任务完成时上游返回的响应头(仅审计级别为 full 时记录)
|
||||
TaskCompletedAt string // 异步任务达到终态的时间
|
||||
AttachmentIds string // 提取的媒体附件 fil_files ID 数组(JSONB: [1,2,3])
|
||||
Model string // 请求使用的模型名称(从请求体或 URL 中提取)
|
||||
}
|
||||
|
||||
// audRequestLogsColumns holds the columns for the table aud_request_logs.
|
||||
@@ -87,6 +88,7 @@ var audRequestLogsColumns = AudRequestLogsColumns{
|
||||
TaskUpstreamHeaders: "task_upstream_headers",
|
||||
TaskCompletedAt: "task_completed_at",
|
||||
AttachmentIds: "attachment_ids",
|
||||
Model: "model",
|
||||
}
|
||||
|
||||
// NewAudRequestLogsDao creates and returns a new DAO object for table data access.
|
||||
|
||||
@@ -453,11 +453,15 @@ func captureRequestHeaders(r *ghttp.Request) map[string]string {
|
||||
func recordAudit(r *ghttp.Request, rc *handler.RelayContext, capture *ResponseCaptureWriter, body []byte, path string, latencyMs int, ttft int) {
|
||||
// 解析 stream 标志
|
||||
var isStream bool
|
||||
var modelName string
|
||||
var rawRequest map[string]json.RawMessage
|
||||
if err := json.Unmarshal(body, &rawRequest); err == nil {
|
||||
if streamVal, ok := rawRequest["stream"]; ok {
|
||||
_ = json.Unmarshal(streamVal, &isStream)
|
||||
}
|
||||
if modelVal, ok := rawRequest["model"]; ok {
|
||||
_ = json.Unmarshal(modelVal, &modelName)
|
||||
}
|
||||
}
|
||||
|
||||
// 捕获响应体(流式请求记录 SSE 原始数据,非流式记录完整响应)
|
||||
@@ -476,6 +480,7 @@ func recordAudit(r *ghttp.Request, rc *handler.RelayContext, capture *ResponseCa
|
||||
StatusCode: capture.StatusCode(),
|
||||
ClientIP: rc.ClientIP,
|
||||
UserAgent: r.Header.Get("User-Agent"),
|
||||
Model: modelName,
|
||||
RequestBody: string(body),
|
||||
ResponseBody: responseBody,
|
||||
LatencyMs: latencyMs,
|
||||
|
||||
@@ -540,6 +540,7 @@ func (p *DataProviderImpl) RecordAudit(ctx context.Context, record *common.Audit
|
||||
StatusCode: record.StatusCode,
|
||||
ClientIp: record.ClientIP,
|
||||
UserAgent: record.UserAgent,
|
||||
Model: record.Model,
|
||||
RequestBody: sysReq,
|
||||
ResponseBody: sysResp,
|
||||
TenantRequestBody: tntReq,
|
||||
|
||||
@@ -43,4 +43,5 @@ type AudRequestLogs struct {
|
||||
TaskUpstreamHeaders any // 异步任务完成时上游返回的响应头(仅审计级别为 full 时记录)
|
||||
TaskCompletedAt *gtime.Time // 异步任务达到终态的时间
|
||||
AttachmentIds any // 提取的媒体附件 fil_files ID 数组(JSONB: [1,2,3])
|
||||
Model any // 请求使用的模型名称(从请求体或 URL 中提取)
|
||||
}
|
||||
@@ -41,4 +41,5 @@ type AudRequestLogs struct {
|
||||
TaskUpstreamHeaders string `json:"task_upstream_headers" orm:"task_upstream_headers" description:"异步任务完成时上游返回的响应头(仅审计级别为 full 时记录)"` // 异步任务完成时上游返回的响应头(仅审计级别为 full 时记录)
|
||||
TaskCompletedAt *gtime.Time `json:"task_completed_at" orm:"task_completed_at" description:"异步任务达到终态的时间"` // 异步任务达到终态的时间
|
||||
AttachmentIds string `json:"attachment_ids" orm:"attachment_ids" description:"提取的媒体附件 fil_files ID 数组(JSONB: [1,2,3])"` // 提取的媒体附件 fil_files ID 数组(JSONB: [1,2,3])
|
||||
Model string `json:"model" orm:"model" description:"请求使用的模型名称(从请求体或 URL 中提取)"` // 请求使用的模型名称(从请求体或 URL 中提取)
|
||||
}
|
||||
@@ -119,10 +119,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -108,10 +108,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -133,10 +133,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -129,10 +129,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -125,10 +125,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
return client.Do(httpReq)
|
||||
|
||||
@@ -103,10 +103,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -96,6 +96,9 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
if timeout <= 0 {
|
||||
timeout = 120 // Coze 可能响应较慢,给更长超时
|
||||
}
|
||||
if constant.RelayMode(info.RelayMode) == constant.RelayModeImagesGenerations && timeout < 600 {
|
||||
timeout = 600
|
||||
}
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -208,6 +208,9 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
if timeout <= 0 {
|
||||
timeout = 300
|
||||
}
|
||||
if constant.RelayMode(info.RelayMode) == constant.RelayModeImagesGenerations && timeout < 600 {
|
||||
timeout = 600
|
||||
}
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -93,6 +93,9 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
if timeout <= 0 {
|
||||
timeout = 120 // Dify 应用可能包含复杂工作流,给更长超时
|
||||
}
|
||||
if constant.RelayMode(info.RelayMode) == constant.RelayModeImagesGenerations && timeout < 600 {
|
||||
timeout = 600
|
||||
}
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -297,10 +297,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -118,6 +118,9 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
if timeout <= 0 {
|
||||
timeout = 120 // 图像生成通常较慢
|
||||
}
|
||||
if constant.RelayMode(info.RelayMode) == constant.RelayModeImagesGenerations && timeout < 600 {
|
||||
timeout = 600
|
||||
}
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -105,10 +105,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -94,10 +94,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -102,10 +102,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -109,11 +109,15 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
// Ollama 默认 300s 超时(大模型推理可能很慢)
|
||||
// Ollama 默认 300s 超时(大模型推理可能很慢)
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 300
|
||||
}
|
||||
if constant.RelayMode(info.RelayMode) == constant.RelayModeImagesGenerations && timeout < 600 {
|
||||
timeout = 600
|
||||
}
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -207,10 +207,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
}
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -66,10 +66,7 @@ func (p *RealtimeProxy) DialUpstream() error {
|
||||
targetURL := buildRealtimeURL(p.info.ChannelMeta.BaseURL)
|
||||
header := buildRealtimeHeaders(p.info)
|
||||
|
||||
timeout := p.info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := p.info.ChannelMeta.Settings.GetTimeoutSeconds(p.info.RelayMode)
|
||||
|
||||
dialer := websocket.Dialer{
|
||||
HandshakeTimeout: time.Duration(timeout) * time.Second,
|
||||
|
||||
@@ -117,10 +117,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
return client.Do(httpReq)
|
||||
|
||||
@@ -88,10 +88,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -159,10 +159,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
httpReq.Header.Set("Authorization", authorization)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -154,10 +154,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -112,10 +112,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -125,10 +125,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -96,10 +96,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -192,13 +192,7 @@ func (a *Adaptor) DoRequest(ctx context.Context, info *common.RelayInfo, request
|
||||
override.MergeHeaderOverrides(httpReq.Header, hdrOverrides)
|
||||
}
|
||||
|
||||
timeout := info.ChannelMeta.Settings.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
timeout = 60
|
||||
if constant.RelayMode(info.RelayMode) == constant.RelayModeImagesGenerations {
|
||||
timeout = 300
|
||||
}
|
||||
}
|
||||
timeout := info.ChannelMeta.Settings.GetTimeoutSeconds(info.RelayMode)
|
||||
|
||||
client := common.NewPooledClient(timeout, info.ChannelMeta.Settings.UseProxy, info.IsStream)
|
||||
|
||||
|
||||
@@ -217,6 +217,7 @@ type AuditRecord struct {
|
||||
StatusCode int
|
||||
ClientIP string
|
||||
UserAgent string
|
||||
Model string // 请求使用的模型名称
|
||||
RequestBody string
|
||||
ResponseBody string
|
||||
LatencyMs int
|
||||
|
||||
@@ -20,6 +20,23 @@ type ChannelMeta struct {
|
||||
Settings ChannelSettings
|
||||
}
|
||||
|
||||
const (
|
||||
DefaultTimeoutSeconds = 60
|
||||
ImagesGenerationTimeoutSecs = 600
|
||||
)
|
||||
|
||||
// GetTimeoutSeconds 返回请求超时秒数。
|
||||
// 渠道自定义优先,未配置时根据请求模式返回默认值(图片生成 600s,其余 60s)。
|
||||
func (s ChannelSettings) GetTimeoutSeconds(relayMode int) int {
|
||||
if s.TimeoutSeconds > 0 {
|
||||
return s.TimeoutSeconds
|
||||
}
|
||||
if constant.RelayMode(relayMode) == constant.RelayModeImagesGenerations {
|
||||
return ImagesGenerationTimeoutSecs
|
||||
}
|
||||
return DefaultTimeoutSeconds
|
||||
}
|
||||
|
||||
// ChannelSettings 渠道配置(来自 chn_channels.settings JSONB)
|
||||
type ChannelSettings struct {
|
||||
TimeoutSeconds int `json:"timeout_seconds"` // 请求超时秒数,默认 60
|
||||
|
||||
Reference in new issue
Block a user