Skip to content

Commit d10fc76

Browse files
authored
fix(task): attribute async task usage log to the initiating node (#5684)
Async task usage logs (LogQuotaData node dimension) were recorded under whichever node happened to poll the task to completion, not the node that submitted it. For token/adaptor-billed video tasks the pre-deduction is often 0, so the entire quota landed on the last polling node. Snapshot common.NodeName into TaskPrivateData at submit time and use it when writing the settlement consume log; fall back to the current node when empty so existing tasks stay compatible.
1 parent c0e42bf commit d10fc76

4 files changed

Lines changed: 9 additions & 1 deletion

File tree

controller/relay.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ func RelayTask(c *gin.Context) {
583583
task.PrivateData.BillingSource = relayInfo.BillingSource
584584
task.PrivateData.SubscriptionId = relayInfo.SubscriptionId
585585
task.PrivateData.TokenId = relayInfo.TokenId
586+
task.PrivateData.NodeName = common.NodeName
586587
task.PrivateData.BillingContext = &model.TaskBillingContext{
587588
ModelPrice: relayInfo.PriceData.ModelPrice,
588589
GroupRatio: relayInfo.PriceData.GroupRatioInfo.GroupRatio,

model/log.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ type RecordTaskBillingLogParams struct {
390390
TokenId int
391391
Group string
392392
Other map[string]interface{}
393+
NodeName string // 任务发起节点;为空时回退当前节点
393394
}
394395

395396
func RecordTaskBillingLog(params RecordTaskBillingLogParams) {
@@ -423,6 +424,10 @@ func RecordTaskBillingLog(params RecordTaskBillingLogParams) {
423424
common.SysLog("failed to record task billing log: " + err.Error())
424425
}
425426
if params.LogType == LogTypeConsume && common.DataExportEnabled {
427+
nodeName := params.NodeName
428+
if nodeName == "" {
429+
nodeName = common.NodeName
430+
}
426431
gopool.Go(func() {
427432
LogQuotaData(QuotaDataLogParams{
428433
UserID: params.UserId,
@@ -433,7 +438,7 @@ func RecordTaskBillingLog(params RecordTaskBillingLogParams) {
433438
UseGroup: params.Group,
434439
TokenID: params.TokenId,
435440
ChannelID: params.ChannelId,
436-
NodeName: common.NodeName,
441+
NodeName: nodeName,
437442
})
438443
})
439444
}

model/task.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type TaskPrivateData struct {
104104
BillingSource string `json:"billing_source,omitempty"` // "wallet" 或 "subscription"
105105
SubscriptionId int `json:"subscription_id,omitempty"` // 订阅 ID,用于订阅退款
106106
TokenId int `json:"token_id,omitempty"` // 令牌 ID,用于令牌额度退款
107+
NodeName string `json:"node_name,omitempty"` // 发起任务的节点名,轮询结算阶段据此归属日志而非最后查询节点
107108
BillingContext *TaskBillingContext `json:"billing_context,omitempty"` // 计费参数快照(用于轮询阶段重新计算)
108109
}
109110

service/task_billing.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ func RecalculateTaskQuota(ctx context.Context, task *model.Task, actualQuota int
241241
TokenId: task.PrivateData.TokenId,
242242
Group: task.Group,
243243
Other: other,
244+
NodeName: task.PrivateData.NodeName,
244245
})
245246
}
246247

0 commit comments

Comments
 (0)