Merge pull request '[migration] track user actions in task logging' (#55) from feature/migration into master

This commit is contained in:
silenceqi 2023-04-04 16:22:11 +08:00
commit 11b9d8511a
2 changed files with 34 additions and 23 deletions

View File

@ -242,6 +242,10 @@ func (h *APIHandler) startDataMigration(w http.ResponseWriter, req *http.Request
return
}
writeLog(&obj, &task2.TaskResult{
Success: true,
}, "task status manually set to ready")
if obj.Metadata.Labels != nil && obj.Metadata.Labels["business_id"] == "index_migration" && len(obj.ParentId) > 0 {
//update status of major task to running
query := util.MapStr{
@ -303,6 +307,9 @@ func (h *APIHandler) stopDataMigrationTask(w http.ResponseWriter, req *http.Requ
h.WriteError(w, err.Error(), http.StatusInternalServerError)
return
}
writeLog(&obj, &task2.TaskResult{
Success: true,
}, "task status manually set to pending stop")
h.WriteJSON(w, util.MapStr{
"success": true,

View File

@ -887,32 +887,36 @@ func (p *DispatcherProcessor) saveTaskAndWriteLog(taskItem *task2.Task, refresh
log.Errorf("failed to update task, err: %v", err)
}
if message != "" {
event.SaveLog(event.Event{
Metadata: event.EventMetadata{
Category: "task",
Name: "logging",
Datatype: "event",
Labels: util.MapStr{
"task_type": taskItem.Metadata.Type,
"task_id": taskItem.ID,
"parent_task_id": taskItem.ParentId,
"retry_no": taskItem.RetryTimes,
},
},
Fields: util.MapStr{
"task": util.MapStr{
"logging": util.MapStr{
"config": util.MustToJSON(taskItem.Config),
"status": taskItem.Status,
"message": message,
"result": taskResult,
},
},
},
})
writeLog(taskItem, taskResult, message)
}
}
func writeLog(taskItem *task2.Task, taskResult *task2.TaskResult, message string) {
event.SaveLog(event.Event{
Metadata: event.EventMetadata{
Category: "task",
Name: "logging",
Datatype: "event",
Labels: util.MapStr{
"task_type": taskItem.Metadata.Type,
"task_id": taskItem.ID,
"parent_task_id": taskItem.ParentId,
"retry_no": taskItem.RetryTimes,
},
},
Fields: util.MapStr{
"task": util.MapStr{
"logging": util.MapStr{
"config": util.MustToJSON(taskItem.Config),
"status": taskItem.Status,
"message": message,
"result": taskResult,
},
},
},
})
}
func (p *DispatcherProcessor) splitMajorMigrationTask(taskItem *task2.Task) error {
if taskItem.Metadata.Labels == nil {
return fmt.Errorf("empty metadata labels, unexpected cluster migration task: %s", util.MustToJSON(taskItem))